Reference: https://blog.csdn.net/dyllove98/article/details/8917485
Mine is under centos7
Install the libraries required by opencv:
Check whether the dependency package is installed according to the following conditions: (each of the following needs to check Yum list xxxx to check whether it is installed)
autoconf automake cmake freetype-devel gcc gcc-c++ git libtool make mercurial nasm pkgconfig zlib-devel in
order to support GUI features gtk2-devel
In order to support the camera libdc1394-devel libv4l-devel
to support the video media ffmpeg-devel (the package cannot be found in the general source, you need to add the source) gstreamer-plugins-base-devel
Graphic file decoding library update
libpng-devel libjpeg-turbo-devel
jasper-devel openexr-devel (not installed)
libtiff-devel libwebp-devel (not installed)
ipp_icv is a parallel computing library. If there is no such product when compiling, it will fail to compile. (Go to the Internet to download the corresponding package to solve the problem, mentioned below)
tbb-devel, Intel's Threading Building Blocks (TBB), is a parallel programming tool developed by Intel.
eigen3-devel matrix calculation Eigen is an open source C++ matrix calculation tool
1. Download the source package
wget http:
//ftp.gnu.org/gnu/gcc/gcc-4.8.0/gcc-4.8.0.tar.bz2
Unzip: tar -jxvf gcc-4.8.0.tar.bz2
2. Download the dependency libraries required for compilation
cd gcc-4.8.0
./contrib/download_prerequisites
cd ..
3. Create a compilation output directory
mkdir gcc-build-4.8.0
4. Enter this directory and execute the following command to generate a makefile
cd gcc-build-4.8.0
../gcc-4.8.0/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
5. Compile
make -j4
If the compilation is successful, the time is relatively long, about half an hour, so if you see it keeps outputting and does not stop immediately, you should be very happy!
ps: I myself appeared when compiling:
6. Installation
sudo make install
7. Switch GCC to the new version
Determine the path of the newly installed GCC, usually under /usr/local/bin by default. You can updateb first, then locate gcc-4.8|tail to find
ls /usr/local/bin | grep gcc
Add a new GCC to the options, the third last is the name, the second last parameter is the new GCC path, and the last parameter 40 is the priority. After setting a larger value, the new version will be automatically used.
update-alternatives --install /usr/ bin/gcc /usr/local/bin/i686-pc-linux-gnu-gcc 40
Note: There is a gcc in the original text
8. Confirm that the current version has been switched to the new version
Upgrade gcc:
Reference: https://blog.csdn.net/dyllove98/article/details/8917485
gcc -v
I used ssh remote here, and found that the version has not changed. After disconnecting and re-training, after regenerating the session, I found it became 4.8!
9. Install cmake:
Reference: https://blog.csdn.net/u011056389/article/details/37816067
Download cmake source code address: https://github.com/Kitware/CMake/releases?after=v3.3.2 , here I choose version 3.3.0
installation:
tar -zxvf cmake-3.0.0.tar.gz
cd cmake-3.0.0
./configure
make -j8
make install
After ./configure is installed, it appears like this:
Appears after make -j8:
10. Install ipp_cv:
Download link: Available in https://blog.csdn.net/huangkangying/article/details/53406370
Reference: https://blog.csdn.net/huangkangying/article/details/53406370
Go to the unzipped opencv directory:
- Create a directory of ippicv_linux_20151201 with MD5.
-
ipp_file=../ippicv_linux_20151201.tgz && ipp_hash=$(md5sum $ipp_file | cut -d" " -f1) && ipp_dir=3rdparty/ippicv/downloads/linux-$ipp_hash mkdir -p $ipp_dir && cp $ipp_file $ipp_dir
Final Results:
11.Install opencv:
Go to the opencv-2.4.13 folder:
Create a build folder:
mkdir build && cd build
Compile and install opencv:
Pit encountered:
When installing directly make, the following error occurred:
make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.o] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make: *** [all] Error 2
Find the problem on the Internet and say that you need to set -D WITH_FFMPEG=OFF to off
cmake -D CMAKE_BUILD_TYPE=RELEASE -D WITH_FFMPEG=OFF -D CMAKE_INSTALL_PREFIX=/usr/local ..
After setting up successfully:
After make
sudo make install
Finish, and finally verify, enter the lib folder under the Build folder to check whether cv2.so exists, as shown in the figure:
Move cv2.so to the python2.7 folder
ln cv2.so /usr/lib64/python2.7/site-packages
12. Test whether opencv is installed successfully:
Write the following code in the python editor. The editor I use is PyCharm, which feels very useful.
import cv2
print cv2.__version__
as follows:
Importing the version number you installed means that the installation is successful! ! !
However, there are problems connecting to the remote environment test in pycharm. Various problems have not been solved. For details, please see my other blog
https://mp.csdn.net/postedit/85065994
You can pay attention to the official account of my friend and me~~~ Here are some python technical information that my friend and I update from time to time! ! You can also leave a message to discuss technical issues. I hope you can support and pay attention to it. Thank you~~