Skip to content Skip to sidebar Skip to footer

How To Resize Window In Opencv2 Python

I am using opencv 2 with a webcam. I can get the video stream and process it, but I can't seem to figure out a way to resize the display window. I have some video images stacked ho

Solution 1:

Yes, unfortunately you can't manually resize a nameWindow window without Qt backend. Your options:

  • use cv2.resize function to resize the image to desired size prior to displaying the image
  • install OpenCV with Qt backend support and use cv2.namedWindow("main", CV_WINDOW_NORMAL)

Solution 2:

Simply write

cv2.namedWindow("main", cv2.WINDOW_NORMAL)

and then manually resize it to your desired size

cv2.resizeWindow('image', 900, 900) 

Solution 3:

You can use the WINDOW_NORMAL flag when calling the namedWindow function as shown below. This will allow you to resize your window.

namedWindow("Image", WINDOW_NORMAL);

Check the namedWindow function documented here

Solution 4:

What worked for me was to resize the image instead of the window (I never did manage to get window resizing to work):

importcv2img= cv2.imread('your_image.jpg')
res = cv2.resize(img, dsize=(500,500), interpolation=cv2.INTER_CUBIC)
cv2.namedWindow("Resized", cv2.WINDOW_NORMAL)
cv2.imshow("Resized", res)

Solution 5:

As per the docs, you need to create your window with autosize true.

cv2.namedWindow("main", cv2.WINDOW_AUTOSIZE)

Your call to imshow will then automatically resize the window to fit your image.

Post a Comment for "How To Resize Window In Opencv2 Python"