6

我尝试从 OpenCV 文档构建示例程序,但遇到了一个问题:

错误:未在此范围内声明“CV_WINDOW_AUTOSIZE”

节目来源:

#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;  
}

我认为CV_WINDOW_AUTOSIZE常量已经包含在某个头文件中,但是我找不到必要的头文件。

4

7 回答 7

11

CV_WINDOW_AUTOSIZE实际上确实可以在 中找到highgui.h,但是正如@berak 在评论中指出的那样,是过时的 c-api 的一部分。您应该改为做以下两件事之一:

  • 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

于 2014-09-29T19:06:08.243 回答
4

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

于 2016-05-24T22:10:05.267 回答
4

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

于 2020-04-24T04:07:32.273 回答
3

因为所有窗口的东西都在 highgui 模块中,你需要

#include <opencv2/highgui/highgui.hpp>

此外,您稍后需要链接到 opencv_highgui 库

于 2013-09-08T09:39:41.167 回答
2

I have same issue and use

WINDOW_AUTOSIZE instead of

CV_WINDOW_AUTOSIZE

于 2020-08-04T11:11:04.443 回答
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

于 2020-02-06T15:37:31.553 回答
-2

您会在highgui.h.

于 2013-09-08T09:37:10.027 回答