Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cv2.imshow image window placement is outside of viewable screen

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!

like image 261
chiaka Avatar asked Nov 11 '17 05:11

chiaka


2 Answers

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()
like image 78
Kinght 金 Avatar answered Nov 15 '22 20:11

Kinght 金


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)
like image 38
Peter F Avatar answered Nov 15 '22 19:11

Peter F