1

ここcmakeで説明されているように、ビルド システムを使用して OpenCV ライブラリをビルドし、ヘッダー、「.a」および「.dylib」ファイルをターミナル C++ プロジェクトに追加しました。ただし、以下のコードを実行すると ( http://iphone-cocoa-objectivec.blogspot.com/2009/01/using-opencv-for-mac-os-in-xcode.htmlから入手)、以下のエラー。誰かアドバイスはありますか?どんな助けでも大歓迎です。

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>

int main()
{

    //get the image from the directed path
    IplImage* img = cvLoadImage("/Users/somedir/Programming/TestProj/fruits.jpg", 1);

    //create a window to display the image
    cvNamedWindow("picture", 1);

    //show the image in the window
    cvShowImage("picture", img);

    //wait for the user to hit a key
    cvWaitKey(0);

    //delete the image and window
    cvReleaseImage(&img);
    cvDestroyWindow("picture");

    //return
    return 0;
}

エラー

Undefined symbols:
  "_cvLoadImage", referenced from:
      _main in main.o
  "_cvNamedWindow", referenced from:
      _main in main.o
  "_cvReleaseImage", referenced from:
      _main in main.o
  "_cvShowImage", referenced from:
      _main in main.o
  "_cvDestroyWindow", referenced from:
      _main in main.o
  "_cvWaitKey", referenced from:
      _main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
4

2 に答える 2

0

OpenCV 2.0 で Xcode を使用しないでください。OpenCV を使用する場合は、Windows を使用し、OpenCV 1.1 も使用します。それは多くの頭痛を救うでしょう。2.0/Mac のドキュメントが改善されたら、Mac プラットフォーム/2.0 バージョンに移行します。この本 (O'Reilly) は良いです - v1.1 をカバーしています。2.0 の次の記事はすぐに続くはずです。1.

于 2009-12-06T00:48:50.270 に答える
0

まず、CMake でライブラリをビルドしないでください。Mac の macports からライブラリを取得することをお勧めします。ワンライナーで簡単に新しいバージョンに更新できます...

さらに、cv::Matインターフェースを使用すると
#include <opencv2/core/core.hpp>#include <opencv2/highgui/highgui.hpp>状況が改善されます... ;) 名前の末尾にバージョンを含む dylib ライブラリを含めます。(バージョンのない dylib は古いインターフェース #include 用だと思います)

手始めに:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main()
{

    //get the image from the directed path
    Mat img = loadImage("/Users/somedir/Programming/TestProj/fruits.jpg");

    //show the image in the window
    imshow("picture", img);

    //wait for the user to hit a key
    waitKey(0);
    //delete the image and window (automatic)
    return 0;
}
于 2012-11-02T10:00:11.773 に答える