我是打开cv的新手。目前,我正在尝试测试是否可以运行一个简单的文件。
// Example showing how to read and write images
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv/cvaux.h>
int main(int argc, char** argv)
{
IplImage * pInpImg = 0;
// Load an image from file - change this based on your image name
pInpImg = cvLoadImage("bear.jpg", CV_LOAD_IMAGE_UNCHANGED);
if(!pInpImg)
{
fprintf(stderr, "failed to load input imagen");
return -1;
}
// Write the image to a file with a different name,
// using a different image format -- .png instead of .jpg
if( !cvSaveImage("my_image_copy.png", pInpImg) )
{
fprintf(stderr, "failed to write image filen");
}
// Remember to free image memory after using it!
cvReleaseImage(&pInpImg);
return 0;
}
我编译了它:
g++ `pkg-config –cflags opencv` cv.cpp -o cv `pkg-config –libs opencv`
我收到此错误:
Undefined symbols for architecture x86_64:
"_cvLoadImage", referenced from:
_main in cv-zQ5X30.o
"_cvReleaseImage", referenced from:
_main in cv-zQ5X30.o
"_cvSaveImage", referenced from:
_main in cv-zQ5X30.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我在这里迷路了,任何帮助将不胜感激。谢谢。
我认为问题可能是使用"-libs"和"-cflags"而不是"--libs"和"--cflags",请改用这个:
g++ `pkg-config --cflags opencv` cv.cpp -o cv `pkg-config --libs opencv`