I installed OpenCV-Python on my Raspberry Pi

Overview

Anyway, I want to install OpenCV safely, so I installed it by the official method. https://docs.opencv.org/master/d2/de6/tutorial_py_setup_in_ubuntu.html

environment

hard

Raspberry Pi 3 B+

OS

$ cat /etc/debian_version
10.7
$ cat /etc/os-release 
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

Installation

$ sudo apt-get install python-opencv

Actually, this is all it takes.

>>> import cv2
>>> print(cv2.__version__)
4.5.1-dev

Installation was successful with Python2.

However, with Python3,

>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2’
>>> 

I can't find it.

I can't find the cv2.so file when I try to pass it, so I will try to build from the source.

Building OpenCV from source

Install necessary packages for the time being

First, install them as needed for the build.

sudo apt-get install cmake
sudo apt-get install gcc g++

I want both Python2 and 3

sudo apt-get install python-dev python-numpy
sudo apt-get install python3-dev python3-numpy

Install GTK related What is GTK? .. .. → It seems to be used when making a GUI application.

sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install libgtk-3-dev

For the time being, it seems that you can build up to this point. The next one seems to just update the package in reserve.

Preliminary installation (no need to do)

sudo apt-get install libpng-dev
sudo apt-get install libjpeg-dev
sudo apt-get install libopenexr-dev
sudo apt-get install libtiff-dev
sudo apt-get install libwebp-dev

Download OpenCV

Download it from Git.

$ sudo apt-get install git
$ git clone https://github.com/opencv/opencv.git

It was long. Create a build directory. The name is build for the time being

$ cd opencv
$ mkdir build
$ cd build

Installation

Next is the installation.

cmake ../

It is near the end of the output.

--   Python 2:
--     Interpreter:                 /usr/bin/python2.7 (ver 2.7.16)
--     Libraries:                   /usr/lib/arm-linux-gnueabihf/libpython2.7.so (ver 2.7.16)
--     numpy:                       /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.16.2)
--     install path:                lib/python2.7/dist-packages/cv2/python-2.7
-- 
--   Python 3:
--     Interpreter:                 /usr/bin/python3 (ver 3.7.3)
--     Libraries:                   /usr/lib/arm-linux-gnueabihf/libpython3.7m.so (ver 3.7.3)
--     numpy:                       /usr/lib/python3/dist-packages/numpy/core/include (ver 1.16.2)
--     install path:                lib/python3.7/dist-packages/cv2/python-3.7

It's convenient to be able to configure the installation with just this. I will study again what is happening.

Finally, build and install.

$ make
# sudo make install

It took a lot of time. About 5 hours I don't want to do it anymore! !! !! !! !! !! !!

Verification

$ python3
>>> import cv2
>>> print(cv2.__version__)
4.5.1-dev

did it!

Finally

I've done it properly, so I've updated OpenCV to the latest dev version. It's ** super annoying ** because I have to build again to change the version.

Everyone be careful.

Recommended Posts

I installed OpenCV-Python on my Raspberry Pi
I installed Linux on my Mac
pigpio on Raspberry pi
Cython on Raspberry Pi
I installed tensorRT on Ubuntu 18.04
I talked to Raspberry Pi
Introduced pyenv on Raspberry Pi
Install OpenCV4 on Raspberry Pi 3
Install TensorFlow 1.15.0 on Raspberry Pi
I want to disable interrupts on Raspberry Pi (≒ DI / EI)
I made a surveillance camera with my first Raspberry PI.
Testing uart communication on Raspberry Pi
MQTT on Raspberry Pi and Mac
raspberry pi 4 centos7 install on docker
Install ghoto2 on Raspberry Pi (memo)
Try using ArUco on Raspberry Pi
OpenCV installation procedure on Raspberry Pi
Power on / off Raspberry pi on Arduino
Install OpenMedia Vault 5 on Raspberry Pi 4
L Chika on Raspberry Pi C #
Build wxPython on Ubuntu 20.04 on raspberry pi 4
Day 65 I installed matplotlib to draw graphs on my Jupyter notebook.
"Honwaka Notification Lamp" on Raspberry Pi Part 2
Detect "brightness" using python on Raspberry Pi 3!
[Super rudimentary] I installed GDAL on Anaconda
USB boot on Raspberry Pi 4 Model B
"Honwaka Notification Lamp" on Raspberry Pi Part 1
Enable UART + serial communication on Raspberry Pi
Adafruit Python BluefruitLE works on Raspberry Pi.
Accelerate Deep Learning on Raspberry Pi 4 CPU
Set swap space on Ubuntu on Raspberry Pi
Programming normally with Node-RED programming on Raspberry Pi 3
I installed TensorFlow (GPU version) on Ubuntu
Use the Grove sensor on the Raspberry Pi
Install 64-bit OS (bate) on Raspberry Pi
I installed Kivy on a Mac environment
Install docker-compose on 64-bit Raspberry Pi OS
Run servomotor on Raspberry Pi 3 using python
"Honwaka Notification Lamp" on Raspberry Pi Part 3
Working with sensors on Mathematica on Raspberry Pi
Mount Windows shared folder on Raspberry Pi
Matrix multiplication on Raspberry Pi GPU (Part 2)
How to install NumPy on Raspberry Pi
Working with GPS on Raspberry Pi 3 Python
I have a question. Unable to make protocol buffers on raspberry pi 3 modelB.
Detect slide switches using python on Raspberry Pi 3!
Build a Django environment on Raspberry Pi (MySQL)
Try using a QR code on a Raspberry Pi
I tried L-Chika with Raspberry Pi 4 (Python edition)
Raspberry Pi backup
Enjoy electronic work with GPIO on Raspberry Pi
Power on / off your PC with raspberry pi
I played RPG Maker 2000 Ruina ~ The Story of the Abandoned City ~ on Raspberry Pi
Use Grove-Temperature & Humidity Sensor (DHT11) on Raspberry Pi
Make DHT11 available on Raspberry Pi + python (memo)
Beginning cross-compilation for Raspberry Pi Zero on Ubuntu
Sound the buzzer using python on Raspberry Pi 3!
Play with your Ubuntu desktop on your Raspberry Pi 4
Display CPU temperature every 5 seconds on Raspberry Pi 4
Introduced Ceph on Kubernetes on Raspberry Pi 4B (ARM64)
Connect to MySQL with Python on Raspberry Pi