Install OpenCV 3.4.1 in ubuntu.16.04

基本上按照官方文檔即可.

Step.1 Install Required Packages

sudo apt-get install -y build-essential
sudo apt-get install -y cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install -y python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
sudo apt-get install -y ffmpeg libopencv-dev libgtk-3-dev python3-numpy libdc1394-22 libpng12-dev libtiff5-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libv4l-dev qtbase5-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip

Step.2 Getting the Latest Stable Version

https://github.com/opencv/opencv/tree/3.4.1


Step.3 Building OpenCV from Source

unzip opencv-3.4.1.zip
mkdir -p opencv-3.4.1/build
cd ./opencv-3.4.1/build
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 INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D WITH_OPENGL=ON ..
make -j8
sudo make install

Step.4 Configuration

sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig

Append the following two lines to the end of the file: ~/.bashrc

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

then

. ~/.bashrc

Check the version of opencv

opencv_version

the output should be 3.4.1


Step.5 Write the “hello world”

Just see the official documentation

https://docs.opencv.org/2.4/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html

Do not use the OpenCV 4.0 right now, or you will get into trouble as following.

/usr/local/include/opencv2/core/cvdef.h:421:4: error: #error “OpenCV
4.x+ requires enabled C++11 support”


參考文獻
1. https://docs.opencv.org/2.4/doc/tutorials/introduction/linux_install/linux_install.html
2. https://blog.csdn.net/wzz18191171661/article/details/70147709
3. https://stackoverflow.com/questions/49943161/opencv-4-x-requires-enabled-c11-support-compilation-darknet-fatal-error

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章