安装OpenCv后出现各种问题,究其原因是一些基础库没有安装好,以下是基础库安装步骤,保证尽量完整,免得在使用的时候出错。
1 |
apt-get remove ffmpeg x264 libx264-dev |
2 |
apt-get install build-essential checkinstall Git cmake libfaac-dev libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libva-dev libvdpau-dev libvorbis-dev libx11-dev libxfixes-dev libxvidcore-dev texi2html yasm zlib1g-dev |
1 |
apt-get install libgstreamer0.10-0 libgstreamer0.10-dev gstreamer0.10-tools gstreamer0.10-plugins-base libgstreamer-plugins-base0.10-dev gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-plugins-bad gstreamer0.10-ffmpeg |
如果 gstreamer0.10-ffmpeg提示没有候选,那么手动下载并安装,或者按如下步骤安装
1 |
apt-get install libgstreamer0.10-dev gstreamer-tools gstreamer0.10-tools gstreamer0.10-doc |
2 |
apt-get install gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-plugins-bad gstreamer0.10-plugins-bad-multiverse |
所有您需要做的就是添加PPA到您的系统,更新本地存储索引和安装gstreamero.10-ffmpeg包。如下输入命令:
1 |
add-apt-repository ppa:mc3man/trusty-media |
3 |
apt-get install gstreamer0.10-ffmpeg |
1 |
apt-get install libgtk2.0-0 libgtk2.0-dev |
2 |
apt-get install libjpeg8 libjpeg8-dev |
下载链接: ftp://ftp.videolan.org/pub/videolan/x264/snapshots
1 |
tar xvf x264-snapshot-**********-stable. tar .bz2 |
2 |
cd x264-snapshot--**********--stable |
3 |
./configure -- enable -shared -- enable -pic |
由于我的电脑是64位,所以要加上 –enable-shared –enable-pic ,否则就会报错:
1 |
/usr/bin/ld: /usr/ local /lib/libavcodec.a(avpacket.o): relocation R_X86_64_32S against `av_destruct_packet' can not be used when making a shared object; recompile with -fPIC |
2 |
/usr/ local /lib/libavcodec.a: could not read symbols: Bad value |
如果出现下面错误:
1 |
/usr/ local /lib/libswscale.a(swscale_unscaled.o): relocation R_X86_64_32S against `av_pix_fmt_descriptors@@LIBAVUTIL_52' can not be used when making a shared object; recompile with -fPIC |
2 |
/usr/ local /lib/libswscale.a: error adding symbols: 错误的值 |
3 |
collect2: error: ld returned 1 exit status |
4 |
make [2]: *** [lib/libopencv_highgui.so.2.4.9] 错误 1 |
5 |
make [1]: *** [modules/highgui/CMakeFiles/opencv_highgui. dir /all] 错误 2 |
可能是opencv249依赖的ffmpeg版本不对照
1 |
wget http://ffmpeg.org/releases/ffmpeg-1.2. tar .bz2 |
2 |
tar xvf ffmpeg-1.2. tar .bz2 |
4 |
./configure -- enable -gpl -- enable -libfaac -- enable -libmp3lame -- enable -libopencore-amrnb -- enable -libopencore-amrwb -- enable -libtheora -- enable -libvorbis -- enable -libx264 -- enable -libxvid -- enable -nonfree -- enable -postproc -- enable -version3 -- enable -x11grab -- enable -shared -- enable -pic |
报错:dvb-v5.h:69:9: error: ‘NULL’ undeclared here ……..原因是v4l的版本不对,于是我装了v4l 1.0.0
1 |
wget http://www.linuxtv.org/downloads/v4l-utils/v4l-utils-1.0.0. tar .bz2 |
2 |
tar xvf v4l-utils-1.0.0. tar .bz2 |
1 |
tar xvf OpenCV-2.4.9. tar .bz2 |
5 |
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/ local -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON .. |
环境变量中添加
1 |
export LD_LIBRARY_PATH=/usr/ local /lib |
另外修改
1 |
sudo vi /etc/ld.so.conf.d/opencv.conf |
追加 /usr/local/lib
执行
1 |
sudo ldconfig /etc/ld.so.conf |
在/etc/bash.bashrc添加
1 |
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/ local /lib/pkgconfig |
最后查看版本和头文件目录
1 |
pkg-config --modversion opencv |
2 |
pkg-config --cflags opencv |
-
1.由于opencv的cmakelist里依赖一些库,所有要先配置好这些库,先去除你电脑上的这些重新装.
-
2.安装其他依赖库.
-
3.安装gstreamer,主要是opencv里头的相机模块用到
-
4.安装gtk,jpeg8
-
5.安装 install x264.
-
6.安装ffmpeg
-
7.安装v4l (video for linux) , http://www.linuxtv.org/downloads/v4l-utils/.
-
8.安装OpenCV 2.4.9.
如果准备在Qt Creator中写代码,关注下一篇文章:Linux下OpenCv+Qt搭配使用问题
(责任编辑:最模板) |