Introduced python3-OpenCV3 to Raspberry Pi


Opencv is the royal road when trying to recognize faces with Raspberry Pi. However, when I looked it up, it wasn't straightforward and there seemed to be a trap. Let's clarify the procedure by leaving the version etc. exactly. There will be cases where we want to create the same environment again in the future.



As a result, this page was made almost as it is. Installing OpenCV 3 on Raspberry Pi + Python 3 as easily as possible


rasbian version check

pi@raspberrypi:~ $ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 9.13 (stretch)
Release:        9.13
Codename:       stretch

Pre-install the libraries that OpenCV depends on (exactly the same as the reference)

$ sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-100
$ sudo apt-get install libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5
$ sudo apt-get install libatlas-base-dev
$ sudo apt-get install libjasper-dev

install opencv As of 2021/1/10 The latest is Install by specifying the version for reference. However, there is no 3.4.4, so if you specify 3.4.4, an error will occur and it will tell you which version exists.

$ sudo pip3 install opencv-python==3.4.4
  Could not find a version that satisfies the requirement opencv-python==3.4.4(from versions:,,,,,,,,,,,,,,,,,,,,,,,,

Specify again and install.

$ sudo pip3 install opencv-python==

I was able to confirm that 3.4.4 was installed. (Although I think you should display here as well)

pi@raspberrypi:~/face $ python3
Python 3.5.3 (default, Nov 18 2020, 21:09:16) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__

Operation check (exactly the same as the reference) Now that canny.jpg is generated, it seems that you can use opencv from at least python3.

pi@raspberrypi:~/face $ python3
Python 3.5.3 (default, Nov 18 2020, 21:09:16) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> bgr = cv2.imread('./test.jpg', cv2.IMREAD_COLOR)
>>> gray = cv2.cvtColor(bgr, cv2.COLOR_BGR2GRAY)
>>> canny = cv2.Canny(gray, 200, 50)
>>> cv2.imwrite('./canny.jpg', canny)

test.jpg is lena, which is often used in opencv examples. You can see that the conversion to GrayScale was completed. test.jpg



I haven't tried to see if it works with the latest opencv

Recommended Posts

Introduced python3-OpenCV3 to Raspberry Pi
I talked to Raspberry Pi
Introducing PyMySQL to raspberry pi3
Introduced pyenv on Raspberry Pi
Port FreeRTOS to Raspberry Pi 4B
Output from Raspberry Pi to Line
[Raspberry Pi] Changed Python default to Python3
Connect two USB cameras to Raspberry Pi 4
Raspberry Pi backup
How to install NumPy on Raspberry Pi
How to use Raspberry Pi pie camera Python
Introduced Ceph on Kubernetes on Raspberry Pi 4B (ARM64)
Connect your Raspberry Pi to your smartphone using Blynk
Connect to MySQL with Python on Raspberry Pi
What is Raspberry Pi?
GPGPU with Raspberry Pi
pigpio on Raspberry pi
Raspberry Pi video camera
Raspberry Pi Bad Knowledge
Let's do Raspberry Pi?
DigitalSignage with Raspberry Pi
Raspberry Pi 4 setup memo
Cython on Raspberry Pi
Raspberry Pi system monitoring
From setting up Raspberry Pi to installing Python environment
Easy IoT to start with Raspberry Pi and MESH
Try to visualize the room with Raspberry Pi, part 1
How to use the Raspberry Pi relay module Python
Output to "7-segment LED" using python on Raspberry Pi 3!
Easy introduction to home hack with Raspberry Pi and
Raspberry Pi 4B initial setting
Indoor monitoring using Raspberry Pi
Mutter plants with Raspberry Pi
Update Python for Raspberry Pi to 3.7 or later with pyenv
Install Raspberry Pi OS (Raspbian)
Introduced Jupyter Notebook to CentOS 7
[Raspberry PI & Garmin GLO] Until you connect Bluetooth GPS to Raspberry Pi
Raspberry Pi + Python + OpenGL memo
I want to disable interrupts on Raspberry Pi (≒ DI / EI)
I tried to automate [a certain task] using Raspberry Pi
Raspbian initial settings (Raspberry Pi 4)
raspberry pi 1 model b, python
Change the message displayed when logging in to Raspberry Pi
How to get temperature from switchBot thermo-hygrometer using raspberry Pi
Use NeoPixel on Raspberry Pi
Install OpenCV4 on Raspberry Pi 3
Install TensorFlow 1.15.0 on Raspberry Pi
[Raspberry Pi] Minimum device driver creation memo to output GPIO
Translate I2C device driver for Arduino to Python for Raspberry pi
Connect Raspberry Pi to Alibaba Cloud IoT Platform with Python
I sent the data of Raspberry Pi to GCP (free)
Log in to Raspberry PI with ssh without password (key authentication)
Use your Raspberry Pi to read your student ID number from your student ID card
I tried to automate the watering of the planter with Raspberry Pi
I made a web server with Raspberry Pi to watch anime
I want to run the Python GUI when starting Raspberry Pi
Use python on Raspberry Pi 3 to illuminate the LED (Hello World)
A memo when connecting bluetooth from a smartphone / PC to Raspberry Pi 4
Raspberry Pi --1 --First time (Connect a temperature sensor to display the temperature)
How to play music (wav / mp3) files on Raspberry Pi python
Run Polyglot on Raspberry Pi to perform morphological analysis in English