MAC-OSX installation OPENCV in Python3.5 virtual environment

Source: Internet
Author: User
Tags virtual environment virtualenv gstreamer

MAC-OSX installation Opencv1 keywords in Python3.5 virtual environment

Key words: MAC,OSX,PYTHON3.5,VIRTUALENV,OPENCV

2 Overview

This article is a basic article of environment construction .

For this thing to let oneself toss nearly 2 days of time, various screening materials, various attempts, finally found the corresponding information, and then successfully installed.

In finishing this article, especially thanks to the author, he provided two ways to install OPENCV, respectively, python2.x [1] and python3.x [2].

The author follow the steps and clues of 3.x , and then solve some of the text mentioned in the middle of the problem, finally successfully installed.

Because the main steps and the original text is not too large, so this article is purely the original Chinese version of the sermon.

This article is suitable for readers:

    • MAXOSX Users
    • Python user
    • Users who use OPENCV for picture processing
3 Installation Steps
    1. Mac OSX

      Apple OSX operating system

    2. HomeBrew

      Software Library installation command line

    3. python3.5

    4. Virtualenv

      Virtual Environments

    5. PIP installation NumPy

    6. Installing Xcode

      Download and install directly from AppStore

    7. Opencv3

In addition to all the prerequisites for the last article, this article assumes that the user has completed all the work successfully because it is relatively simple and rich in Chinese literature. The focus of this article is on the final opencv3 part.

Attention:

    • The python3.5-based virtual Environment directory established in this paper is ~/py3venv/ and will be used in the subsequent compilation phase configuration.
    • Since this article involves a lot of online installation parts, readers should first have the scientific Internet skills
4 OpenCV Download

Since OPENCV is the source code, the user needs to download it and compile the platform accordingly. The main need to download two related warehouses:

    • Opencv.git

      OPENCV Core Library

    • Opencv_contrib.git

      OPENCV expansion Module

Attention:

    • Must be downloaded two, because the following configuration will be used in the

    • Switch all to unified version: 3.0.0

      As of July 13, the latest tag number: 3.0.1, but this article did not test success, and 3.0.0 is successful

The following are the relevant command lines.

Download opencv.git Warehouse [2]:

$ cd ~$ git clone https://github.com/itseez/opencv.git3.0. 0

Download opencv_contrib.git Warehouse [2]:

$ cd ~$ git clone https://github.com/itseez/opencv_contrib3.0. 0

Attention:

    • The download directory is in the root directory of the user file ~
    • This path information is used in subsequent compilation configurations.
5 OPENCV Compilation

Create a new build directory under the downloaded OPENCV directory [2]:

$ cd ~/mkdir  build$ CD Build

Execute the cmake command under the build directory:

Cmake-d cmake_build_type=RELEASE-D cmake_install_prefix=/usr/Local-D Python3_packages_path=~/py3venv/lib/python3.5/site-Packages-D python3_library=/usr/local/cellar/python3/3.5.1/frameworks/python.framework/versions/3.5/lib/Libpython3.5m.dylib-D python3_include_dir=/usr/local/cellar/python3/3.5.1/frameworks/python.framework/versions/3.5/include/Python3.5m-D install_c_examples=OFF-D install_python_examples= on-D build_examples= on-D build_opencv_python3= on-D opencv_extra_modules_path=~/opencv_contrib/modules.

Attention:

    • This is the configuration of the python3.5 virtual environment under MAOSX
    • Please carefully control whether each path is correct on this computer
    • This article compares the references to the following modifications: Install_c_examples set to Off
    • A line preceded by a continuation symbol has the- D
    • Command most later : the symbol is not an ellipsis, but a part of the command line

After executing the command, check the output information in the shell to verify that the compilation was successful.

View the build list to be built contains python3 information:

--   OpenCV modules:--to be     built:                 HAL core Flann imgproc ml photo video imgcodecs shape Videoio h Ighgui objdetect superres ts features2d calib3d stitching videostab python3--     Disabled:                    World --     Disabled by dependency:      -

To view setup information associated with python3.5 :

--Python3:--Interpreter:/users/harmo/py3venv/bin/python3 (ver3.5.1)--Libraries:/usr/local/cellar/python3/3.5.1/frameworks/python.framework/versions/3.5/lib/libpython3.5m.dylib (ver3.5.1)--NumPy:/users/harmo/py3venv/lib/python3.5/site-packages/numpy/core/include (ver1.11.1)--Packages Path:/users/harmo/py3venv/lib/python3.5/site-packages

To view the end success information for the shell output:

 Done Done--Build files has been written to:/users/harmo/downloads/opencv/build

If CMake succeeds, a series of files will be generated in the build directory:

(py3venv)?  ls 3rdparty                   Makefile                   bin                        doc                        opencv2CMakeCache.txt             opencvconfig-version.cmake Cmake_install.cmake        include                    osxcmakefiles                 opencvconfig.cmake         cmake_uninstall.cmake      junk                       Samplescpackconfig.cmake          opencvmodules.cmake        cvconfig.h                 lib                        unix-install Cpacksourceconfig.cmake    Apps                       data                       modules                    version_string.tmp

