Linux installation OpenCV and python2.7 modules such as Windows installation NumPy, CV2, etc.

Source: Internet
Author: User

OpenCV (open source computer Vision Library) is a BSD-licensed (open source) distributed cross-platform computer Vision Library with C ++,c,python and Java interfaces that can run on Linux, Windows, Mac OS and Android OS. The OPENCV is designed to improve computational efficiency and focus on real-time applications, written in an optimized C/s + + +, and libraries can take advantage of multicore processing to achieve many common algorithms for image processing and computer vision.

#-----------------------------------------------------------------------------------------------------------

0x00 Preface

The installation method of OpenCV in Linux can be installed according to Https://github.com/jayrambhia/Install-OpenCV.

But sometimes because of the speed or other reasons, in short I think it is very cumbersome, I extracted from the above project key statements, run can be installed successfully.

This time only to make Ubuntu under the installation method, other system installation you can refer to the above project.

0x01 preparatory work

Download OpenCV Source Package (now the latest version is 3.3.1):

Https://sourceforge.net/projects/opencvlibrary/files/opencv-unix/3.3.1/opencv-3.3.1.zip/download

Update under Ubuntu:

#change to Root sudo -s#updateapt-get Update

Prepare the file dependencies.sh

#!/bin/BashEcho "---Removing any pre-installed ffmpeg and x264"sudoApt-get-qq Remove FFmpeg x264 libx264-Devfunctioninstall_dependency {Echo "---Installing dependency: $"    sudoApt-get-yInstall$1}install_dependency LIBOPENCV-devinstall_dependency Build-essentialinstall_dependency checkinstallinstall_dependency cmakeinstall_dependencyPkg-configinstall_dependency yasminstall_dependency Libtiff5-devinstall_dependency libjpeg-devinstall_dependency Libjasper-devinstall_dependency Libavcodec-devinstall_dependency Libavformat-devinstall_dependency Libswscale-devinstall_dependency libdc1394- A-devinstall_dependency Libxine2-devinstall_dependency Libgstreamer0.Ten-devinstall_dependency Libgstreamer-plugins-base0.Ten-devinstall_dependency libv4l-devinstall_dependency python-devinstall_dependency python-numpyinstall_dependency LIBTBB-devinstall_dependency libqt5x11extras5install_dependency libqt5opengl5install_dependency libqt5opengl5-devinstall_dependency libgtk2.0-devinstall_dependency LIBFAAC-devinstall_dependency Libmp3lame-devinstall_dependency Libopencore-amrnb-devinstall_dependency Libopencore-amrwb-devinstall_dependency Libtheora-devinstall_dependency Libvorbis-devinstall_dependency Libxvidcore-devinstall_dependency x264install_dependency v4l-utils#install_dependency ffmpeginstall_dependencyUnzip

Prepare for the install.sh.

#!/bin/bashversion=3.3.1DownloadFile=opencv-3.3.1.ZipDldir=opencvsource dependencies.SHmkdir-P $dldirMV$downloadfile $dldir/$DOWNLOADFILECD $dldirUnzip$DOWNLOADFILECD OpenCV-$versionmkdirBUILDCD Buildcmake-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 : Make-j4sudo  Make Installsudo SH-C'echo "/usr/local/lib" >/etc/ld.so.conf.d/opencv.conf'sudoLdconfigEcho "OpenCV"$version"Ready-to-be used"

0x02 installation OpenCV

As long as Opencv-3.3.1.zip, dependencies.sh, install.sh are in the same folder, they can be installed:

chmod +x dependencies. SH chmod install. SH  Install. SH

The installation process is relatively lengthy.

0X03 Compiling OPENCV Program

For example, the file to be compiled is Pcat.cpp

g++-ggdb 'pkg-config –-cflags opencv ' pkg-config –-libs OpenCV ' Pcat. CPP –o pcat

0x04 Windows installs NumPy, CV2 and other python2.7 modules

For Windows, I only need to cv2 this python2.7 module for the time being, and this CV2 module relies on the NumPy module

installation of NumPy :

https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy

Now numpy the latest version is the 32-bit version of 1.13.3,python download the numpy-1.13.3+mkl-cp27-cp27m-win32.whl,64-bit version of the download numpy-1.13.3+ Mkl-cp27-cp27m-win_amd64.whl

Install NUMPY-XXX.WHL

installation of Cv2 :

Https://opencv.org/releases.html

Now OPENCV the latest version is 3.3.1, download HTTPS://SOURCEFORGE.NET/PROJECTS/OPENCVLIBRARY/FILES/OPENCV-WIN/3.3.1/ Opencv-3.3.1-vc14.exe/download

This opencv-3.3.1-vc14.exe will be extracted automatically after clicking, including sources and build folder, \opencv\sources\samples is available for learning.

Open \opencv\build\python\2.7, there are two versions of x86 and x64, the key to see what version of Python you are, copy the corresponding version of the folder under the Cv2.pyd

Copy to python2.7 's installation directory \lib\site-packages inside

You can then turn on Python to verify whether the success

Import Cv2

Linux installation OpenCV and python2.7 modules such as Windows installation NumPy, CV2, etc.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.