1.主要文獻(xiàn)參考:
(1):https://docs.opencv.org/3.4.5/d7/d9f/tutorial_linux_install.html
(2):https://blog.csdn.net/qinglongzhan/article/details/81942935
(3):https://www.cnblogs.com/gala/archive/2011/10/10/2206529.html
(4):https://www.cnblogs.com/wyuzl/p/7889007.html
2.下載和安裝必須的包:
正式安裝opencv之前肝箱,需要安裝好opencv編譯的依賴包,列舉如下:
(1):yum install cmake
(2):build-essential 安裝
在ubuntu環(huán)境下:?apt-get install build-essential
在centos環(huán)境下:??yum install gcc gcc-c++ kernel-devel 安裝gcc-essential
? ? ? ? ? ? ? ? ? ? ?yum install gcc-gfortran 安裝gfortran
安裝完后,可以用 gcc -v 掠兄、g++ -v 和 fortran -v 查看版本妄均。
?(3):gtk2.0安裝
在ubuntu環(huán)境下:apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
在centos環(huán)境下:(安裝git)yum install git
(安裝gtk 圖形化界面庫)安裝必要文件包:yum install libgnomeui-devel
? 安裝必要組件:yum install gtk2 gtk2-devel gtk2-devel-docs
? 安裝可選組件:yum install gnome-devel gnome-devel-docs
(4):pkg-config 安裝
mkdir /opt/pkg
cd /opt/pkg?
wget http://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz
tar xvf pkg-config-0.29.2.tar.gz?
cd pkg-config-0.29.2
./configure --prefix=/usr/local/pkg-config --with-internal-glib
make
make instal
驗(yàn)證查看環(huán)境十分OK pkg-config --version
(5):ffmpeg組件安裝
主要依賴的有 libavcodec-dev libavformat-dev libswscale-dev荐类,這些庫都是FFmpeg 開源庫中的。
先安裝epel擴(kuò)展源
yum -y install epel-release
安裝其他擴(kuò)展源
yum localinstall –nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm
yum localinstall –nogpgcheck https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm
rpm –import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
最后安裝ffmpeg
yum -y install ffmpeg ffmpeg-devel
測(cè)試ffmpeg有沒有安裝成功
輸入命令ffmpeg -version
(6):安裝opencv其他依賴項(xiàng)
yum install python-devel numpy
yum install libdc1394-devel
yum install libv4l-devel
yum install gstreamer-plugins-base-devel
3滨攻、下載和安裝opencv
(1):下載源碼并編譯安裝
進(jìn)入鏈接選擇3.4.4:https://opencv.org/releases.html
或者直接點(diǎn)擊鏈接下載:https://codeload.github.com/opencv/opencv/zip/3.4.4
下載得到壓縮包:opencv-3.4.4.zip
unzip opencv-3.4.4.zip
mv opencv-3.4.4 opencv
cd opencv
mkdir build
cd build
cmake -D WITH_TBB=ON -D WITH_EIGEN=ON ..? ?
cmake -D BUILD_DOCS=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF ..? ?
cmake -D WITH_OPENCL=OFF -D WITH_CUDA=OFF -D BUILD_opencv_gpu=OFF -D BUILD_opencv_gpuarithm=OFF -D BUILD_opencv_gpubgsegm=OFF -D BUILD_opencv_gpucodec=OFF -D BUILD_opencv_gpufeatures2d=OFF -D BUILD_opencv_gpufilters=OFF -D BUILD_opencv_gpuimgproc=OFF -D BUILD_opencv_gpulegacy=OFF -D BUILD_opencv_gpuoptflow=OFF -D BUILD_opencv_gpustereo=OFF -D BUILD_opencv_gpuwarping=OFF ..? ?
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..?
make?
sudo make install
(2):opencv配置與加載動(dòng)態(tài)庫
(1):sudo vim /etc/ld.so.conf.d/opencv.conf
/usr/local/lib64(添加內(nèi)容)
sudo ldconfig
export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:$PKG_CONFIG_PATH
(2):也可以這樣配置
輸入命令:vi /etc/profile
在末尾加入:
export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:$PKG_CONFIG_PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib64
更新環(huán)境變量:source /etc/profile
sudo ldconfig
4顶霞、opencv測(cè)試
cd opencv/samples/cpp/example_cmake
make
./opencv_example
或者查看opencv是否安裝成功
輸入命令:pkg-config --cflags opencv
pkg-config --modversion opencv