Then you can compile the OpenCV and Execute

 make-j4

Note: If you want to compile faster, you can modify the number 4 in the command to the number of available CPU cores for your computer to achieve multi-core compilation.

The compilation process is a bit lengthy, but fortunately there is a progress bar in the shell that can be patiently waited for a few minutes.

6 Compiling FAQs

During the CMake phase, some exception hints may appear, listed here.

6.1 Self-Test tips

In the process of CMake, you will encounter such an exception prompt:

--Checking forModule'gstreamer-base-1.0'--No Package'gstreamer-base-1.0'found--Checking forModule'gstreamer-video-1.0'--No Package'gstreamer-video-1.0'found--Checking forModule'gstreamer-app-1.0'--No Package'gstreamer-app-1.0'found--Checking forModule'gstreamer-riff-1.0'--No Package'gstreamer-riff-1.0'found--Checking forModule'gstreamer-pbutils-1.0'--No Package'gstreamer-pbutils-1.0'Found

It can be ignored, whether the installation is successful, the python3.5 words mentioned above prevail.

6.2 IPPICV File

The program is executed to:

-- icv:downloading ippicv_macosx_20141027.tgz ... CMake Error at 3rdparty/ippicv/downloader.cmake: (file):  file DOWNLOAD HASH mismatch

You are prompted to download the file with the wrong hash value, and then abort execution.

Referring to another article [3], the following solutions are presented:

This file is required and then overwritten by the past.

wget http://www.mirrorservice.org/sites/dl.sourceforge.net/pub/sourceforge/o/op/opencvlibrary/3rdparty/ippicv/ Ippicv_macosx_20141027.tgz

Copy yourself Download ippicv_macosx_20141027.tgz to ~/opencv/3rdparty/ippicv/downloads/ Replace the macosx-9662fe0694a67e59491a0dcc82fa26e0/ippicv_macosx_20141027.tgz with the old file.

7 OPENCV Installation

If you compile successfully in the previous steps, you can start the installation:

 Make Install

If you are prompted for permission issues, do the following:

sudo  Make Install

If there is no problem, then congratulations on the installation success.

8 Verification Checks

Once the OPENCV is successfully installed, a validation check is required.

Check for file cv2.so in the virtual environment py3venv :

(py3venv)? Py3venvpwd/users/harmo/py3venv (py3venv)? Py3venv cd Lib/python3.5/site-packages (py3venv)? Site-packagesls-l|grepCV-rwxr-xr-x1Harmo Staff2021204  7  7  -: Onecv2.cpython-35m-DARWIN.SOLRWXR-xr-x1Harmo Staff the  7  6  -: -Cv2.so-/usr/local/cellar/opencv3/3.1.0_3/lib/python2.7/site-packages/cv2.so

Use OpenCV corresponding library file in python3.5 :

(py3venv)? site-Packages Pythonpython3.5.1(Default, Jan A  ., ,: Wu: +) [GCC4.2.1Compatible Apple LLVM7.0.2(clang-700.1.Bayi)] on Darwintype" Help","Copyright","credits"Or"License"  for  Moreinformation.>>>Import Cv2>>>cv2.__version__'3.0.0'>>>

If you go to this step, finally congratulations, you successfully installed the OPENCV.

What can I do after installing the OPENCV?

All kinds of picture processing, face recognition, mobile detection alarm and so on fun opencv out of the box function waiting for you to develop, enjoy and play it.

Enjoy it~!

9 Summary of this article

After the completion of the environment, the correct process is deliberately recorded. On the one hand let oneself in the future do similar things no longer twists and turns, on the other hand also let a friend with the same needs to go a little detour, at least no longer spend a few days to find all kinds of information and trial and error.

10 references

Find a lot of information, the most valuable reference is the following several, thanks to the original author.

[1] Install OpenCV 3.0 and Python 2.7+ on OSX http://www.pyimagesearch.com/2015/06/15/ install-opencv-3-0-and-python-2-7-on-osx/
[2] (1, 2, 3, 4) Install OpenCV 3.0 and Python 3.4+ on OSX http://www.pyimagesearch.com/2015/06/29/ install-opencv-3-0-and-python-3-4-on-osx/
[3] Ippicv_macosx_20141027.tgz problem http://blog.csdn.net/alanzjl/article/details/47294751
Author: Harmo ha mo
Author Introduction: Https://zhengwh.github.io
Technical Blog: Http://www.cnblogs.com/beer
Email: [Email protected]
Qq: 1295351490
Time: 2016-02
Copyright Notice: Welcome to learn to exchange for the purpose of the reader to reprint, but please "annotated source"
Support this article: If you are inspired by the article, you can click the button in the lower right corner of the blog to "recommend"

MAC-OSX installation OPENCV in Python3.5 virtual environment

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.