【问题标题】:opencv load and display imageopencv 加载并显示图像
【发布时间】:2015-09-18 02:29:06
【问题描述】:

我已经安装了 opencv 3.0 并验证了它是否正常工作。然后开始了一个关于加载和显示图像的教程,它给了我错误说明 'CV_LOAD_IMAGE_COLOR' 未在此范围内声明。我浏览过类似的帖子,但没有帮助

这里是代码。非常感谢任何帮助。

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
    if( argc != 2)
    {
     cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
     return -1;
    }

    Mat image;
    image = imread(argv[1], CV_LOAD_IMAGE_COLOR);   // Read the file

    if(! image.data )                              // Check for invalid input
    {
        cout <<  "Could not open or find the image" << std::endl ;
        return -1;
    }

    namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
    imshow( "Display window", image );                   // Show our image inside it.

    waitKey(0);                                          // Wait for a keystroke in the window
    return 0;
}

【问题讨论】:

标签: c++ opencv


【解决方案1】:

OpenCV 3.0 的文档可以在这里找到:http://docs.opencv.org/3.0.0/d4/da8/group__imgcodecs.html

当前负责 imread 的枚举是:

enum    cv::ImreadModes {
  cv::IMREAD_UNCHANGED = -1,
  cv::IMREAD_GRAYSCALE = 0,
  cv::IMREAD_COLOR = 1,
  cv::IMREAD_ANYDEPTH = 2,
  cv::IMREAD_ANYCOLOR = 4,
  cv::IMREAD_LOAD_GDAL = 8
}

这意味着您在使用 OpenCv 3.0 时需要使用 cv::IMREAD_COLOR 而不是 cv::CV_LOAD_IMAGE_COLOR

image = imread(argv[1], IMREAD_COLOR);   // Read the file

【讨论】:

    【解决方案2】:

    CV_LOAD_IMAGE_COLOR 在 opencv2/imgcodecs/imgcodecs_c.h 中声明。 因此,您需要添加

    #include<opencv2/imgcodecs/imgcodecs_c.h>
    

    另外,你可以只包含一个头文件

    #include <opencv2/opencv.hpp>
    

    而不是将所有头文件单独包含在opencv中。

    【讨论】:

      猜你喜欢
      • 2016-11-25
      • 1970-01-01
      • 2013-07-12
      • 2021-03-20
      • 2015-07-15
      • 1970-01-01
      • 2017-12-04
      • 1970-01-01
      • 2016-11-26
      相关资源
      最近更新 更多