Home > Backend Development > Python Tutorial > Python3+opencv configuration tutorial

Python3+opencv configuration tutorial

php中世界最好的语言
Release: 2018-04-09 11:46:47
Original
2733 people have browsed it

This time I will bring you Python3 opencv configuration tutorial, what are the precautions for Python3 opencv configuration, the following is a practical case, let's take a look.

Whether it is Windows, Linux, or Raspberry Pi. Configuring the opencv environment of python3 is a headache, especially after many people use pip to install, they find that although opencv is installed, it is installed under the system's native python2.

The author also experienced many failures before the installation was successful.

This article uses the compiled method to configure opencv. Each step has separate configurations for Ubuntu and Raspberry Pi. Since the two systems are very similar (it can be said to be basically the same), they are explained in detail in one article.

Generally speaking, as long as you follow the steps to install and configure, you will not go wrong. Without further ado, let’s start the show!

step1: Preparation

##1.ubuntu

Preparation work before installation:

1.1. Update the Ubuntu apt-get repository

sudo apt-get update && sudo apt-get upgrade
Copy after login

1.2. Install the necessary python plug-in And some environments

sudo apt-get install python3-setuptools python3-dev -y
Copy after login

1.3. Install pip

sudo easy_install3 pip
Copy after login

1.4. Update pip (not necessary)

pip install --upgrade pip
Copy after login

1.5. Install numpy package

pip install numpy
Copy after login
Some common packages:

1.6.Install build-essential

sudo apt-get install build-essential -y
Copy after login

1.7. Some other development packages

sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev -y
Copy after login

2. Raspberry Pi

Update Raspberry Pi System and kernel

2.1 sudo apt-get update

2.2 sudo apt-get upgrade

2.3 sudo rpi-update

may occur when updating the kernel "No space left on device" error is reported. This is because there is insufficient storage space. It is best to check the memory usage before updating (just use the free command)

step2: Start installing opencv

ubuntu/Raspberry Pi Universal

1. First, you need to find a suitable place to store it. For the opencv installation package, the path I chose is ~/Download/opencv

2. Enter the installation path and download the installation package

cd ~/Download/opencv
wget https://github.com/Itseez/opencv/archive/3.0.0.zip
Copy after login

3. After the download is completed, you need to create a path for storing the compiled files:

unzip 3.0.0.zip && cd opencv-3.0.0
mkdir build && cd build
Copy after login

4. In the next step, be careful to configure according to the local path, and execute the following command in the build directory. :

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local
PYTHON3_EXECUTABLE=/usr/bin/python3
PYTHON_INCLUDE_DIR=/usr/include/python3.4
PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.4m.so
PYTHON3_NUMPY_INCLUDE_DIRS=/usr/local/lib/python3.4/dist-packages/numpy/core/include ..
Copy after login

NoteAll here are one-line commands, each path must be ensured to exist, don’t forget the last two points, most of the time the tree The path PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.4m.so will be different between Raspberry Pi and Ubuntu. In Raspberry Pi, cd to the /usr/lib/ directory and find a directory , libpython3.4m.so exists (at worst, you can search them one by one), and if you find them, just remember the path and replace them.

This step is mainly to find the files, for example, find python3.4, find libpython3.4m.so, find the path of numpy/core/include, and replace them accordingly

5, Finally, execute the installation command:

make && sudo make install
Copy after login
Remember to execute it in the build directory. This step takes a long time to install. You can first take a look at the opencv introductory tutorial Shenma's

6. If you have completed all the previous steps, congratulations, let’s start verification

import cv2
>>> print(cv2.version)
... opencv-3.0.0
Copy after login
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other php Chinese websites related articles!

Recommended reading:

Perfect solution to python2.7 being unable to use pip

##How to read and write txt files line by line in python

The above is the detailed content of Python3+opencv configuration tutorial. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template