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
1.2. Install the necessary python plug-in And some environments
sudo apt-get install python3-setuptools python3-dev -y
1.3. Install pip
sudo easy_install3 pip
1.4. Update pip (not necessary)
pip install --upgrade pip
1.5. Install numpy package
pip install numpy
1.6.Install build-essential
sudo apt-get install build-essential -y
1.7. Some other development packages
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev -y
2. Raspberry Pi
Update Raspberry Pi System and kernel2.1 sudo apt-get update2.2 sudo apt-get upgrade2.3 sudo rpi-updatemay 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
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
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 ..
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 accordingly5, Finally, execute the installation command:
make && sudo make install
6. If you have completed all the previous steps, congratulations, let’s start verification
import cv2 >>> print(cv2.version) ... opencv-3.0.0
Perfect solution to python2.7 being unable to use pip
The above is the detailed content of Python3+opencv configuration tutorial. For more information, please follow other related articles on the PHP Chinese website!