0

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 ****

pkg-config が次のように報告するように opencv をインストールしました。

$ 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 -> Settings -> GCC C++ Compiler "All options" set to:

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

C/C++ Build -> Settings -> MacOS X C++ Linker -> "All options" は次のように設定されています: -L/opt/local/lib

C/C++ Build -> Settings -> MacOS X C++ Linker -> Libraries に次のライブラリ (-l) もリストされています。

opencv_core opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_features2d opencv_calib3d opencv_objdetect opencv_contrib opencv_legacy opencv_flann

OS Xではなく、Ubuntuでこの同じ例を構築できます。opencvのOS XでEclipseが使用するパスのセットアップを説明できる人はいますか?

4

2 に答える 2

0

このトピックについてさらに多くの調査を行い、さまざまなオプションを検討した結果、OS X で IDE に Eclipse ではなく Xcode を使用することが最善の方法であることがわかりました。

Xcode をセットアップして正しく動作させるために使用した情報は、ここに投稿された回答にあります。

OS X Lion / Mountain Lion 用の OpenCV (2.3.1+) を Xcode でコンパイルする

ただし、これを行う前に、ここにある Mac OS X OpenCV ポートの手順に戻りました: http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port

これが、OS X の最新の IDE で OpenCV を使用しようとしている他の人に役立つことを願っています...

-ウォルト

于 2013-04-09T04:42:28.393 に答える