[英]opencv load and display image
I have installed opencv 3.0 and verified that its properly working.Then started a tutorial on Loading and displaying an image which gave me errors stating that 'CV_LOAD_IMAGE_COLOR' was not declared in this scope.I went through similar posts but were not helpful我已经安装了 opencv 3.0 并验证它是否正常工作。然后开始了一个关于加载和显示图像的教程,这给了我错误,指出“CV_LOAD_IMAGE_COLOR”未在此范围内声明。我浏览了类似的帖子,但没有帮助
and here is the code.Any help is very much appreciated.这是代码。非常感谢任何帮助。
#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;
}
The documentation for OpenCV 3.0 can be found here: http://docs.opencv.org/3.0.0/d4/da8/group__imgcodecs.html OpenCV 3.0 的文档可以在这里找到: http : //docs.opencv.org/3.0.0/d4/da8/group__imgcodecs.html
The current enum responsible for imread is:当前负责 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
}
This means you need to use cv::IMREAD_COLOR
when using OpenCv 3.0 instead of cv::CV_LOAD_IMAGE_COLOR
.这意味着在使用 OpenCv 3.0 时需要使用cv::IMREAD_COLOR
而不是cv::CV_LOAD_IMAGE_COLOR
。
image = imread(argv[1], IMREAD_COLOR); // Read the file
CV_LOAD_IMAGE_COLOR is declared in opencv2/imgcodecs/imgcodecs_c.h. CV_LOAD_IMAGE_COLOR 在 opencv2/imgcodecs/imgcodecs_c.h 中声明。 Therefore, you need to add因此,您需要添加
#include<opencv2/imgcodecs/imgcodecs_c.h>
Besides, you can include just one header file此外,您可以只包含一个头文件
#include <opencv2/opencv.hpp>
instead of separately include all the header files in opencv.而不是单独包含 opencv 中的所有头文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.