繁体   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