1.下载 1.0或者2.0 版本opencv
2.
./configure --host=arm-linux --without-gtk --without-carbon --without-quicktime --without-1394libs --without-ffmpeg --without-python --without-swig --enable-static --disable-shared --disable-apps CXX=arm-linux-g++ CPPFLAGS=-I/opt/FriendlyARM/toolschain/4.5.1/arm-none-linux-gnueabi/include
./configure --host=arm-linux --without-gtk --without-carbon --without-quicktime --without-1394libs --without-ffmpeg --without-python --without-swig --enable-static --disable-shared --disable-apps CXX=arm-linux-g++ CPPFLAGS=-I/opt/FriendlyARM/toolschain/4.5.1/arm-none-linux-gnueabi/include LDFLAGS=-L/opt/FriendlyARM/toolschain/4.5.1/arm-none-linux-gnueabi/lib --with-v4l --prefix=/opt/opencv-arm --libdir=/opt/opencv-arm/lib --includedir=/opt/opencv-arm/include
- --host=arm-linux :指出交叉编译arm平台
- --without-gtk:忽略gtk+2.0 windows
- --without-carbon: 不使用Mac OS上的X库
- --without-quicktime
- --without-1394libs
- --without-ffmpeg
- --without-python
- --without-swig
- --enable-static :生成静态库
- --disable-shared:不生成动态库
- CXX=arm-linux-g++ : 指定编译工具(建议用2.95.2或者2.95.3版本)
- CPPFLAGS=-I/usr/include :OpenCV会用到一些dev的包,如png.h,jpeglib.h,大部分头文件在/usr/include下。
如果在编译时出现png.h: No such file or directory ,意即缺少开发包,比如在Debian下可以apt-get install libpng2-dev,或者到libpng的网站 http://www.libpng.org/pub/png/libpng.html ,编译安装开发包即可。
make make install export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
接着,根据需要在/usr/local/lib/pkgconfig/opencv.pc的Libs项中加入参数-lpthread、-ldl之类,例如
Libs: -L${libdir} -lcv -lcxcore -lcvaux -lml -lpthread -ldl //这里是加入以前没有的库就可以了 否则会显示多次加载 最后结果:Libs: -L${libdir} -lcv -lhighgui -lcvaux -lml -lcxcore -lpthread -ldl -lrt -fopenmp
编译例程
- 编译例程drawing.c
-
arm-linux-g++ drawing.c `pkg-config --cflags --libs opencv` -o drawing
arm-linux-g++ drawing.c -o drawing -I/root/opencv-arm/include/opencv -L/root/opencv-arm/lib -lcv -lhighgui -lcvaux -lml -lcxcore -lpthread -ldl -lrt -fopenmp
- 编译修改后的摄像头标定程序:
-
arm-linux-g++ `pkg-config --cflags --libs opencv` calibration.cpp -o calibration
将生成的可执行程序拷贝到开发板上,运行。如果出现缺少libstdc++库的情况,可以在arm编译器目录下的lib目录中查找,拷贝到开发板中,并确保程序可以找到即可。
摄像头驱动
内核选项加入ovXXXX 驱动,并且模块加载。OpenCV程序中默认设备为/dev/video0 ,在程序中调用cvCaptureFromCAM函数可以直接获取摄像头,并采集图像。
显示
直接在要显示的地方调用显示驱动函数。