使用eclipse在OS X 10.8中构建opencv示例

时间:2013-04-08 04:44:04

标签: eclipse macos opencv

我正在尝试使用OS X 10.8中的Eclipse构建以下示例:

//============================================================================

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

但得到这个结果:

**** Build of configuration Debug for project cvTesting ****

make all 
Building file: ../src/cvTesting.cpp
Invoking: GCC C++ Compiler
g++ -I/opt/local/include/opencv -I/opt/local/include/opencv2 -I/opt/local/include/opencv2/core/ -        I/opt/local/include/opencv2/highgui/ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/cvTesting.d"     -MT"src/cvTesting.d" -o "src/cvTesting.o" "../src/cvTesting.cpp"
../src/cvTesting.cpp:9:33: warning: opencv2/core/core.hpp: No such file or directory
../src/cvTesting.cpp:10:39: warning: opencv2/highgui/highgui.hpp: No such file or directory
../src/cvTesting.cpp:13: error: 'cv' is not a namespace-name
../src/cvTesting.cpp:13: error: expected namespace-name before ';' token
../src/cvTesting.cpp: In function 'int main(int, char**)':
../src/cvTesting.cpp:24: error: 'Mat' was not declared in this scope
../src/cvTesting.cpp:24: error: expected `;' before 'image'
../src/cvTesting.cpp:25: error: 'image' was not declared in this scope
../src/cvTesting.cpp:25: error: 'CV_LOAD_IMAGE_COLOR' was not declared in this scope
../src/cvTesting.cpp:25: error: 'imread' was not declared in this scope
../src/cvTesting.cpp:33: error: 'CV_WINDOW_AUTOSIZE' was not declared in this scope
../src/cvTesting.cpp:33: error: 'namedWindow' was not declared in this scope
../src/cvTesting.cpp:34: error: 'imshow' was not declared in this scope
../src/cvTesting.cpp:36: error: 'waitKey' was not declared in this scope
make: *** [src/cvTesting.o] Error 1

**** Build Finished ****

我安装了opencv,以便pkg-config报告以下内容:

$ pkg-config opencv --cflags

-I / opt / local / include / opencv -I / opt / local / include

$ pkg-config --libs opencv

/opt/local/lib/libopencv_calib3d.dylib /opt/local/lib/libopencv_contrib.dylib /opt/local/lib/libopencv_core.dylib /opt/local/lib/libopencv_features2d.dylib / opt / local / lib / libopencv_flann.dylib /opt/local/lib/libopencv_gpu.dylib /opt/local/lib/libopencv_highgui.dylib /opt/local/lib/libopencv_imgproc.dylib /opt/local/lib/libopencv_legacy.dylib / opt / local / lib / libopencv_ml.dylib /opt/local/lib/libopencv_nonfree.dylib /opt/local/lib/libopencv_objdetect.dylib /opt/local/lib/libopencv_photo.dylib /opt/local/lib/libopencv_stitching.dylib / opt / local / lib / libopencv_ts.dylib /opt/local/lib/libopencv_video.dylib /opt/local/lib/libopencv_videostab.dylib

并且在Eclipse中,在我拥有的项目属性中,C / C ++ Build - &gt;设置 - &gt; GCC C ++编译器“所有选项”设置为:

-I / opt / local / include / opencv -I / opt / local / include / opencv2 -O0 -g3 -Wall -c -fmessage-length = 0

和C / C ++ Build - &gt;设置 - &gt; MacOS X C ++链接器 - &gt; “所有选项”设置为: -L /选择/本地/ lib中

我还在C / C ++ Build - &gt;中列出了以下库(-l)。设置 - &gt; MacOS X C ++链接器 - &gt;库:

opencv_core opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_features2d opencv_calib3d opencv_objdetect opencv_contrib opencv_legacy opencv_flann

我能够在Ubuntu中构建相同的示例,而不是OS X.任何人都可以帮助解释OS X中eclipse使用的路径设置,opencv?

2 个答案:

答案 0 :(得分:0)

正如您在编译器输出中看到的那样:

  

../ src / cvTesting.cpp:9:33:警告:opencv2 / core / core.hpp:没有这样的文件或目录
  ../src/cvTesting.cpp:10:39:警告:opencv2 / highgui / highgui.hpp:没有这样的文件或目录

Eclipse无法找到core.hpp和highgui.hpp文件。您确定这些文件位于这些位置吗?

您也可以尝试使用core.hhighgui.h代替*.hpp个文件。

答案 1 :(得分:0)

经过对该主题的更多研究以及各种选项的研究后,我发现了在OS X中使用Xcode而不是Eclipse的最佳方法。

我用来获取Xcode设置并正常工作的信息在此处发布的答案中:

Compile OpenCV (2.3.1+) for OS X Lion / Mountain Lion with Xcode

在此之前,我通过此处找到的Mac OS X OpenCV端口说明返回:    http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port

希望这有助于其他人尝试在OS X中使用OpenCV和现代IDE ...

-Walt