0

我最近在笔记本电脑上安装了 OpenCV。安装 OpenCV 2.4.2 后,我尝试运行并编译一个基本程序来加载和显示图像。代码如下。

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

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

namedWindow( "Display window", CV_WINDOW_AUTOSIZE );
imshow( "Display window", image );                   

waitKey(0);                                          
return 0;
}

该程序在他们的网站上给出。然后对于编译命令,我使用了以下命令:

g++ `pkg-config opencv --cflags` p1.cpp  -o p1 `pkg-config opencv --libs` 

编译失败,结果是:

Package opencv was not found in the pkg-config search path.

Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable


No package 'opencv' found


Package opencv was not found in the pkg-config search path.


Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable


No package 'opencv' found


p1.cpp:1:33: fatal error: opencv2/core/core.hpp: No such file or directory
compilation terminated.

我哪里错了?

4

0 回答 0