Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
784 views
in Technique[技术] by (71.8m points)

opencv - 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 horizontally, but the image dimension is very small that it's difficult to see things.

My code is pretty simple, and along the lines of this:

cv2.namedWindow("main")

....

result = np.hstack((res2, foreground))
result = np.hstack((ff, result))

cv2.imshow("main", result)
cv2.waitKey(20)

The opencv documentation states:

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 don't have a qt backend. Is there a way for me to increase the size of the images so that I can see them?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...