簡體   English   中英

Xcode中的OpenCV C ++錯誤

[英]OpenCV C++ error in Xcode

我已經按照此處所述使用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

首先,不要使用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;
}

避免將Xcode與OpenCV 2.0一起使用。 如果使用OpenCV,請使用Windows,也請使用OpenCV 1.1。 這將節省很多頭痛。 如果更好地記錄了2.0 / Mac,請過渡到Mac平台/2.0版本。 這本書(O'Reilly)很不錯-涵蓋了v1.1。 下一版的2.0將很快推出。 1。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM