error OpenCV C ++ en Xcode
Pregunta
He construido las bibliotecas OpenCV utilizando el sistema de acumulación cmake
como se describe aquí y han añadido la cabecera, '.a' y los archivos '' .dylib a mi proyecto de la terminal C ++. Sin embargo, cuando ejecuto el código de abajo (lo recibió de http://iphone-cocoa-objectivec.blogspot.com/2009/01/using-opencv-for-mac-os-in-xcode.html ), me da la errores a continuación. ¿Alguien tiene algún consejo? Cualquier ayuda será muy 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;
}
Errores
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
Solución
Evitar el uso de Xcode con OpenCV 2.0. Si se utiliza OpenCV utilizar Windows y también utilizar OpenCV 1.1. Se ahorrará muchos dolores de cabeza. Cuando 2.0 / Mac están mejor documentados a continuación, la transición a la versión Mac plataforma / 2.0. El libro (O'Reilly) es bueno - cubre v1.1. El siguiente tramo de 2.0 debe seguir pronto. 1.
Otros consejos
En primer lugar, no construyen las librerías con CMake, mejor obtenerlos de macports en mac, puede actualizar fácilmente a la nueva versión con una sola línea ...
Además, si desea utilizar las interfaces cv::Mat
con fotos
#include <opencv2/core/core.hpp>
y #include <opencv2/highgui/highgui.hpp>
cosas irían mejor ...;) Incluir las bibliotecas dylib con versiones al final de su nombre. (Creo que los dylibs sin versiones son para el viejo # include interfaz)
Para empezar:
#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;
}