I'm trying to use cv2.imshow
to display a specific section of my screen.
However, while running, I noticed the displayed window is smaller than expected. I've stepped through the code with the debugger and noticed that when cv2.waitKey(1)
triggers the cv2.imshow
window resizes itself and I'm not sure why.
If I comment out cv2.waitKey(1)
the display window remains the expected size, the documentation that would suggest cv2.waitKey
does anything other than wait for a specified amount of time 0 = infinite, x = time in milliseconds.
Why is waitKey
resizing cv2.imshow
and how do I fix this?
import cv2 as cv
import numpy as np
from mss import mss
sct = mss()
def screenshot(top, left, width, height):
monitor = {'top': top, 'left': left, 'width': width, 'height': height}
haystack = np.array(sct.grab(monitor))
cv.imshow("Objects", haystack)
cv.moveWindow("Objects",5000,50)
cv.setWindowProperty('Objects', cv.WND_PROP_TOPMOST, 1)
cv.waitKey(1)
return haystack
top = 350
left = 1000
width = 500
height = 800
while True:
screenshot(top, left, width, height)
With cv.waitKey(1)
commented out:
and with cv.waitKey(1)
not commented out:
Contents of haystack
saved to file using cv2.imwrite
: