erro OpenCV C ++ no Xcode
Pergunta
Eu construí as bibliotecas OpenCV utilizando o sistema de compilação cmake
como descrito aqui e ter adicionado o cabeçalho, '.a' e '.dylib' arquivos para o meu projeto de terminal de c ++. No entanto, quando eu executar o código abaixo (got it from http://iphone-cocoa-objectivec.blogspot.com/2009/01/using-opencv-for-mac-os-in-xcode.html ), ele me dá o erros abaixo. Alguém tem algum conselho? Qualquer ajuda será muito apreciada.
#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;
}
Erros
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
Solução
Evite usar Xcode com OpenCV 2.0. Se estiver usando OpenCV uso do Windows e também usar OpenCV 1.1. Ela vai lhe poupar muita dor de cabeça. Quando 2.0 / Mac estão mais bem documentado, em seguida, transição para a plataforma Mac / versão 2.0. O livro (O'Reilly) é bom - covers v1.1. A próxima parcela de 2,0 deve seguir em breve. 1.
Outras dicas
Em primeiro lugar, não construir as libs com CMake, melhor para obtê-los a partir MacPorts no mac, você pode facilmente atualizar para a versão mais recente com um one-liner ...
Além disso, se você usaria as interfaces cv::Mat
com
#include <opencv2/core/core.hpp>
e #include <opencv2/highgui/highgui.hpp>
as coisas iriam melhor ...;) incluir as bibliotecas dylib com versões no final do seu nome. (Eu acho que os dylibs versão menos são para o velho #include interface)
Para começar:
#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;
}