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 cannot figure out how to resize the display window. I have several video images arranged horizontally, but the image size is very small, which is difficult to see.

My code is pretty simple in lines too:

cv2.namedWindow("main") .... result = np.hstack((res2, foreground)) result = np.hstack((ff, result)) cv2.imshow("main", result) cv2.waitKey(20) 

opencv documentation says:

 namedWindow flags – Flags of the window. Currently the only supported flag is CV_WINDOW_AUTOSIZE . If this is set, the window size is automatically adjusted to fit the displayed image (see imshow() ), and you cannot change the window size manually. 

But qt backends apparently have extra flags. I do not have a qt backend. Is there a way to increase the size of the images so that I can see them?

+7
source share
4 answers

Yes, unfortunately, you cannot manually resize the nameWindow window without Qt support. Your options:

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

Just write

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

and then manually resize to fit

+9
source

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

 namedWindow("Image", WINDOW_NORMAL); 

Check namedWindow function registered here

+2
source

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

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

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

-2
source

All Articles