(由于最近需要在6410的板子上做人脸识别,于是就要安装与移植opencv了,安装过很多次,终于好用了,自己测试过。相关文件下载:点击打开链接)
1、 OpenCv库编译。首先将opencv-1.0.0.tar.gz拷贝到虚拟机/opt目录下,然后解压:
tar zxvf opencv-1.0.0.tar.gz
2、进入到opencv-1.0.0目录中,输入命令,完成配置:
./configure --host=arm-linux --without-gtk --without-carbon --without-quicktime --without-1394libs --with-ffmpeg --without-python --without-swig --enable-static --enable-shared --disable-apps CXX=arm-linux-g++ CPPFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib --with-v4l --prefix=/usr/local --libdir=/usr/local/lib --includedir=/usr/local/include
3、配置完后,输入命令:
make
make install
4、经历了漫长的等待之后,去看下/usr/local/lib目录,会发现opencv相对应的库全在这里面,特别是看下/usr/local/lib/pkgconfig下是否有opencv.pc这个文件。然后配置环境变量:
gedit /etc/profile
在该文件后面加上
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
保存退出后,执行:
source /etc/profile
5、测试是否编译成功:
pkg-config --cflags opencv
pkg-config --libs opencv
成功!!!
6、安装opencv相关的图片库
tar zxvf (挨个解压吧,都放在/opt目录下)
(1) libz的交叉编译
./configure --prefix=/usr/local/libz-arm --shared
修改makefile
CC=arm-linux-gcc
AR=arm-linux-ar
RANLIB=arm-linux-ranlib
LDSHARED=arm-linux-gcc -shared -wl, -soname,libz.so.1,--version-script,zl
lib.map
make
make install
(2)libjpeg的交叉编译:
./configure --host=arm-linux --prefix=/usr/local/libjpeg-arm --enable-shared --enable-static
修改makefile
CC=arm-linux-gcc
AR=arm-linux-ar ac
AR2= arm-linux-ranlib
在/usr/local/libjpeg-arm目录下建立 man/man1,include,lib,bin四个目录(此步非常重要)
make
make install
(3)交叉编译 x264,xvid,ffmpeg
为了使OpenCV能处理视频,我们要事先交叉编译ffmpeg,而ffmpeg又是依赖x264和xvid的。
编译yasm
./configure --enable-shared --prefix=/usr/local --host=arm-linux
make
make install
交叉编译x264
CC=arm-linux-gcc ./configure --enable-shared --host=arm-linux --disable-assembly --prefix=/usr/local/x264-arm
make
make install
交叉编译xvid
cd /build/generic(先进入这个目录)
CC=arm-linux-gcc ./configure --prefix=/usr/local/xvid-arm –disable-assembly
make
make install
(安装后库文件在/usr/local/x264-arm中)
(4)libpng的交叉编译
./configure --host=arm-linux --prefix=/usr/local/libpng-arm --enable-shared --enable-static
make
make install
7、所有工作结束,将相关的库文件全部拷贝出来,放到arm开发板上吧
8、在qt中添加opencv:在.pro文件中加上;
INCLUDEPATH += /usr/local/include/opencv/
LIBS += -L/usr/local/lib/ \
-lcv \
-lcvaux \
-lcxcore \
-lhighgui \
-lml \
-lpthread \
-lrt