Home > OS >  OpenCV imshow window rendering off screen; how do I move an imshow window?
OpenCV imshow window rendering off screen; how do I move an imshow window?

Time:05-06

I've a function that grabs a screenshot of a named application window and displays it with cv.imshow

However the window is rendering off screen.

import cv2 as cv

def videoLoop():
    window = pygetwindow.getWindowsWithTitle('App')[0]
    haystack_img = ImageGrab.grab(bbox=(750, 30, 1150, 78))
    haystack_img_np = np.array(haystack_img)
    haystack = cv.cvtColor(haystack_img_np, cv.COLOR_BGR2GRAY)
    test = cv.imshow("Ship Detection", haystack)
    cv.moveWindow(test, 1000,800)
    cv.waitKey(1)

I've tried using cv.moveWindow but I'm getting a NULL error.

Failed capture: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\highgui\src\window_w32.cpp:1515: error: (-27:Null pointer) NULL window: '' in function 'cvMoveWindow'

I can also spawn a blank window with:

cv.imshow(test)
cv.moveWindow(test, 1000,800)
cv.waitKey(1)

But when I try with haystack I get the error: Failed capture: Can't convert object to 'str' for 'winname'

cv.imshow("Ship Detection", haystack)
cv.moveWindow(haystack, 1000,800)
cv.waitKey(1)

CodePudding user response:

cv.imshow("Ship Detection", haystack)
cv.moveWindow("Ship Detection", 1000,800)
cv.waitKey(1)

moveWindow wants the window name not the object.

  • Related