Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV: where can I find CV_WINDOW_AUTOSIZE constants?

Tags:

c++

linux

opencv

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.

like image 953
user2758580 Avatar asked Sep 08 '13 09:09

user2758580


3 Answers

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

like image 178
leinaD_natipaC Avatar answered Oct 19 '22 22:10

leinaD_natipaC


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

like image 5
lmiguelmh Avatar answered Oct 19 '22 23:10

lmiguelmh


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

like image 4
Spaceship222 Avatar answered Oct 19 '22 23:10

Spaceship222