C++ 使用opencv 2.4.6加载和显示图像

C++ 使用opencv 2.4.6加载和显示图像,c++,image,opencv,C++,Image,Opencv,我尝试使用opencv版本2.4.6编译这个加载和显示图像的源代码。我认为不应该有错误,因为我在互联网上得到了这个代码。但我仍然有一些错误,我不知道如何解决它 我的代码: #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace cv; using namespace std; int main( i

我尝试使用opencv版本2.4.6编译这个加载和显示图像的源代码。我认为不应该有错误,因为我在互联网上得到了这个代码。但我仍然有一些错误,我不知道如何解决它

我的代码:

#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", CV_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;
}
#包括
#包括
#包括
使用名称空间cv;
使用名称空间std;
int main(int argc,字符**argv)
{
如果(argc!=2)
{

错误在opencv文件中是否很奇怪。请尝试删除您拥有的两个opencv包含并添加这两个:#包含,#包含我尝试过,但仍然得到相同的错误。我不知道现在该怎么办。嗯,为什么您同时包含
-I“C:\Users\nurulazila\Desktop\opencv\include\opencv2”
C:/opencv/build/include
目录?似乎您需要包含一个或另一个目录(您安装opencv 2.4.6的目录)。我已经删除了包含C:\Users\nurulazila\Desktop\opencv\include\opencv2的路径。我用正确的目录对其进行了更改,并将其保存在C:\中。不过,我在opencv目录中的operations.cpp文件中遇到了错误。名称用于库包含。您有
-L“C:\Users\nurulazila\Desktop\opencv\build\x86\mingw\lib”-“C:\opencv\build\x86\mingw\lib”
但您只需要链接到其中一个目录。如果库安装/构建正确,问题在于如何链接/导入opencv库。请尝试删除指向不正确目录的链接或包含指向不正确目录的链接。
Compiler: OpenCV2
Executing  g++.exe...
g++.exe "C:\Users\nurulazila\Desktop\please.cpp" -o "C:\Users\nurulazila\Desktop\please.exe"   -L"C:\opencv\build\x86\mingw\lib" -lcxcore2460 -lcv2460 -lcvaux2460 -lhighgui2460 -lml2460  -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"  -I"C:\opencv\build\include"   -L"C:\Dev-Cpp\lib" -L"C:\opencv\build\x86\mingw\lib" -lcxcore2460 -lcv2460 -lcvaux2460 -lhighgui2460 -lml2460 
In file included from C:/opencv/build/include/opencv2/core/core.hpp:4824,
                 from C:\Users\nurulazila\Desktop\please.cpp:1:
C:/opencv/build/include/opencv2/core/operations.hpp: In static member function `static cv::Ptr<_Tp2> cv::Algorithm::create(const std::string&)':
C:/opencv/build/include/opencv2/core/operations.hpp:3918: error: expected primary-expression before '>' token
C:/opencv/build/include/opencv2/core/operations.hpp:3918: error: expected primary-expression before ')' token

C:/opencv/build/include/opencv2/core/operations.hpp: At global scope:
C:/opencv/build/include/opencv2/core/operations.hpp:3970: error: got 2 template parameters for `void cv::AlgorithmInfo::addParam(cv::Algorithm&, const char*, cv::Ptr<_Tp2>&, bool, cv::Ptr<_Tp2> (cv::Algorithm::*)(), void (cv::Algorithm::*)(const cv::Ptr<_Tp2>&), const std::string&)'
C:/opencv/build/include/opencv2/core/operations.hpp:3970: error:   but 1 required
C:/opencv/build/include/opencv2/core/operations.hpp:3979: error: redefinition of `void cv::AlgorithmInfo::addParam(cv::Algorithm&, const char*, cv::Ptr<_Tp2>&, bool, cv::Ptr<_Tp2> (cv::Algorithm::*)(), void (cv::Algorithm::*)(const cv::Ptr<_Tp2>&), const std::string&)'
C:/opencv/build/include/opencv2/core/operations.hpp:3970: error: `void cv::AlgorithmInfo::addParam(cv::Algorithm&, const char*, cv::Ptr<_Tp2>&, bool, cv::Ptr<_Tp2> (cv::Algorithm::*)(), void (cv::Algorithm::*)(const cv::Ptr<_Tp2>&), const std::string&)' previously declared here

Execution terminated