1. 程式人生 > >Install OpenCV 3.4.1 in ubuntu.16.04

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

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

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”