6

I have tried to build the sample program from OpenCV documentation, but i have encountered a problem:

error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope

Source of program:

#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main( int argc, char** argv )
{
Mat image;
image = imread( argv[1], 1 );

 if( argc != 2 || !image.data )
{
  printf( "No image data \n" );
  return -1;
}

 namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
 imshow( "Display Image", image );

 waitKey(0);

 return 0;  
}

I think that CV_WINDOW_AUTOSIZE constants have been contained in a certain header file, but I can't find the necessary header file.

7 Answers 7

13

CV_WINDOW_AUTOSIZE actually really is found in highgui.h, BUT, as @berak pointed out in the comments, that's part of the obsolete c-api. You should instead do one of two things:

  • Use WINDOW_AUTOSIZE instead, which is part of the C++ API. You don't need to change anything else to make this work, not even #include anything that isn't already #included in the example.
  • Use namedWindow( "Display Image" ) instead, since namedWindow uses WINDOW_AUTOSIZE by default and so you don't even have to include it as an argument.

Tested for OpenCV 3.0.0

2
  • Good for OpenCV 3.0. Thanks much.
    – Bondolin
    Nov 28, 2014 at 16:59
  • Yeah, the version is important in this kind of opensource thing. Whenever a recently popular library gets updated, all the tutorials and troubleshooting stay out of date and no one realizes until after hours of fruitless investigating. Dec 1, 2014 at 7:41
5

It appears that in OpenCV 3.1 you need to use cv::WindowFlags::WINDOW_AUTOSIZE which is located in <opencv2/highgui.hpp>.

4

For opencv 4, it is defined in <opencv2/highgui/highgui_c.h>

3

since all the windowing stuff is in the highgui module, you'll need

#include <opencv2/highgui/highgui.hpp>

also, you'll need to link against the opencv_highgui library later

4
  • 1
    This didn't work for me, however #include <opencv/highgui.h> did. Why is this? Sep 25, 2014 at 22:45
  • @leinaD_natipaC - you're using the obsolete c-api (don't do that!), above answer was for 2.4.9
    – berak
    Sep 26, 2014 at 9:49
  • Then what should I use? Including <opencv2/highgui/highgui.hpp> does nothing, even though CMake says it's linking the executable against opencv_highgui (message("${OpenCV_LIBS}") --> [...];opencv_highgui;[...] ) , everything else works otherwise so I have no idea what I'm doing wrong. Sep 29, 2014 at 18:29
  • Never mind, just found out that I was reading the docs all wrong. You were right about using the c-api though. Sep 29, 2014 at 18:59
2

I have same issue and use

WINDOW_AUTOSIZE instead of

CV_WINDOW_AUTOSIZE

1

It has been change in version 4. You can use directly WIDOW_AUTOSIZE if have defined using namespace cv as in your example. Also, do not forget to add the correct dependencies for opencv

-2

You will find it in highgui.h.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.