Day 8: Camera + OpenCV for Image Processing.
Course Title: Raspberry Pi and Artificial Intelligence
Presented by:
Eng. Mohammed Al-Ramadi
Mechatronics Engineer & Robotics Researcher
Course Introduction
Course Objectives: Course Overview:
What We’ll Cover Over 10 Days
Understand the fundamentals of Raspberry • Day 1 – Raspberry Pi Setup, OS, and I/O Basics.
Pi hardware and software.
• Day 2 – Linux & Python Raspberry Pi Applications.
Learn how to interface Raspberry Pi with • Day 3 – Networking & IoT Communications.
physical components (LEDs, sensors, motors).
• Day 4 – Sensors & Actuators : Environmental Monitoring.
Explore real-time data handling, automation, • Day 5 – Motor Control and PWM Applications.
and robotics. • Day 6 – Data Logging and Visualization (CSV/Matplotlib).
Integrate Raspberry Pi with AI tools (object • Day 7 – Integrated Systems: Raspberry Pi, ESP32, and Arduino.
detection, decision-making systems). • Day 8 – Camera + OpenCV for Image Processing.
Build your own AI-powered smart system by • Day 9 – Intro to Ai with Raspberry Pi: Object Detection and Classification.
the end of the course • Day 10 – Final Project : Build an AI-Powered Smart System.
Presented by:
Eng. Mohammed Al-Ramadi
Introduction to Computer Vision
Definition:
Computer Vision (CV) is the field of enabling computers to interpret and make decisions
based on visual input (images/videos).
.رؤية الحاسوب هي فرع من الذكاء االصطناعي يُعنى بجعل الحاسوب "يرى" ويفهم محتوى الصور والفيديو
• Used in facial recognition, object tracking, barcode
Real-life Example
scanning, license plate reading, etc.
• Raspberry Pi with OpenCV can perform real-time نظام جرس ذكي يلتقط صورة الزائر
image analysis. إشعارا إلى
ً ويتعرف على وجهه ويرسل
.صاحب المنزل
Presented by:
Eng. Mohammed Al-Ramadi
Overview of Raspberry Pi Camera Modules
Module Resolution Interface Special Features
Camera Module v1 5 MP CSI Basic use
Camera Module v2 8 MP CSI Better resolution
Interchangeable
HQ Camera 12.3 MP CSI
lenses
Plug-and-play, not
USB Webcam Varies USB
limited to CSI slot
CSI (Camera Serial Interface) gives high-speed video directly to the GPU.
Installing and Testing the Pi Camera
1- Connect the ribbon cable to the CSI port (carefully – the shiny side faces the HDMI port).
2- Enable camera support in terminal:
sudo raspi-config
→ Interface Options → Camera → Enable
sudo reboot
3- Load video driver:
sudo modprobe bcm2835-v4l2
To make it persistent:
sudo nano /etc/modules
# Add:
bcm2835-v4l2
3- Test with
ls /dev/video0
Presented by:
Eng. Mohammed Al-Ramadi
Introduction to OpenCV and Image Processing
OpenCV (Open Source Computer Vision) is a powerful
Python/C++ library for image processing.
❑ Supports:
• Image capture and manipulation
• Real-time video processing
• Object and face detection
• Machine learning and AI models
❑ Installed via
sudo apt update
pip3 install opencv-python
sudo apt install libatlas-base-dev
Presented by:
Eng. Mohammed Al-Ramadi
Capturing and Displaying Images and Video (OpenCV)
❑ Example: Live Camera Feed
Press Q to exit the video window.
Presented by:
Eng. Mohammed Al-Ramadi
Capturing and Displaying Images and Video (OpenCV)
❑ Example: Live Camera Feed
كود مباشر لعرض الفيديو
S والتقاط صورة عند الضغط على
Presented by:
Eng. Mohammed Al-Ramadi
Basic Image Operations
Operation Purpose
Resize Adjust resolution for speed
Grayscale Convert image to single channel
Blur Reduce noise before detection
Flip Mirror view (for selfie cam)
Draw Add lines, shapes, or text
❑ Example: Convert to grayscale
gray = cv2RGB_ROLOC.2vc ,emarf(roloCtvc.2GRAY(
Preprocessing helps improve detection accuracy.
Presented by:
Eng. Mohammed Al-Ramadi
Object Detection with Haar Cascades
• Haar cascades are pre-trained classifiers for face,
eyes, hands, etc.
• Lightweight and fast for Raspberry Pi.
Face Detection Example:
Can detect multiple faces in real-time from a video stream.
Presented by:
Eng. Mohammed Al-Ramadi
Practical Lab 1: Real-Time Camera Feed
Objective:
• Open camera using OpenCV
• Display live video with FPS counter
Extensions:
• Add brightness/contrast sliders
• Show timestamp on video
Presented by:
Eng. Mohammed Al-Ramadi
Practical Lab 2: Face Detection in Real-Time
Objective:
• Use Haar cascade classifier
• Detect faces and draw bounding boxes
• Count and log number of faces
Bonus Task: Save cropped face regions as separate
image files for dataset creation.
Presented by:
Eng. Mohammed Al-Ramadi
Applications and Limitations
Application Notes
Smart surveillance Motion or face-triggered recording
Classroom attendance Face recognition of students
Robotics Visual line tracking, gesture following
Access control Face or QR-based authentication
Limitations on Pi:
• Performance constraints (use lower resolutions for better speed)
• False positives in noisy lighting
• Lag if multiple tasks (detection + saving + networking)
Presented by:
Eng. Mohammed Al-Ramadi
Practical Lab 1: Log Sensor Data to CSV
Objective:
Use a real DHT11/DHT22 sensor to:
•Read temperature and humidity.
•Log data every 10 seconds into a CSV file.
Expanded Tasks:
•Use exception handling to ensure data saving even if reading fails.
•Add a "Session ID" to distinguish multiple experiments.
Presented by:
Eng. Mohammed Al-Ramadi
Thanks
Prepared and Delivered by:
Eng. Mohammed Al-Ramadi
Te: 773431543