🛠 Vision par caméra : OpenCV sur le SoC x86
Objectives
Leverage the Alpha's x86 power for real-time vision: capture a USB camera (or Intel RealSense, explicitly cited as compatible in the official documentation) on one of the three USB 3.0 Type-A ports, and process images with OpenCV in Python — capture, resizing, face detection. This is the type of workload a microcontroller cannot handle, but the Core m3-7Y30 can manage.
Hardware
- LattePanda Alpha running Windows or Linux (Linux: a recent distribution is recommended for UVC; community support exists beyond Ubuntu 16.04)
- UVC USB camera (standard webcams work without drivers) or Intel RealSense camera
- HDMI / DisplayPort-USB-C / eDP display depending on your configuration
pip install opencv-python(orsudo apt install python3-opencvon Linux)
Complete Code
# vision_visage.py — capture USB + détection de visage OpenCV
import cv2
cap = cv2.VideoCapture(0) # 0 = première caméra UVC (Windows ou /dev/video0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
assert cap.isOpened, "Caméra introuvable : vérifier /dev/video0 ou le numéro de flux"
while True:
ok, frame = cap.read
if not ok:
break
gris = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
visages = cascade.detectMultiScale(gris, scaleFactor=1.2, minNeighbors=5)
for (x, y, w, h) in visages:
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
cv2.putText(frame, f"visages: {len(visages)}", (10, 30),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
cv2.imshow("LattePanda Alpha - vision", frame)
if cv2.waitKey(1) & 0xFF == 27: # Échap pour quitter
break
cap.release
cv2.destroyAllWindows
Expected Verification
The window opens within seconds displaying the 640×480 stream; a green rectangle surrounds each detected face, and the counter is displayed in red. On Linux, ls /dev/video* shows the camera; on Windows, Device Manager lists it under "Imaging devices".
Common Errors
VideoCapture(0)selecting another camera (virtual, infrared): tryVideoCapture(1), or on Linux target/dev/video1.- Forgetting
cv2.waitKey(1): the window freezes and stops responding. - RealSense cameras requiring the specific librealsense library in addition to OpenCV.
- On recent Linux systems, missing multimedia packages if using a minimal distribution: install python3-opencv via apt instead of pip if video dependencies are missing.
Other tutorials for this board
- Faire clignoter une LED sur les broches du coprocesseur
- Bouton poussoir et console série avec le coprocesseur
- Premier script Python sur le PC x86 de la carte
- Pont série SoC ↔ MCU : le tunnel x86 vers ATmega32U4
- Lire un capteur analogique du MCU depuis Python (Firmata)
- Wi-Fi 802.11ac et Bluetooth 4.2 depuis le SoC
Code examples for this board
clignotante.pyPythonbouton.pyPythonservo.pyPythonanalogique.pyPythonrespiration.pyPythonneopixel.pyPython