Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV: Is namedWindow() necessary before imshow()?

Tags:

c++

opencv

In OpenCV, I have seen many instances of namedWindow() preceding imshow(); such as:

namedWindow( imageName, CV_WINDOW_AUTOSIZE );
namedWindow( "Gray image", CV_WINDOW_AUTOSIZE );

imshow( imageName, image );
imshow( "Gray image", gray_image );

The above code is from OpenCV documentation.

In one of the posts a user mentions that namedWindow() is not necessary. I myself have never used namedWindow().

From the namedWindow documentation it seems that namedWindow() might be useful with imshow() when the flag is not WINDOW_AUTOSIZE. But is there any use of namedWindow() with WINDOW_AUTOSIZE before imshow()?

like image 550
Ruchir Avatar asked Jul 01 '15 07:07

Ruchir


People also ask

What is namedWindow in OpenCV?

Python OpenCV namedWindow() method is used to create a window with a suitable name and size to display images and videos on the screen. The image by default is displayed in its original size, so we may need to resize the image for it to fit our screen.

How do I close my cv2 Imshow?

waitKey() and cv2. destroyAllWindows(). Inside the cv2. waitKey() function, you can provide any value to close the image and continue with further lines of code.


1 Answers

from the documentation to which you refer:

namedWindow creates a window that can be used as a placeholder for images and trackbars. Created windows are referred to by their names.

The fuction namedWindow just makes sure that if you wish to do something with that same window afterwards (eg move, resize, close that window), you can do it by referencing it with the same name.

So if you just want to show it; you don't need to use namedWindow().

like image 183
Chris Maes Avatar answered Nov 01 '22 19:11

Chris Maes