cv2.imshow image window placement is outside of viewable screen

痴心易碎 提交于 2019-12-12 09:35:30

问题


I am running Anaconda install of python35 with cv2 install from menpo. I am having trouble with cv2.imshow() inconsistently placing the image window outside of the viewable screen when running code similar to the one below both as a standalone script and line by line in the console (cmd, spyder, ipython)...

import cv2
img = cv2.imread('Image71.jpg',0)
cv2.startWindowThread()
cv2.namedWindow('image')
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

I have also tried the above without cv2.starWindowThread() and cv2.namedWindow() with the same result. The window appears on my taskbar but is not in view, cv2.waitKey(0) responds to the keystroke, and I am not able to bring the window into view using any of the window arrangement shortcut keys for Windows 10 (e.g. alt+tab, Winkey + left, etc). My OS is Win10 version 1709. Any help is much appreciated, thx!


回答1:


img = cv2.imread("test.png")
winname = "Test"
cv2.namedWindow(winname)        # Create a named window
cv2.moveWindow(winname, 40,30)  # Move it to (40,30)
cv2.imshow(winname, img)
cv2.waitKey()
cv2.destroyAllWindows()



回答2:


wrapped answer by Kinght in a function for easy calling

def showInMovedWindow(winname, img, x, y):
    cv2.namedWindow(winname)        # Create a named window
    cv2.moveWindow(winname, x, y)   # Move it to (x,y)
    cv2.imshow(winname,img)

img = cv2.imread('path.png')
showInMovedWindow('named_window',img, 0, 200)


来源:https://stackoverflow.com/questions/47234590/cv2-imshow-image-window-placement-is-outside-of-viewable-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!