第一次写教程~
最近在跑IDT(Improved Dense Trajectories)的代码,配置环境什么的都是新手上路~所以记录一下。
opencv可以官网直接下载,附链接:
opencv-2.4.9
https://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip/download
sudo apt-get -qq install libopencv-dev build-essential checkinstall cmake pkg-config libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libopencore-amrnb-dev libopencore-amrwb-dev x264 v4l-utils
解压-进入opencv目录
cd opencv-2.4.9
创建一个编译目录-进入目录(第一次安装时忘记了这一步)
mkdir release
cd release
开始编译(prefix是指定一个目录)
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install
等待之后(15分钟左右),过程会有进度的提示,编译结束后会看到如下信息:
-- Configuring done
-- Generating done
-- Build files have been written to: /自己的目录/opencv-2.4.9
可以查看生成的动态库:
zyx@zyx-ubuntu:/usr/local/lib$ ls
libopencv_calib3d.so libopencv_ml.so.2.4.9
libopencv_calib3d.so.2.4 libopencv_nonfree.so
libopencv_calib3d.so.2.4.9 libopencv_nonfree.so.2.4
libopencv_contrib.so libopencv_nonfree.so.2.4.9
libopencv_contrib.so.2.4 libopencv_objdetect.so
libopencv_contrib.so.2.4.9 libopencv_objdetect.so.2.4
libopencv_core.so libopencv_objdetect.so.2.4.9
libopencv_core.so.2.4 libopencv_ocl.so
libopencv_core.so.2.4.9 libopencv_ocl.so.2.4
libopencv_features2d.so libopencv_ocl.so.2.4.9
libopencv_features2d.so.2.4 libopencv_photo.so
libopencv_features2d.so.2.4.9 libopencv_photo.so.2.4
libopencv_flann.so libopencv_photo.so.2.4.9
libopencv_flann.so.2.4 libopencv_stitching.so
libopencv_flann.so.2.4.9 libopencv_stitching.so.2.4
libopencv_gpu.so libopencv_stitching.so.2.4.9
libopencv_gpu.so.2.4 libopencv_superres.so
libopencv_gpu.so.2.4.9 libopencv_superres.so.2.4
libopencv_highgui.so libopencv_superres.so.2.4.9
libopencv_highgui.so.2.4 libopencv_ts.a
libopencv_highgui.so.2.4.9 libopencv_video.so
libopencv_imgproc.so libopencv_video.so.2.4
libopencv_imgproc.so.2.4 libopencv_video.so.2.4.9
libopencv_imgproc.so.2.4.9 libopencv_videostab.so
libopencv_legacy.so libopencv_videostab.so.2.4
libopencv_legacy.so.2.4 libopencv_videostab.so.2.4.9
libopencv_legacy.so.2.4.9 pkgconfig
libopencv_ml.so python2.7
libopencv_ml.so.2.4 python3.4
在文件/etc/ld.so.conf中添加 /usr/local/lib,或者也可以在/etc/ld.so.conf.d 目录下增加一个conf文件(命名 /etc/ld.so.conf.d.opencv.conf),同样添加 /usr/local/lib,(推荐后者)。
使用下面的动态库管理命令ldconfig,让opencv的相关链接库被系统共享
cd /etc
sudo ldconfig -v
最好再重启一下电脑
如果成功的话,使用以下命令会看到动态库的信息
cd /etc
sudo ldconfig -v >temp.so.txt && cat temp.so.txt|grep opencv
libopencv_superres.so.2.4 -> libopencv_superres.so.2.4.9
libopencv_gpu.so.2.4 -> libopencv_gpu.so.2.4.9
libopencv_video.so.2.4 -> libopencv_video.so.2.4.9
libopencv_legacy.so.2.4 -> libopencv_legacy.so.2.4.9
libopencv_nonfree.so.2.4 -> libopencv_nonfree.so.2.4.9
libopencv_ml.so.2.4 -> libopencv_ml.so.2.4.9
libopencv_contrib.so.2.4 -> libopencv_contrib.so.2.4.9
libopencv_photo.so.2.4 -> libopencv_photo.so.2.4.9
libopencv_videostab.so.2.4 -> libopencv_videostab.so.2.4.9
libopencv_features2d.so.2.4 -> libopencv_features2d.so.2.4.9
libopencv_objdetect.so.2.4 -> libopencv_objdetect.so.2.4.9
libopencv_calib3d.so.2.4 -> libopencv_calib3d.so.2.4.9
libopencv_core.so.2.4 -> libopencv_core.so.2.4.9
libopencv_imgproc.so.2.4 -> libopencv_imgproc.so.2.4.9
libopencv_highgui.so.2.4 -> libopencv_highgui.so.2.4.9
libopencv_stitching.so.2.4 -> libopencv_stitching.so.2.4.9
libopencv_ocl.so.2.4 -> libopencv_ocl.so.2.4.9
libopencv_flann.so.2.4 -> libopencv_flann.so.2.4.9
libopencv_core.so.2.4 -> libopencv_core.so.2.4.8
libopencv_imgproc.so.2.4 -> libopencv_imgproc.so.2.4.8
在 /etc/profile 这个文件中添加
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
参考其他教程,输入pkg-config –cflags opencv 和pkg-config –libs opencv ,可以发现以下信息:
pkg-config --cflags opencv
-I/usr/local/include/opencv -I/usr/local/include
但是我并没有出现这些信息,不影响使用。
到此,OpenCV配置完成
OpenCV自带测试例子,进入解压的opencv目录,运行:
samples/c/build_all.sh
完成后,显示所有可执行的文件
find . -perm /u=x,g=x,o=x
可以自己调用看能不能成功运行。
安装ffmpeg时遇到了很多问题,每次安装好ffmpeg之后,再安装opencv就会导致ffmpeg不能使用,显示的问题大概是一个relocate的错误,所以我先安装了opencv,然后ffmpeg只进行了简单的安装,并没有按许多教程所说,修改文件之类的。
sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next
sudo apt-get update
sudo apt-get install ffmpeg
使用命令,会显示版本信息
ffmpeg -version
https://blog.csdn.net/u013685264/article/details/52814721