In today’s Lesson we will see just how far we can push things on the Raspberry Pi 5. I will show you how to install YOLO11 on the Pi . I will show you a simple program that will run YOLO11 under Python and openCV. The objective in today’s lesson is to see if the Pi5, without a Hailo accelerator hat, has sufficient power to do useful object detection. We will not use an accelerator hat, but the work is computationally intensive, so you must use active cooling. This is the low cost cooling fan we are using. It is sufficient to do the job, low cost and is a thin form factor that allows other hats to still fit on the Raspberry Pi 5. You can pick up the fan I am using HERE. Also, we are using an 8GB Pi 5. If you already have a Pi 5, it will probably work. The Pi 5 we are using is available HERE. These appliations are power hungry, so make sure you are using an official Pi Power supply.
In this lesson, I assume you are already familiar with the Pi 5. Note we are using Bookworm OS. Not all the dependencies work yet on Trixie, so I strongly recommend starting by flashing a fresh bookworm SD card.
YOLO11 is a powerful AI object detection model that runs well on the Raspberry Pi 5. The model below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | # 1. Configure X11 (manual steps required) sudo raspi-config # → Go to Advanced Options → X11 → Enable X11 # → Finish and reboot when prompted # 5. Update system and install OpenCV sudo apt update sudo apt full-upgrade -y sudo apt install python3-opencv -y # Verify OpenCV python3 -c "import cv2; print('OpenCV version:', cv2.__version__)" # Expected output: something like "OpenCV version: 4.6.0" or higher # 6. Install MediaPipe pip install mediapipe --break # Verify MediaPipe python3 -c "import mediapipe as mp; print('MediaPipe version:', mp.__version__)" # 7. Create and activate virtual environment for YOLO11 (Ultralytics) python3 -m venv --system-site-packages YOLO source YOLO/bin/activate # You are now inside the (YOLO) virtual environment # Install Ultralytics YOLO11 inside it pip install "numpy<2.0" ultralytics # Now create a Pi friendly YOLO11 model yolo export model=yolo11n.pt format=ncnn # Optional: Verify YOLO installation python -c "from ultralytics import YOLO; print('Ultralytics YOLO ready')" # When finished working with YOLO, you can deactivate with: # deactivate #Now open Thonny, and you need to point thonny to the virtual environment you #just created. Open tools- options, select 'interpreter' tab, then click they Python #executable, selecting ... and navigate from home directory, #to YOLO, to bin, and then select python |
Now you should be set up to use YOLO11 on the Raspberry Pi 5!
We will start with this program, which is a simple grab a frame and show a frame openCV Program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import cv2 from picamera2 import Picamera2 import time piCam = Picamera2() W=1280 H=720 RES = (W,H) piCam.preview_configuration.main.size = RES piCam.preview_configuration.main.format = "RGB888" piCam.preview_configuration.controls.FrameRate=60 piCam.preview_configuration.align() piCam.configure("preview") piCam.start() fps=0 tStart=time.time() while True: frame= piCam.capture_array() #frame=cv2.flip(frame,-1) deltaT=time.time()-tStart tStart=time.time() fps= fps*.9 + .1/deltaT cv2.putText(frame, "FPS: "+str(round(fps,1)), (int(W*.01), int(H*.075)), cv2.FONT_HERSHEY_SIMPLEX, H*.002, (0, 0, 255), 2) cv2.imshow("Camera", frame) cv2.moveWindow("Camera",100,100) if cv2.waitKey(1)==ord('q'): break cv2.destroyAllWindows() |
In the video, we show how to use YOLO11 object detection in this simple program.