5
votes

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()?

1

1 Answers

10
votes

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().