cv2: How to resize window

Published: 2019-08-26 03:12:25 -0400 -0400

Reading time: 1 mins (119 words)

Tags: python opencv cv2 window tutorial image


I’m using Python and the library cv2 (opencv-python) to display an image in a window but my image is super big and going off the screen. How do I resize my window so the image stays on the screen without distorting it?


Here’s an example:

window_width = 600
window_height = 600

cv2.namedWindow("my_window_name", cv2.WINDOW_NORMAL)
cv2.resizeWindow("my_window_name", window_width, window_height)
cv2.imshow("my_window_name", image_to_show)

Basically we’re creating a namedWindow which allows us to identify and modify that window later. We then mutate it with resizeWindow and show our image in it with imshow.

did this help?

I regularly post about tech topics I run into. You can get a periodic email containing updates on new posts and things I’ve built by subscribing here.

About the Ham

Hi I'm Hamilton and I wrote / built this! I like doing lots of things, but mostly I like to build (and then share those buildings). Some things I'm currently building: art, software, and prose. To stay up-to-date with my latest buildings, subscribe to my email list or follow one of my many other accounts. #buildit #shipit #justhamit

comments powered by Disqus