1.从官网(http://opencv.org/)上下载源码,编译安装,编译通过,未发现错误。
2.编写了如下测试程序:
//showImage.cpp
#include "highgui.h" int main( int argc, char **argv ) { IplImage *img = cvLoadImage( argv[1] ); cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE); cvShowImage("Example1", img); cvWaitKey(0); cvReleaseImage(&img); cvDestroyWindow("Example1"); return 0; }
编译:根据网上的文档,使用如下参数编译
g++ `pkg-config --cflags --libs opencv` showImage.cpp -o showImage
提示错误,函数未定义:
showImage.cpp:(.text+0x1d): undefined reference to `cvLoadImage' showImage.cpp:(.text+0x35): undefined reference to `cvNamedWindow' showImage.cpp:(.text+0x49): undefined reference to `cvShowImage' showImage.cpp:(.text+0x55): undefined reference to `cvWaitKey' showImage.cpp:(.text+0x61): undefined reference to `cvReleaseImage' showImage.cpp:(.text+0x6d): undefined reference to `cvDestroyWindow' collect2: ld 返回 1
解决办法:必须指定链接目录和库。`pkg-config --cflags --libs opencv`貌似不起作用
g++ showImage.cpp -o showImage -I /usr/local/include/opencv -lopencv_highgui -lopencv_core
编译成功。
3.运行程序,发现出错
OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvNamedWindow................略
解决办法:根据提示安装libgtk2.0-dev,并且重新编译opencv的源码。然后再编译此程序,运行成功。
4.编译另一个播放AVI视频的程序:
//showAVI.cpp #include "highgui.h" int main(int argc, char** argv) { cvNamedWindow("Example2", CV_WINDOW_AUTOSIZE); CvCapture* capture = cvCreateFileCapture(argv[1]); IplImage* frame; while(1) { frame = cvQueryFrame(capture); if(!frame) break; cvShowImage("Example2", frame); char c = cvWaitKey(33); if(c == 27) break; } cvReleaseCapture(&capture); cvDestroyWindow("Example2"); return 0; }
编译后,运行出错:
Gtk-WARNING **: Unable to locate theme engine in module_path: "pixmap"
解决办法:
sudo apt-get install gtk2-engines-pixbuf
重新编译opencv源码和此程序,发现能运行,但是无法读取avi视频,也无错误信息输出。
gdb跟踪调试后发现cvCreateFileCapture()函数返回NULL,再次google之后发现缺少ffmpeg。于是
sudo apt-get install ffmpeg
重新编译后还是如此。cmake生成Makefile的时候认真阅读了输出信息,发现缺少很多依赖。
目前在逐一补充所需依赖...
真不明白为什么缺少这么多文件还可以完全opencv的源码编译....