http://blog.youkuaiyun.com/noodies/article/details/5798434
编译OpenCV for arm-linux(库文件libcv.so.2.1.0编译成为了x86-64格式)
编译OpenCV-2.1.0 for arm-linux-gcc4.3.2(库文件libcv.so.2.1.0编译成为了x86-64格式)
标签: referencemakefile嵌入式tiffgeneratorlinker
2010-08-09 11:41 18154人阅读 评论(52) 收藏 举报
分类: 嵌入式系统(5) Linux(7)
版权声明:本文为博主原创文章,未经博主允许不得转载。
OpenCV是Intel支持的开源计算机视觉库。它由一系列C函数和少量C++类构成,实现了图像处理和计算机视觉方面的很多通用算法。它不依赖于其它的外部库—尽管也可以使用某些外部库。
OpenCV使用BSD License,对非商业应用和商业应用都可以免费使用。
OpenCV的主要应用环境是Windows和Linux,对于嵌入式系统如arm-linux,很少有资料提到,因此将我在arm-linux编译过程记录下来和大家分享。
预备工作:
a. 安装交叉编译链
我使用的是arm-linux-gcc 4.3.2,解压到目录/usr/local/arm/4.3.2,然后在环境变量PATH中增加/usr/local/arm/4.3.2/bin
rootroot@rootroot-virtual-machine:~/wyb$ tar zxvf arm-linux-gcc-4.3.2.tgz
ootroot@rootroot-virtual-machine:~/wyb$ cd usr/local/
rootroot@rootroot-virtual-machine:~/wyb/usr/local$ sudo mv arm/ /usr/local/
[sudo] password for rootroot:
rootroot@rootroot-virtual-machine:~/wyb/usr/local$
rootroot@rootroot-virtual-machine:~/wyb/usr/local$ cd /usr/local/
rootroot@rootroot-virtual-machine:/usr/local$ sudo chmod 777 arm/ -R
rootroot@rootroot-virtual-machine:~$
rootroot@rootroot-virtual-machine:~$
rootroot@rootroot-virtual-machine:~$ sudo apt-get update
[sudo] password for rootroot:
rootroot@rootroot-virtual-machine:~$ sudo apt-get install lsb-core
http://www.cmake.org/files/v2.8/cmake-2.8.2-Linux-i386.tar.gz
http://www.cmake.org/files/v2.8/
b. 安装CMake
OpenCV 2.0之后的版本,必须使用CMake创建Makefile。我使用的CMake版本是2.8.2,解压到目录/usr/local/cmake-2.8.2-Linux-i386,然后在环境变量PATH中增加/usr/local/cmake-2.8.2-Linux-i386/bin
rootroot@rootroot-virtual-machine:~/wyb$ tar zxvf cmake-2.8.2-Linux-i386.tar.gz
rootroot@rootroot-virtual-machine:~/wyb$ sudo mv cmake-2.8.2-Linux-i386 /usr/local/
rootroot@rootroot-virtual-machine:~/wyb$ sudo chmod 777 /usr/local/cmake-2.8.2-Linux-i386/ -R
rootroot@rootroot-virtual-machine:~$ cp .bashrc bak1.bashrc
rootroot@rootroot-virtual-machine:~$ diff .bashrc bak1.bashrc
115,118d114
<
<
< export PATH=$PATH:/usr/local/cmake-2.8.2-Linux-i386/bin
<
rootroot@rootroot-virtual-machine:~$
编译OpenCV:
rootroot@cm-System-Product-Name:/home/wwt$ wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2/download
--2016-11-24 14:22:05-- http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2/download
正在解析主机 sourceforge.net (sourceforge.net)... 216.34.181.60
正在连接 sourceforge.net (sourceforge.net)|216.34.181.60|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 301 Moved Permanently
位置:https://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2/download [跟随至新的 URL]
--2016-11-24 14:22:07-- https://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2/download
正在连接 sourceforge.net (sourceforge.net)|216.34.181.60|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2?r=&ts=1479968535&use_mirror=nchc [跟随至新的 URL]
--2016-11-24 14:22:15-- http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2?r=&ts=1479968535&use_mirror=nchc
正在解析主机 downloads.sourceforge.net (downloads.sourceforge.net)... 216.34.181.59
正在连接 downloads.sourceforge.net (downloads.sourceforge.net)|216.34.181.59|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:http://nchc.dl.sourceforge.net/project/opencvlibrary/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2 [跟随至新的 URL]
--2016-11-24 14:22:16-- http://nchc.dl.sourceforge.net/project/opencvlibrary/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2
正在解析主机 nchc.dl.sourceforge.net (nchc.dl.sourceforge.net)... 211.79.60.17, 2001:e10:ffff:1f02::17
正在连接 nchc.dl.sourceforge.net (nchc.dl.sourceforge.net)|211.79.60.17|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:http://101.110.118.69/nchc.dl.sourceforge.net/project/opencvlibrary/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2 [跟随至新的 URL]
--2016-11-24 14:22:18-- http://101.110.118.69/nchc.dl.sourceforge.net/project/opencvlibrary/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2
正在连接 101.110.118.69:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度: 14459566 (14M) [application/octet-stream]
正在保存至: “download”
1、解压OpenCV 2.1到/usr/local/OpenCV-2.1.0目录下
rootroot@rootroot-virtual-machine:~/wyb$ tar jxvf OpenCV-2.1.0.tar.bz2
rootroot@rootroot-virtual-machine:~/wyb$ sudo mv OpenCV-2.1.0 /usr/local/
2、创建/usr/local/opencv-arm/目录,作为CMake编译arm版本的工作目录
rootroot@rootroot-virtual-machine:~/wyb$ sudo mkdir -p /usr/local/opencv-arm/
rootroot@rootroot-virtual-machine:~$ cd wyb/cmake-2.8.2-Linux-i386/bin/
rootroot@rootroot-virtual-machine:~/wyb/cmake-2.8.2-Linux-i386/bin$ ll
total 35408
drwxrwxr-x 2 rootroot rootroot 4096 1月 12 16:43 ./
drwxrwxr-x 6 rootroot rootroot 4096 1月 12 16:43 ../
-rwxr-xr-x 1 rootroot rootroot 4769652 6月 28 2010 ccmake*
-rwxr-xr-x 1 rootroot rootroot 4596128 6月 28 2010 cmake*
-rwxr-xr-x 1 rootroot rootroot 16134364 6月 28 2010 cmake-gui*
-rwxr-xr-x 1 rootroot rootroot 4839828 6月 28 2010 cpack*
-rwxr-xr-x 1 rootroot rootroot 5896652 6月 28 2010 ctest*
rootroot@rootroot-virtual-machine:~/wyb/cmake-2.8.2-Linux-i386/bin$ ./cmake-gui
./cmake-gui: error while loading shared libraries: libSM.so.6: cannot open shared object file: No such file or directory
rootroot@rootroot-virtual-machine:~/wyb/cmake-2.8.2-Linux-i386/bin$
3、在X环境下,运行cmake-gui
选择源代码目录:/usr/local/OpenCV-2.1.0
选择Build目录:/usr/local/opencv-arm/
点击Configure,保持generator为Unix Makefiles,选择Specify options for cross-compiling,点击Next
Operating System填写arm-inux
C Compilers填写/usr/local/arm/4.3.2/bin/arm-linux-gcc
C++ Compilers填写/usr/local/arm/4.3.2/bin/arm-linux-g++
程序库的Target Root填写/usr/local/arm/4.3.2/,然后点击Finish
修改默认配置,默认安装目录为/usr/local,对于交叉编译的库来说并不合适,所以我把CMAKE_INSTALL_PREFIX变量改为/usr/local/arm/lib/opencv/
另外,我没有安装tiff图像的支持,因此去掉WITH_TIFF
点击Generate生成Makefile
/home/rootroot/wyb/OpenCV-2.1.0/
/usr/local/opencv-arm/
arm-linux
/usr/local/arm/4.3.2/bin/arm-linux-gcc
/usr/local/arm/4.3.2/bin/arm-linux-g++
/usr/local/arm/4.3.2/
rootroot@rootroot-virtual-machine:/usr/local/opencv-arm$ make
[ 44%] Building CXX object src/cxcore/CMakeFiles/cxcore.dir/cxalloc.o
In file included from /usr/local/OpenCV-2.1.0/include/opencv/cxcore.h:1826:0,
from /usr/local/OpenCV-2.1.0/src/cxcore/_cxcore.h:51,
from /usr/local/OpenCV-2.1.0/src/cxcore/cxalloc.cpp:43:
/usr/local/OpenCV-2.1.0/include/opencv/cxcore.hpp:177:13: error: ‘ptrdiff_t’ does not name a type
typedef ptrdiff_t difference_type;
^
In file included from /usr/local/OpenCV-2.1.0/include/opencv/cxcore.hpp:2307:0,
from /usr/local/OpenCV-2.1.0/include/opencv/cxcore.h:1826,
from /usr/local/OpenCV-2.1.0/src/cxcore/_cxcore.h:51,
http://blog.youkuaiyun.com/tfygg/article/details/37910025
opencv在linux下的安装
之后就是make ; make install 当然这中间也遇到一些问题。具体如下:
(1)../include/opencv/cxcore.hpp:169:13: error: 'ptrdiff_t' does not name a type
../include/opencv/cxoperations.hpp:1916:15: error: 'ptrdiff_t' does not name a type
../include/opencv/cxoperations.hpp:2465:31: error: 'ptrdiff_t' does not name a type
../include/opencv/cxmat.hpp:356:15: error: expected ';' before 'delta1'
../include/opencv/cxmat.hpp:358:9: error: 'delta1' was not declared in this scope
../include/opencv/cxmat.hpp:367:31: error: 'delta2' was not declared in this scope
上面这个问题只需要在OpenCV2.0.0/include/opencv/cxcore.hpp文件中加入:
using std::vector;
using std::string;
+using std::ptrdiff_t;
template<typename _Tp> class CV_EXPORTS Size_;
template<typename _Tp> class CV_EXPORTS Point_;
加了这一句话就好了
[ 72%] Building CXX object src/highgui/CMakeFiles/highgui.dir/cvcap.o
[ 72%] Building CXX object src/highgui/CMakeFiles/highgui.dir/cvcap_images.o
[ 72%] Building CXX object src/highgui/CMakeFiles/highgui.dir/image.o
[ 72%] Building CXX object src/highgui/CMakeFiles/highgui.dir/loadsave.o
/usr/local/OpenCV-2.1.0/src/highgui/loadsave.cpp: In function ‘void* cv::imdecode_(const cv::Mat&, int, int, cv::Mat*)’:
/usr/local/OpenCV-2.1.0/src/highgui/loadsave.cpp:333:28: error: ‘unlink’ was not declared in this scope
unlink(filename);
http://www.mamicode.com/info-detail-23747.html
ZOJ3672:Gao The Sequence
安装opencv2.0
error: highgui/loadsave.cpp:333:28: error: ‘unlink’ was not declared in this scope 解决方法:
vi src/highgui/loadsave.cpp
加入:
#include<unistd.h>
Linking CXX static library ../../lib/libcvhaartraining.a
[ 86%] Built target cvhaartraining
Scanning dependencies of target createsamples
[ 86%] Building CXX object apps/haartraining/CMakeFiles/createsamples.dir/createsamples.o
Linking CXX executable ../../bin/opencv_createsamples
../../lib/libhighgui.so.2.1.0: undefined reference to `cvCreateCameraCapture_V4L(int)'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/opencv_createsamples] Error 1
make[1]: *** [apps/haartraining/CMakeFiles/createsamples.dir/all] Error 2
make: *** [all] Error 2
rootroot@rootroot-virtual-machine:/usr/local/opencv-arm$
rootroot@rootroot-virtual-machine:/usr/local/opencv-arm$ cd /usr/local/OpenCV-2.1.0/src/highgui/
rootroot@rootroot-virtual-machine:/usr/local/OpenCV-2.1.0/src/highgui$ sudo cp cvcap_v4l.cpp cvcap_v4l.cpp.bak
[sudo] password for rootroot:
rootroot@rootroot-virtual-machine:/usr/local/OpenCV-2.1.0/src/highgui$ sudo cp cvcap.cpp cvcap.cpp.bak
rootroot@rootroot-virtual-machine:/usr/local/OpenCV-2.1.0/src/highgui$
http://blog.youkuaiyun.com/dayeshisir/article/details/6625400
fedora 15 安装opencv2.2时出现undefined reference to `cvCreateCameraCapture_V4L(int)'问题及其解决方法
/usr/local/OpenCV-2.1.0/tests/cv/src/anearestneighbors.cpp:513:22: error: ‘unlink’ was not declared in this scope
unlink( filename );
^
/usr/local/OpenCV-2.1.0/tests/cv/src/anearestneighbors.cpp:509:23: warning: ignoring return value of ‘char* tmpnam(char*)’, declared with attribute warn_unused_result [-Wunused-result]
tmpnam( filename );
^
make[2]: *** [tests/cv/CMakeFiles/cvtest.dir/src/anearestneighbors.o] Error 1
make[1]: *** [tests/cv/CMakeFiles/cvtest.dir/all] Error 2
make: *** [all] Error 2
rootroot@rootroot-virtual-machine:/usr/local/opencv-arm$
/usr/local/OpenCV-2.1.0/tests/cxcore/src/aio.cpp:429:28: error: ‘unlink’ was not declared in this scope
unlink(filename);
^
make[2]: *** [tests/cxcore/CMakeFiles/cxcoretest.dir/src/aio.o] Error 1
make[1]: *** [tests/cxcore/CMakeFiles/cxcoretest.dir/all] Error 2
make: *** [all] Error 2
rootroot@rootroot-virtual-machine:/usr/local/opencv-arm$ cd /usr/local/OpenCV-2.1.0/tests/cxcore/src/
[ 99%] Building CXX object tests/ml/CMakeFiles/mltest.dir/src/slmltests.o
/usr/local/OpenCV-2.1.0/tests/ml/src/slmltests.cpp: In member function ‘virtual int CV_SLMLTest::validate_test_results(int)’:
/usr/local/OpenCV-2.1.0/tests/ml/src/slmltests.cpp:104:20: error: ‘unlink’ was not declared in this scope
unlink( fname1 );
^
make[2]: *** [tests/ml/CMakeFiles/mltest.dir/src/slmltests.o] Error 1
make[1]: *** [tests/ml/CMakeFiles/mltest.dir/all] Error 2
make: *** [all] Error 2
[ 99%] Building CXX object tests/ml/CMakeFiles/mltest.dir/src/slmltests.o
/usr/local/OpenCV-2.1.0/tests/ml/src/slmltests.cpp: In member function ‘virtual int CV_SLMLTest::validate_test_results(int)’:
/usr/local/OpenCV-2.1.0/tests/ml/src/slmltests.cpp:104:20: error: ‘unlink’ was not declared in this scope
unlink( fname1 );
^
make[2]: *** [tests/ml/CMakeFiles/mltest.dir/src/slmltests.o] Error 1
make[1]: *** [tests/ml/CMakeFiles/mltest.dir/all] Error 2
make: *** [all] Error 2
rootroot@rootroot-virtual-machine:/usr/local/opencv-arm$ cd /usr/local/OpenCV-2.1.0/tests/ml/src/
[100%] Building CXX object tests/ml/CMakeFiles/mltest.dir/src/amltests.o
Linking CXX executable ../../bin/mltest
CMakeFiles/mltest.dir/src/slmltests.o: In function `CV_SLMLTest::run_test_case(int)':
slmltests.cpp:(.text._ZN11CV_SLMLTest13run_test_caseEi+0x92): warning: the use of `tmpnam' is dangerous, better use `mkstemp'
[100%] Built target mltest
rootroot@rootroot-virtual-machine:/usr/local/opencv-arm$
rootroot@rootroot-virtual-machine:/usr/local/opencv-arm$
rootroot@rootroot-virtual-machine:/usr/local/opencv-arm$
4、在终端界面中,进入目录/usr/local/opencv-arm,运行make编译opencv
编译时发现如下错误:
Linking CXX executable ../../bin/opencv_createsamples
../../lib/libcxcore.so: undefined reference to `clock_gettime'
../../lib/libcxcore.so: undefined reference to `pthread_key_create'
../../lib/libcxcore.so: undefined reference to `pthread_getspecific'
../../lib/libcxcore.so: undefined reference to `pthread_setspecific'
原因是cmake不认识我定义的arm-linux系统标记,没有加上库pthread和rt的链接选项
没有碰到这里
5、修改CMakeCache.txt,CMAKE_EXE_LINKER_FLAGS原来为空,加上-lpthread -lrt,重新编译,错误消除
6、运行make install,将opencv生成的库和头文件安装到目录/usr/local/arm/lib/opencv/
测试OpenCV库
1、首先确认一下库是否已编译正确及其安装位置
查看头文件:
[c-sharp] view plain copy
[root@localhost opencv-arm]# ls /usr/local/arm/lib/opencv/include/opencv/
cvaux.h cvcompat.h cv.hpp cvtypes.h cvvidsurv.hpp cxcore.h cxerror.h cxmat.hpp cxoperations.hpp highgui.h ml.h
cvaux.hpp cv.h cvinternal.h cvver.h cvwimage.h cxcore.hpp cxflann.h cxmisc.h cxtypes.h highgui.hpp
rootroot@rootroot-virtual-machine:/usr/local$ cd /usr/local/arm/lib/opencv/include/opencv/
rootroot@rootroot-virtual-machine:/usr/local/arm/lib/opencv/include/opencv$ ll
total 1000
drwxrwxr-x 2 rootroot rootroot 4096 1月 12 18:23 ./
drwxrwxr-x 3 rootroot rootroot 4096 1月 12 18:23 ../
-rw-r--r-- 1 rootroot rootroot 66326 4月 6 2010 cvaux.h
-rw-r--r-- 1 rootroot rootroot 68287 4月 6 2010 cvaux.hpp
-rw-r--r-- 1 rootroot rootroot 40693 4月 6 2010 cvcompat.h
-rw-r--r-- 1 rootroot rootroot 72383 4月 6 2010 cv.h
-rw-r--r-- 1 rootroot rootroot 46827 4月 6 2010 cv.hpp
-rw-r--r-- 1 rootroot rootroot 6164 4月 6 2010 cvinternal.h
-rw-r--r-- 1 rootroot rootroot 11734 4月 6 2010 cvtypes.h
-rw-r--r-- 1 rootroot rootroot 2534 4月 6 2010 cvver.h
-rw-r--r-- 1 rootroot rootroot 42000 4月 6 2010 cvvidsurv.hpp
-rw-r--r-- 1 rootroot rootroot 20724 4月 6 2010 cvwimage.h
-rw-r--r-- 1 rootroot rootroot 77824 4月 6 2010 cxcore.h
-rw-r--r-- 1 rootroot rootroot 83148 1月 12 17:38 cxcore.hpp
-rw-r--r-- 1 rootroot rootroot 8750 4月 6 2010 cxerror.h
-rw-r--r-- 1 rootroot rootroot 6936 4月 6 2010 cxflann.h
-rw-r--r-- 1 rootroot rootroot 153155 4月 6 2010 cxmat.hpp
-rw-r--r-- 1 rootroot rootroot 27971 4月 6 2010 cxmisc.h
-rw-r--r-- 1 rootroot rootroot 90263 4月 6 2010 cxoperations.hpp
-rw-r--r-- 1 rootroot rootroot 53078 4月 6 2010 cxtypes.h
-rw-r--r-- 1 rootroot rootroot 18598 4月 6 2010 highgui.h
-rw-r--r-- 1 rootroot rootroot 4823 4月 6 2010 highgui.hpp
-rw-r--r-- 1 rootroot rootroot 72789 4月 6 2010 ml.h
rootroot@rootroot-virtual-machine:/usr/local/arm/lib/opencv/include/opencv$
查看库文件:
[c-sharp] view plain copy
[root@localhost opencv-arm]# ls /usr/local/arm/lib/opencv/lib
libcv.a libcvaux.a libcvaux.so libcv.so libcxcore.a libcxcore.so libhighgui.a libhighgui.so libml.a libml.so
rootroot@rootroot-virtual-machine:/usr/local/arm/lib/opencv/lib$ ll
total 8776
drwxrwxr-x 3 rootroot rootroot 4096 1月 12 18:23 ./
drwxrwxrwx 6 rootroot rootroot 4096 1月 12 18:23 ../
lrwxrwxrwx 1 rootroot rootroot 15 1月 12 18:23 libcvaux.so -> libcvaux.so.2.1
lrwxrwxrwx 1 rootroot rootroot 17 1月 12 18:23 libcvaux.so.2.1 -> libcvaux.so.2.1.0
-rw-r--r-- 1 rootroot rootroot 1351098 1月 12 18:23 libcvaux.so.2.1.0
lrwxrwxrwx 1 rootroot rootroot 12 1月 12 18:23 libcv.so -> libcv.so.2.1
lrwxrwxrwx 1 rootroot rootroot 14 1月 12 18:23 libcv.so.2.1 -> libcv.so.2.1.0
-rw-r--r-- 1 rootroot rootroot 2821335 1月 12 18:23 libcv.so.2.1.0
lrwxrwxrwx 1 rootroot rootroot 16 1月 12 18:23 libcxcore.so -> libcxcore.so.2.1
lrwxrwxrwx 1 rootroot rootroot 18 1月 12 18:23 libcxcore.so.2.1 -> libcxcore.so.2.1.0
-rw-r--r-- 1 rootroot rootroot 3357666 1月 12 18:23 libcxcore.so.2.1.0
lrwxrwxrwx 1 rootroot rootroot 17 1月 12 18:23 libhighgui.so -> libhighgui.so.2.1
lrwxrwxrwx 1 rootroot rootroot 19 1月 12 18:23 libhighgui.so.2.1 -> libhighgui.so.2.1.0
-rw-r--r-- 1 rootroot rootroot 943890 1月 12 18:23 libhighgui.so.2.1.0
lrwxrwxrwx 1 rootroot rootroot 12 1月 12 18:23 libml.so -> libml.so.2.1
lrwxrwxrwx 1 rootroot rootroot 14 1月 12 18:23 libml.so.2.1 -> libml.so.2.1.0
-rw-r--r-- 1 rootroot rootroot 491953 1月 12 18:23 libml.so.2.1.0
drwxrwxr-x 2 rootroot rootroot 4096 1月 12 18:23 pkgconfig/
rootroot@rootroot-virtual-machine:/usr/local/arm/lib/opencv/lib$
2、写个简单的测试程序,打开摄像头并创建一个窗口显示
// test.cpp
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
int main()
{
CvCapture* capture = NULL;
IplImage* frame = NULL;
if( !(capture = cvCaptureFromCAM(-1)))
{
fprintf(stderr, "Can not open camera./n");
return -1;
}
cvNamedWindow("video", 1);
while(frame = cvQueryFrame( capture ) )
{
cvShowImage("video", frame);
}
cvDestroyWindow("video");
cvReleaseCapture(&capture);
return 0;
}
3、编译链接测试程序
arm-linux-g++ -I/usr/local/arm/lib/opencv/include/opencv/ -L/usr/local/arm/lib/opencv/lib/ -lcv -lcxcore -lhighgui -lpthread -lrt -o test test.cpp
rootroot@rootroot-virtual-machine:~/wyb$ arm-linux-g++ -I/usr/local/arm/lib/opencv/include/opencv/ -L/usr/local/arm/lib/opencv/lib -lcv -lcxcore -lhighgui -lpthread -lrt -o test test.cpp
/usr/local/arm/lib/opencv/lib/libcv.so: file not recognized: File format not recognized
collect2: ld returned 1 exit status
rootroot@rootroot-virtual-machine:~/wyb$
rootroot@rootroot-virtual-machine:/usr/local/arm/lib/opencv/lib$ file libcv.so.2.1.0
libcv.so.2.1.0: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=7f04c77df448080762e47b6f746e5db2e340251d, not stripped
rootroot@rootroot-virtual-machine:/usr/local/arm/lib/opencv/lib$
http://stackoverflow.com/questions/14404445/g-throwing-file-not-recognized-file-format-not-recognized-error
g++ throwing file not recognized: File format not recognized error
getting following error with the command g++ -o test -L . -l pq
libpq.so: file not recognized: File format not recognized
#file libpq.so
libpq.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), not stripped
4、复制程序到嵌入式系统中运行
编译OpenCV for arm-linux(库文件libcv.so.2.1.0编译成为了x86-64格式)
编译OpenCV-2.1.0 for arm-linux-gcc4.3.2(库文件libcv.so.2.1.0编译成为了x86-64格式)
标签: referencemakefile嵌入式tiffgeneratorlinker
2010-08-09 11:41 18154人阅读 评论(52) 收藏 举报
分类: 嵌入式系统(5) Linux(7)
版权声明:本文为博主原创文章,未经博主允许不得转载。
OpenCV是Intel支持的开源计算机视觉库。它由一系列C函数和少量C++类构成,实现了图像处理和计算机视觉方面的很多通用算法。它不依赖于其它的外部库—尽管也可以使用某些外部库。
OpenCV使用BSD License,对非商业应用和商业应用都可以免费使用。
OpenCV的主要应用环境是Windows和Linux,对于嵌入式系统如arm-linux,很少有资料提到,因此将我在arm-linux编译过程记录下来和大家分享。
预备工作:
a. 安装交叉编译链
我使用的是arm-linux-gcc 4.3.2,解压到目录/usr/local/arm/4.3.2,然后在环境变量PATH中增加/usr/local/arm/4.3.2/bin
rootroot@rootroot-virtual-machine:~/wyb$ tar zxvf arm-linux-gcc-4.3.2.tgz
ootroot@rootroot-virtual-machine:~/wyb$ cd usr/local/
rootroot@rootroot-virtual-machine:~/wyb/usr/local$ sudo mv arm/ /usr/local/
[sudo] password for rootroot:
rootroot@rootroot-virtual-machine:~/wyb/usr/local$
rootroot@rootroot-virtual-machine:~/wyb/usr/local$ cd /usr/local/
rootroot@rootroot-virtual-machine:/usr/local$ sudo chmod 777 arm/ -R
rootroot@rootroot-virtual-machine:~$
rootroot@rootroot-virtual-machine:~$
rootroot@rootroot-virtual-machine:~$ sudo apt-get update
[sudo] password for rootroot:
rootroot@rootroot-virtual-machine:~$ sudo apt-get install lsb-core
http://www.cmake.org/files/v2.8/cmake-2.8.2-Linux-i386.tar.gz
http://www.cmake.org/files/v2.8/
b. 安装CMake
OpenCV 2.0之后的版本,必须使用CMake创建Makefile。我使用的CMake版本是2.8.2,解压到目录/usr/local/cmake-2.8.2-Linux-i386,然后在环境变量PATH中增加/usr/local/cmake-2.8.2-Linux-i386/bin
rootroot@rootroot-virtual-machine:~/wyb$ tar zxvf cmake-2.8.2-Linux-i386.tar.gz
rootroot@rootroot-virtual-machine:~/wyb$ sudo mv cmake-2.8.2-Linux-i386 /usr/local/
rootroot@rootroot-virtual-machine:~/wyb$ sudo chmod 777 /usr/local/cmake-2.8.2-Linux-i386/ -R
rootroot@rootroot-virtual-machine:~$ cp .bashrc bak1.bashrc
rootroot@rootroot-virtual-machine:~$ diff .bashrc bak1.bashrc
115,118d114
<
<
< export PATH=$PATH:/usr/local/cmake-2.8.2-Linux-i386/bin
<
rootroot@rootroot-virtual-machine:~$
编译OpenCV:
rootroot@cm-System-Product-Name:/home/wwt$ wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2/download
--2016-11-24 14:22:05-- http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2/download
正在解析主机 sourceforge.net (sourceforge.net)... 216.34.181.60
正在连接 sourceforge.net (sourceforge.net)|216.34.181.60|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 301 Moved Permanently
位置:https://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2/download [跟随至新的 URL]
--2016-11-24 14:22:07-- https://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2/download
正在连接 sourceforge.net (sourceforge.net)|216.34.181.60|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2?r=&ts=1479968535&use_mirror=nchc [跟随至新的 URL]
--2016-11-24 14:22:15-- http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2?r=&ts=1479968535&use_mirror=nchc
正在解析主机 downloads.sourceforge.net (downloads.sourceforge.net)... 216.34.181.59
正在连接 downloads.sourceforge.net (downloads.sourceforge.net)|216.34.181.59|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:http://nchc.dl.sourceforge.net/project/opencvlibrary/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2 [跟随至新的 URL]
--2016-11-24 14:22:16-- http://nchc.dl.sourceforge.net/project/opencvlibrary/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2
正在解析主机 nchc.dl.sourceforge.net (nchc.dl.sourceforge.net)... 211.79.60.17, 2001:e10:ffff:1f02::17
正在连接 nchc.dl.sourceforge.net (nchc.dl.sourceforge.net)|211.79.60.17|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:http://101.110.118.69/nchc.dl.sourceforge.net/project/opencvlibrary/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2 [跟随至新的 URL]
--2016-11-24 14:22:18-- http://101.110.118.69/nchc.dl.sourceforge.net/project/opencvlibrary/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2
正在连接 101.110.118.69:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度: 14459566 (14M) [application/octet-stream]
正在保存至: “download”
1、解压OpenCV 2.1到/usr/local/OpenCV-2.1.0目录下
rootroot@rootroot-virtual-machine:~/wyb$ tar jxvf OpenCV-2.1.0.tar.bz2
rootroot@rootroot-virtual-machine:~/wyb$ sudo mv OpenCV-2.1.0 /usr/local/
2、创建/usr/local/opencv-arm/目录,作为CMake编译arm版本的工作目录
rootroot@rootroot-virtual-machine:~/wyb$ sudo mkdir -p /usr/local/opencv-arm/
rootroot@rootroot-virtual-machine:~$ cd wyb/cmake-2.8.2-Linux-i386/bin/
rootroot@rootroot-virtual-machine:~/wyb/cmake-2.8.2-Linux-i386/bin$ ll
total 35408
drwxrwxr-x 2 rootroot rootroot 4096 1月 12 16:43 ./
drwxrwxr-x 6 rootroot rootroot 4096 1月 12 16:43 ../
-rwxr-xr-x 1 rootroot rootroot 4769652 6月 28 2010 ccmake*
-rwxr-xr-x 1 rootroot rootroot 4596128 6月 28 2010 cmake*
-rwxr-xr-x 1 rootroot rootroot 16134364 6月 28 2010 cmake-gui*
-rwxr-xr-x 1 rootroot rootroot 4839828 6月 28 2010 cpack*
-rwxr-xr-x 1 rootroot rootroot 5896652 6月 28 2010 ctest*
rootroot@rootroot-virtual-machine:~/wyb/cmake-2.8.2-Linux-i386/bin$ ./cmake-gui
./cmake-gui: error while loading shared libraries: libSM.so.6: cannot open shared object file: No such file or directory
rootroot@rootroot-virtual-machine:~/wyb/cmake-2.8.2-Linux-i386/bin$
3、在X环境下,运行cmake-gui
选择源代码目录:/usr/local/OpenCV-2.1.0
选择Build目录:/usr/local/opencv-arm/
点击Configure,保持generator为Unix Makefiles,选择Specify options for cross-compiling,点击Next
Operating System填写arm-inux
C Compilers填写/usr/local/arm/4.3.2/bin/arm-linux-gcc
C++ Compilers填写/usr/local/arm/4.3.2/bin/arm-linux-g++
程序库的Target Root填写/usr/local/arm/4.3.2/,然后点击Finish
修改默认配置,默认安装目录为/usr/local,对于交叉编译的库来说并不合适,所以我把CMAKE_INSTALL_PREFIX变量改为/usr/local/arm/lib/opencv/
另外,我没有安装tiff图像的支持,因此去掉WITH_TIFF
点击Generate生成Makefile
/home/rootroot/wyb/OpenCV-2.1.0/
/usr/local/opencv-arm/
arm-linux
/usr/local/arm/4.3.2/bin/arm-linux-gcc
/usr/local/arm/4.3.2/bin/arm-linux-g++
/usr/local/arm/4.3.2/
rootroot@rootroot-virtual-machine:/usr/local/opencv-arm$ make
[ 44%] Building CXX object src/cxcore/CMakeFiles/cxcore.dir/cxalloc.o
In file included from /usr/local/OpenCV-2.1.0/include/opencv/cxcore.h:1826:0,
from /usr/local/OpenCV-2.1.0/src/cxcore/_cxcore.h:51,
from /usr/local/OpenCV-2.1.0/src/cxcore/cxalloc.cpp:43:
/usr/local/OpenCV-2.1.0/include/opencv/cxcore.hpp:177:13: error: ‘ptrdiff_t’ does not name a type
typedef ptrdiff_t difference_type;
^
In file included from /usr/local/OpenCV-2.1.0/include/opencv/cxcore.hpp:2307:0,
from /usr/local/OpenCV-2.1.0/include/opencv/cxcore.h:1826,
from /usr/local/OpenCV-2.1.0/src/cxcore/_cxcore.h:51,
http://blog.youkuaiyun.com/tfygg/article/details/37910025
opencv在linux下的安装
之后就是make ; make install 当然这中间也遇到一些问题。具体如下:
(1)../include/opencv/cxcore.hpp:169:13: error: 'ptrdiff_t' does not name a type
../include/opencv/cxoperations.hpp:1916:15: error: 'ptrdiff_t' does not name a type
../include/opencv/cxoperations.hpp:2465:31: error: 'ptrdiff_t' does not name a type
../include/opencv/cxmat.hpp:356:15: error: expected ';' before 'delta1'
../include/opencv/cxmat.hpp:358:9: error: 'delta1' was not declared in this scope
../include/opencv/cxmat.hpp:367:31: error: 'delta2' was not declared in this scope
上面这个问题只需要在OpenCV2.0.0/include/opencv/cxcore.hpp文件中加入:
using std::vector;
using std::string;
+using std::ptrdiff_t;
template<typename _Tp> class CV_EXPORTS Size_;
template<typename _Tp> class CV_EXPORTS Point_;
加了这一句话就好了
[ 72%] Building CXX object src/highgui/CMakeFiles/highgui.dir/cvcap.o
[ 72%] Building CXX object src/highgui/CMakeFiles/highgui.dir/cvcap_images.o
[ 72%] Building CXX object src/highgui/CMakeFiles/highgui.dir/image.o
[ 72%] Building CXX object src/highgui/CMakeFiles/highgui.dir/loadsave.o
/usr/local/OpenCV-2.1.0/src/highgui/loadsave.cpp: In function ‘void* cv::imdecode_(const cv::Mat&, int, int, cv::Mat*)’:
/usr/local/OpenCV-2.1.0/src/highgui/loadsave.cpp:333:28: error: ‘unlink’ was not declared in this scope
unlink(filename);
http://www.mamicode.com/info-detail-23747.html
ZOJ3672:Gao The Sequence
安装opencv2.0
error: highgui/loadsave.cpp:333:28: error: ‘unlink’ was not declared in this scope 解决方法:
vi src/highgui/loadsave.cpp
加入:
#include<unistd.h>
Linking CXX static library ../../lib/libcvhaartraining.a
[ 86%] Built target cvhaartraining
Scanning dependencies of target createsamples
[ 86%] Building CXX object apps/haartraining/CMakeFiles/createsamples.dir/createsamples.o
Linking CXX executable ../../bin/opencv_createsamples
../../lib/libhighgui.so.2.1.0: undefined reference to `cvCreateCameraCapture_V4L(int)'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/opencv_createsamples] Error 1
make[1]: *** [apps/haartraining/CMakeFiles/createsamples.dir/all] Error 2
make: *** [all] Error 2
rootroot@rootroot-virtual-machine:/usr/local/opencv-arm$
rootroot@rootroot-virtual-machine:/usr/local/opencv-arm$ cd /usr/local/OpenCV-2.1.0/src/highgui/
rootroot@rootroot-virtual-machine:/usr/local/OpenCV-2.1.0/src/highgui$ sudo cp cvcap_v4l.cpp cvcap_v4l.cpp.bak
[sudo] password for rootroot:
rootroot@rootroot-virtual-machine:/usr/local/OpenCV-2.1.0/src/highgui$ sudo cp cvcap.cpp cvcap.cpp.bak
rootroot@rootroot-virtual-machine:/usr/local/OpenCV-2.1.0/src/highgui$
http://blog.youkuaiyun.com/dayeshisir/article/details/6625400
fedora 15 安装opencv2.2时出现undefined reference to `cvCreateCameraCapture_V4L(int)'问题及其解决方法
/usr/local/OpenCV-2.1.0/tests/cv/src/anearestneighbors.cpp:513:22: error: ‘unlink’ was not declared in this scope
unlink( filename );
^
/usr/local/OpenCV-2.1.0/tests/cv/src/anearestneighbors.cpp:509:23: warning: ignoring return value of ‘char* tmpnam(char*)’, declared with attribute warn_unused_result [-Wunused-result]
tmpnam( filename );
^
make[2]: *** [tests/cv/CMakeFiles/cvtest.dir/src/anearestneighbors.o] Error 1
make[1]: *** [tests/cv/CMakeFiles/cvtest.dir/all] Error 2
make: *** [all] Error 2
rootroot@rootroot-virtual-machine:/usr/local/opencv-arm$
/usr/local/OpenCV-2.1.0/tests/cxcore/src/aio.cpp:429:28: error: ‘unlink’ was not declared in this scope
unlink(filename);
^
make[2]: *** [tests/cxcore/CMakeFiles/cxcoretest.dir/src/aio.o] Error 1
make[1]: *** [tests/cxcore/CMakeFiles/cxcoretest.dir/all] Error 2
make: *** [all] Error 2
rootroot@rootroot-virtual-machine:/usr/local/opencv-arm$ cd /usr/local/OpenCV-2.1.0/tests/cxcore/src/
[ 99%] Building CXX object tests/ml/CMakeFiles/mltest.dir/src/slmltests.o
/usr/local/OpenCV-2.1.0/tests/ml/src/slmltests.cpp: In member function ‘virtual int CV_SLMLTest::validate_test_results(int)’:
/usr/local/OpenCV-2.1.0/tests/ml/src/slmltests.cpp:104:20: error: ‘unlink’ was not declared in this scope
unlink( fname1 );
^
make[2]: *** [tests/ml/CMakeFiles/mltest.dir/src/slmltests.o] Error 1
make[1]: *** [tests/ml/CMakeFiles/mltest.dir/all] Error 2
make: *** [all] Error 2
[ 99%] Building CXX object tests/ml/CMakeFiles/mltest.dir/src/slmltests.o
/usr/local/OpenCV-2.1.0/tests/ml/src/slmltests.cpp: In member function ‘virtual int CV_SLMLTest::validate_test_results(int)’:
/usr/local/OpenCV-2.1.0/tests/ml/src/slmltests.cpp:104:20: error: ‘unlink’ was not declared in this scope
unlink( fname1 );
^
make[2]: *** [tests/ml/CMakeFiles/mltest.dir/src/slmltests.o] Error 1
make[1]: *** [tests/ml/CMakeFiles/mltest.dir/all] Error 2
make: *** [all] Error 2
rootroot@rootroot-virtual-machine:/usr/local/opencv-arm$ cd /usr/local/OpenCV-2.1.0/tests/ml/src/
[100%] Building CXX object tests/ml/CMakeFiles/mltest.dir/src/amltests.o
Linking CXX executable ../../bin/mltest
CMakeFiles/mltest.dir/src/slmltests.o: In function `CV_SLMLTest::run_test_case(int)':
slmltests.cpp:(.text._ZN11CV_SLMLTest13run_test_caseEi+0x92): warning: the use of `tmpnam' is dangerous, better use `mkstemp'
[100%] Built target mltest
rootroot@rootroot-virtual-machine:/usr/local/opencv-arm$
rootroot@rootroot-virtual-machine:/usr/local/opencv-arm$
rootroot@rootroot-virtual-machine:/usr/local/opencv-arm$
4、在终端界面中,进入目录/usr/local/opencv-arm,运行make编译opencv
编译时发现如下错误:
Linking CXX executable ../../bin/opencv_createsamples
../../lib/libcxcore.so: undefined reference to `clock_gettime'
../../lib/libcxcore.so: undefined reference to `pthread_key_create'
../../lib/libcxcore.so: undefined reference to `pthread_getspecific'
../../lib/libcxcore.so: undefined reference to `pthread_setspecific'
原因是cmake不认识我定义的arm-linux系统标记,没有加上库pthread和rt的链接选项
没有碰到这里
5、修改CMakeCache.txt,CMAKE_EXE_LINKER_FLAGS原来为空,加上-lpthread -lrt,重新编译,错误消除
6、运行make install,将opencv生成的库和头文件安装到目录/usr/local/arm/lib/opencv/
测试OpenCV库
1、首先确认一下库是否已编译正确及其安装位置
查看头文件:
[c-sharp] view plain copy
[root@localhost opencv-arm]# ls /usr/local/arm/lib/opencv/include/opencv/
cvaux.h cvcompat.h cv.hpp cvtypes.h cvvidsurv.hpp cxcore.h cxerror.h cxmat.hpp cxoperations.hpp highgui.h ml.h
cvaux.hpp cv.h cvinternal.h cvver.h cvwimage.h cxcore.hpp cxflann.h cxmisc.h cxtypes.h highgui.hpp
rootroot@rootroot-virtual-machine:/usr/local$ cd /usr/local/arm/lib/opencv/include/opencv/
rootroot@rootroot-virtual-machine:/usr/local/arm/lib/opencv/include/opencv$ ll
total 1000
drwxrwxr-x 2 rootroot rootroot 4096 1月 12 18:23 ./
drwxrwxr-x 3 rootroot rootroot 4096 1月 12 18:23 ../
-rw-r--r-- 1 rootroot rootroot 66326 4月 6 2010 cvaux.h
-rw-r--r-- 1 rootroot rootroot 68287 4月 6 2010 cvaux.hpp
-rw-r--r-- 1 rootroot rootroot 40693 4月 6 2010 cvcompat.h
-rw-r--r-- 1 rootroot rootroot 72383 4月 6 2010 cv.h
-rw-r--r-- 1 rootroot rootroot 46827 4月 6 2010 cv.hpp
-rw-r--r-- 1 rootroot rootroot 6164 4月 6 2010 cvinternal.h
-rw-r--r-- 1 rootroot rootroot 11734 4月 6 2010 cvtypes.h
-rw-r--r-- 1 rootroot rootroot 2534 4月 6 2010 cvver.h
-rw-r--r-- 1 rootroot rootroot 42000 4月 6 2010 cvvidsurv.hpp
-rw-r--r-- 1 rootroot rootroot 20724 4月 6 2010 cvwimage.h
-rw-r--r-- 1 rootroot rootroot 77824 4月 6 2010 cxcore.h
-rw-r--r-- 1 rootroot rootroot 83148 1月 12 17:38 cxcore.hpp
-rw-r--r-- 1 rootroot rootroot 8750 4月 6 2010 cxerror.h
-rw-r--r-- 1 rootroot rootroot 6936 4月 6 2010 cxflann.h
-rw-r--r-- 1 rootroot rootroot 153155 4月 6 2010 cxmat.hpp
-rw-r--r-- 1 rootroot rootroot 27971 4月 6 2010 cxmisc.h
-rw-r--r-- 1 rootroot rootroot 90263 4月 6 2010 cxoperations.hpp
-rw-r--r-- 1 rootroot rootroot 53078 4月 6 2010 cxtypes.h
-rw-r--r-- 1 rootroot rootroot 18598 4月 6 2010 highgui.h
-rw-r--r-- 1 rootroot rootroot 4823 4月 6 2010 highgui.hpp
-rw-r--r-- 1 rootroot rootroot 72789 4月 6 2010 ml.h
rootroot@rootroot-virtual-machine:/usr/local/arm/lib/opencv/include/opencv$
查看库文件:
[c-sharp] view plain copy
[root@localhost opencv-arm]# ls /usr/local/arm/lib/opencv/lib
libcv.a libcvaux.a libcvaux.so libcv.so libcxcore.a libcxcore.so libhighgui.a libhighgui.so libml.a libml.so
rootroot@rootroot-virtual-machine:/usr/local/arm/lib/opencv/lib$ ll
total 8776
drwxrwxr-x 3 rootroot rootroot 4096 1月 12 18:23 ./
drwxrwxrwx 6 rootroot rootroot 4096 1月 12 18:23 ../
lrwxrwxrwx 1 rootroot rootroot 15 1月 12 18:23 libcvaux.so -> libcvaux.so.2.1
lrwxrwxrwx 1 rootroot rootroot 17 1月 12 18:23 libcvaux.so.2.1 -> libcvaux.so.2.1.0
-rw-r--r-- 1 rootroot rootroot 1351098 1月 12 18:23 libcvaux.so.2.1.0
lrwxrwxrwx 1 rootroot rootroot 12 1月 12 18:23 libcv.so -> libcv.so.2.1
lrwxrwxrwx 1 rootroot rootroot 14 1月 12 18:23 libcv.so.2.1 -> libcv.so.2.1.0
-rw-r--r-- 1 rootroot rootroot 2821335 1月 12 18:23 libcv.so.2.1.0
lrwxrwxrwx 1 rootroot rootroot 16 1月 12 18:23 libcxcore.so -> libcxcore.so.2.1
lrwxrwxrwx 1 rootroot rootroot 18 1月 12 18:23 libcxcore.so.2.1 -> libcxcore.so.2.1.0
-rw-r--r-- 1 rootroot rootroot 3357666 1月 12 18:23 libcxcore.so.2.1.0
lrwxrwxrwx 1 rootroot rootroot 17 1月 12 18:23 libhighgui.so -> libhighgui.so.2.1
lrwxrwxrwx 1 rootroot rootroot 19 1月 12 18:23 libhighgui.so.2.1 -> libhighgui.so.2.1.0
-rw-r--r-- 1 rootroot rootroot 943890 1月 12 18:23 libhighgui.so.2.1.0
lrwxrwxrwx 1 rootroot rootroot 12 1月 12 18:23 libml.so -> libml.so.2.1
lrwxrwxrwx 1 rootroot rootroot 14 1月 12 18:23 libml.so.2.1 -> libml.so.2.1.0
-rw-r--r-- 1 rootroot rootroot 491953 1月 12 18:23 libml.so.2.1.0
drwxrwxr-x 2 rootroot rootroot 4096 1月 12 18:23 pkgconfig/
rootroot@rootroot-virtual-machine:/usr/local/arm/lib/opencv/lib$
2、写个简单的测试程序,打开摄像头并创建一个窗口显示
// test.cpp
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
int main()
{
CvCapture* capture = NULL;
IplImage* frame = NULL;
if( !(capture = cvCaptureFromCAM(-1)))
{
fprintf(stderr, "Can not open camera./n");
return -1;
}
cvNamedWindow("video", 1);
while(frame = cvQueryFrame( capture ) )
{
cvShowImage("video", frame);
}
cvDestroyWindow("video");
cvReleaseCapture(&capture);
return 0;
}
3、编译链接测试程序
arm-linux-g++ -I/usr/local/arm/lib/opencv/include/opencv/ -L/usr/local/arm/lib/opencv/lib/ -lcv -lcxcore -lhighgui -lpthread -lrt -o test test.cpp
rootroot@rootroot-virtual-machine:~/wyb$ arm-linux-g++ -I/usr/local/arm/lib/opencv/include/opencv/ -L/usr/local/arm/lib/opencv/lib -lcv -lcxcore -lhighgui -lpthread -lrt -o test test.cpp
/usr/local/arm/lib/opencv/lib/libcv.so: file not recognized: File format not recognized
collect2: ld returned 1 exit status
rootroot@rootroot-virtual-machine:~/wyb$
rootroot@rootroot-virtual-machine:/usr/local/arm/lib/opencv/lib$ file libcv.so.2.1.0
libcv.so.2.1.0: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=7f04c77df448080762e47b6f746e5db2e340251d, not stripped
rootroot@rootroot-virtual-machine:/usr/local/arm/lib/opencv/lib$
http://stackoverflow.com/questions/14404445/g-throwing-file-not-recognized-file-format-not-recognized-error
g++ throwing file not recognized: File format not recognized error
getting following error with the command g++ -o test -L . -l pq
libpq.so: file not recognized: File format not recognized
#file libpq.so
libpq.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), not stripped
4、复制程序到嵌入式系统中运行
首先复制主机/usr/local/arm/lib/opencv/lib/下面的几个.so文件到嵌入式Linux系统的/lib/目录下,再复制我们编译的test到嵌入式系统/opt/myworks/目录下(并确保文件test属性为可执行),如果test可正常运行没有报告缺少库文件,说明我们编译的arm-linux版OpenCV库已经可以正常使用。