How to Install OpenCV in Ubuntu16.04
It is not easy to install Opencv in Ubuntu. But let’s do it anyway.
Step 1: Download the OpenCV 3.2.0 from official website.
Step 2: using the below commands to update the system.
sudo apt-get update sudo apt-get upgrade
Step 3: Install the dependent files.
sudo apt-get -y remove ffmpeg x264 libx264-dev sudo apt-get -y install libopencv-dev sudo apt-get -y install build-essential checkinstall cmake pkg-config yasm sudo apt-get -y install libtiff5-dev libjpeg-dev libjasper-dev sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libdc1 394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev sudo apt-get -y install python-dev python-numpy sudo apt-get -y install libtbb-dev sudo apt-get -y install libqt4-dev libgtk2.0-dev sudo apt-get -y install libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev sudo apt-get -y install x264 v4l-utils ffmpeg sudo apt-get -y install libgtk2.0-dev
Step 4: After installing successfully, find the downloaded opencv and run the below commands.
sudo unzip opencv-3.0.0.zip cd opencv-3.0.0 sudo mkdir build cd build
Step 5: Run the cmake command
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
Note:
CMAKE_INSTALL_PREFIX:Installed python directory prefix. According to the prefix, the system will know the installed python path: CMAKE_INSTALL_PREFIX/lib/python2.7/dist-packages。We can use “python -c “import sys; print sys.prefix”” to get the installed python path.
Step 6: Compiler. (j4 means 4 logical processor)
sudo make -j4
Step 7: Install.
sudo make install
Until now, If it goes well, we have finished installing the OpenCV.
But as we know. A lot of times, things don’t go so well. But don’t worry, I am going to list the questions I met and the corresponding answers.
Troubleshooting
Q1: When I updated the system, It was timeout to install the Java 9.
A1: It is the network question, I try it another day, It goes well, I have done nothing.
Q2: When I ran cmake commands, There were two errors. The first error information is that:
CMake Warning at 3rdparty/ippicv/downloader.cmake:56 (message): ICV: Local copy of ICV package has invalid MD5 hash: d41d8cd98f00b204e9800998ecf8427e (expected: 808b791a6eac9ed78d32a7666804320e) Call Stack (most recent call first): 3rdparty/ippicv/downloader.cmake:110 (_icv_downloader) cmake/OpenCVFindIPP.cmake:243 (include) cmake/OpenCVFindLibsPerf.cmake:37 (include) CMakeLists.txt:558 (include) ICV: Downloading ippicv_linux_20151201.tgz... CMake Error at 3rdparty/ippicv/downloader.cmake:73 (file): file DOWNLOAD HASH mismatch for file: [/home/tucodec/software/opencv-3.2.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/ippicv_linux_20151201.tgz] expected hash: [808b791a6eac9ed78d32a7666804320e] actual hash: [d41d8cd98f00b204e9800998ecf8427e] status: [7;"Couldn't connect to server"] Call Stack (most recent call first): 3rdparty/ippicv/downloader.cmake:110 (_icv_downloader) cmake/OpenCVFindIPP.cmake:243 (include) cmake/OpenCVFindLibsPerf.cmake:37 (include) CMakeLists.txt:558 (include) CMake Error at 3rdparty/ippicv/downloader.cmake:77 (message): ICV: Failed to download ICV package: ippicv_linux_20151201.tgz. Status=7;"Couldn't connect to server" Call Stack (most recent call first): 3rdparty/ippicv/downloader.cmake:110 (_icv_downloader) cmake/OpenCVFindIPP.cmake:243 (include) cmake/OpenCVFindLibsPerf.cmake:37 (include) CMakeLists.txt:558 (include) Configuring incomplete, errors occurred! See also "/home/tucodec/software/opencv-3.2.0/bulid/CMakeFiles/CMakeOutput.log". See also "/home/tucodec/software/opencv-3.2.0/bulid/CMakeFiles/CMakeError.log".
It is a little long to read it. But don’t worry, the reason for that is ippicv_linux_20151201.tgz didn’t download successfully. So we just need to download it. After downloading it, put it to the right place and try it again.
The other error information is that
in file included from /home/tucodec/software/opencv-3.2.0/modules/core/src/hal_internal.cpp:49:0: /home/tucodec/software/opencv-3.2.0/bulid/opencv_lapack.h:2:45: fatal error: LAPACKE_H_PATH-NOTFOUND/lapacke.h: No such file or directory compilation terminated. modules/core/CMakeFiles/opencv_core.dir/build.make:1153: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/src/hal_internal.cpp.o' failed make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/src/hal_internal.cpp.o] Error 1 make[2]: *** Waiting for unfinished jobs.... CMakeFiles/Makefile2:1333: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/all' failed make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2 Makefile:160: recipe for target 'all' failed make: *** [all] Error 2
As for this error, please refer to this website.
If you find this article is useful for you, I am really appreciate you to share it with your friends, classmates, colleagues.
Have a nice day and Good luck. If you have some suggestions, please feel free to write a comment to tell me. You feedback is a gift for me. Thank you.
Note: Please don’t copy the article content to your blogs. Thanks!