Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PYTHON - how to return the window size of a cv2.imshow window?

Tags:

python

opencv

since i used cv2.namedWindow('Frame', cv2.WINDOW_NORMAL) I was able to resize my window while running but I also want to print the new window size. Anyone who could help?

Update: This is not the full code but it's something like this

cap = cv2.VideoCapture(0)
cv2.namedWindow('Frame', cv2.WINDOW_NORMAL)
while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    cv2.imshow('Frame',frame)
    print(frame.shape) #prints image dimension
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

It kept printing (480, 640, 3) even after I resized the window

like image 386
Mae Mara Avatar asked Dec 23 '22 06:12

Mae Mara


1 Answers

You can use the following command.

cv2.getWindowImageRect('Frame')

This will return a tuple of (x, y, w, h) with the current information of the image that is showing in the window named 'Frame'.

Note: This will return the details of the image, but not the information of the window that the image is in.

Edit Note: This function appears after opencv 3.4.1 release.

like image 123
Ramesh-X Avatar answered Dec 25 '22 19:12

Ramesh-X