Install OpenCV & matplotlib on Raspberry Pi OS (Bookworm)

Install OpenCV & matplotlib on Raspberry Pi OS (Bookworm) to make it compatible with Picamera2. Tested on Raspberry Pi 5B/64-bit Raspberry Pi OS (Bookworm).


It's suggested in Raspberry Pi official Picamera2 Document, to install OpenCV compatible with the Qt GUI toolkit that is installed with Picamera2. Install OpenCV from apt.


To install OpenCV, enter the commands in Terminal:
sudo apt install -y python3-opencv
sudo apt install -y opencv-data

To install matplotlib:
sudo apt install python3-matplotlib

picam2_cv2_and_info.py
Python code to check if Picamera2/OpenCV related packages are installed, include: picamera2, cv2, numpy, matplotlib.
"""
Python code to check if Picamera2/OpenCV related packages installed,
include:
- picamera2
- cv2
- numpy
- matplotlib
"""
import platform
from importlib.metadata import version

print("Python:", platform.python_version())

# import picamera2
try:
    import picamera2
    print(picamera2.__name__ + ":", version(picamera2.__name__))
except ModuleNotFoundError as err:
    print("ModuleNotFoundError:", err)
    
# import cv2
try:
    import cv2
    print(cv2.__name__ + ":", cv2.__version__)
except ModuleNotFoundError as err:
    print("ModuleNotFoundError:", err)

# import numpy
try:
    import numpy
    print(numpy.__name__ + ":", numpy.__version__)
except ModuleNotFoundError as err:
    print("ModuleNotFoundError:", err)

# import matplotlib
try:
    import matplotlib
    print(matplotlib.__name__ + ":", matplotlib.__version__)
except ModuleNotFoundError as err:
    print("ModuleNotFoundError:", err)


print()


Next:
Python/OpenCV exercises on Raspberry Pi - Capture images from Camera Module 3 using Picamera2, display using OpenCV.
Picamera2+OpenCV+matplotlib Python exercise to display histogram, run on Raspberry Pi
Python + cv2 exercises to resize jpg and save in bmp


Comments

Popular posts from this blog

480x320 TFT/ILI9488 SPI wih EP32C3 (arduino-esp32) using Arduino_GFX Library

MicroPython/ESP32-C3 + 1.8" 128x160 TFT ST7735 SPI, using boochow/MicroPython-ST7735 library.