Tutorial Overview
π― Learning Objectives
By the end of this tutorial, you will:
β
Access and view camera streams
β
Understand image topics and formats
β
Perform basic image processing (filters, thresholding, edge detection)
β
Detect colors and shapes
β
Record and process video data
β
Understand camera calibration
β
Explore potential perception applications
β
Integrate vision with robot control
β±οΈ Time Required
Reading & Setup: 20 minutes
Basic Image Access: 25 minutes
Image Processing: 40 minutes
Color/Shape Detection: 35 minutes
π Prerequisites
β
Completed Sensor Data Visualization
β
Completed ROS2 Communication & Tools
β
Basic Python knowledge
β
Understanding of image concepts (pixels, RGB)
β
OpenCV basics helpful but not required
β
Can record and play rosbags
π οΈ What You'll Need
β
Beetlebot (powered, camera working)
β
Laptop with ROS2 Jazzy
β
Test objects with distinct colors
β
Good lighting (avoid direct sunlight on camera)
β
Printed patterns for detection tests (optional)
Part 1: Camera System Overview
Raspberry Pi Camera V1.3 Specifications
Your robot's camera:
Hardware:
Sensor: OmniVision OV5647
Resolution: 5MP (2592Γ1944 max)
Typical streaming: 1080p (1920Γ1080) or 720p (1280Γ720)
Frame rate: 30 fps (1080p), 60 fps (720p)
FOV: ~54Β° horizontal, ~41Β° vertical
Focus: Fixed (best 30cm - 3m)
Interface: CSI (Camera Serial Interface) to Pi
Mounting:
Height: 8.8cm from ground
Position: 15cm forward from center
Orientation: Horizontal, forward-facing
Topic: /pi_camera/image_raw
Available topics:
Topic details:
/pi_camera/image_raw (sensor_msgs/Image)
Uncompressed RGB8 or BGR8 format
~30 MB/s bandwidth (1080p @ 30fps)
/pi_camera/image_raw/compressed (sensor_msgs/CompressedImage)
Better for remote viewing
/pi_camera/camera_info (sensor_msgs/CameraInfo)
Intrinsic parameters (focal length, principal point)
Understanding Image Messages
Image message structure:
Common encodings:
rgb8: 8-bit RGB (Red-Green-Blue)
bgr8: 8-bit BGR (OpenCV default)
rgba8: 8-bit RGBA (with alpha channel)
Part 2: Accessing Camera Stream
Quick View with rqt_image_view
Simplest method:
Controls:
Refresh: Click dropdown again
Rotate: Image β Transform menu
[PLACEHOLDER: Screenshot of rqt_image_view showing camera feed]
Exercise 9.1: Camera Field of View Test
Task: Measure camera's actual field of view
Materials needed:
Procedure:
Viewing in RViz
Integrated visualization:
Benefits of RViz camera view:
See camera + LiDAR + map simultaneously
Overlay detection results
3D context for camera view
Can add measurement tools
Part 3: Basic Image Processing with OpenCV
Installing Dependencies
Creating Image Processing Node
[!WARNING] TODO: Exercise Script Not Included in Core Repository The camera_processor.py script below is an exercise for the user to practice processing camera frames with OpenCV. It does not come pre-installed.
Basic template for image processing:
Script:
Run:
Two windows appear:
Original: Color camera feed
Grayscale: Converted to grayscale
Press Ctrl+C to stop
Image Filtering
Add filters to processing node:
[PLACEHOLDER: Screenshot showing original vs filtered images]
Exercise 9.2: Edge Detection for Obstacle Boundaries
Task: Detect obstacles using edge detection
Modify processing node:
Test:
Place various objects in front of robot
Observe edge detection outlining objects
Try different Canny thresholds (50, 150) to tune sensitivity
Part 4: Color Detection
HSV Color Space
Why HSV instead of RGB?
RGB (Red-Green-Blue):
Lighting affects all channels
Hard to isolate specific colors
HSV (Hue-Saturation-Value):
Hue = Color (0-180Β° in OpenCV)
Saturation = Color intensity (0-255)
Value = Brightness (0-255)
Lighting mainly affects Value
Easier to detect specific colors
Color ranges in HSV (OpenCV):
Color Detection Node
[!WARNING] TODO: Exercise Script Not Included in Core Repository The color_detector.py script below is an exercise for color tracking. It is not pre-installed. You are encouraged to create it yourself!
Create color detector:
Script:
Run:
Exercise 9.3: Color-Based Object Tracking
Task: Track colored object and display centroid
Modification to color_detector.py:
Test:
Hold red object in front of camera
Observe centroid tracking
Check console for position logs
Part 5: Shape Detection
Detecting Simple Shapes
Add shape detection:
Exercise 9.4: Shape and Color Recognition
Task: Create multi-property detector
Test scenario:
Part 6: Camera Calibration
Camera distortion:
Lens distortion (barrel, pincushion)
Affects measurements and 3D perception
Need calibration to correct
What calibration provides:
Intrinsic matrix (focal length, principal point)
Allows undistortion of images
Enables accurate 3D measurements
Viewing Current Calibration
Using Calibration Data
Undistort image:
Part 7: Practical Applications
Application 1: Line Following
Detect line on floor, steer toward it:
Use error for steering:
Application 2: Obstacle Color Classification
Classify obstacles by color, react differently:
Application 3: AprilTag Detection
AprilTags = Fiducial markers (like QR codes for robots)
Install apriltag library:
Launch apriltag detector:
Use cases:
Precise localization (know exact position from tag)
Object identification (each tag has unique ID)
Docking stations (navigate to specific tag)
AR applications (overlay virtual objects)
Part 8: Recording and Processing Video
Recording Camera Data
Offline Processing
[!WARNING] TODO: Exercise Script Not Included in Core Repository The offline_processor.py script below is an exercise to demonstrate processing rosbags programmatically. It is not pre-installed.
Python script: offline_processor.py
Run:
Part 9: Limitations and Considerations
What Camera Perception Can't Do (Without ML)
β οΈ Important: Basic image processing has limitations
Without machine learning:
β Cannot do:
Object recognition (identify specific objects like "person", "chair", "dog")
Text reading (OCR - though basic, possible with libraries)
Complex scene understanding
β
Can do:
Shape detection (simple geometries)
Marker detection (AprilTags, QR codes)
Brightness/contrast analysis
When to Use Machine Learning
For advanced perception, need ML models:
Options:
Pre-trained models (YOLO, MobileNet, etc.)
Custom training (TensorFlow, PyTorch)
Train on specific objects
Requires dataset collection
Computationally intensive
Note: ML perception is beyond this tutorial but worth exploring!
Lighting Considerations
Camera performance varies with lighting:
Good lighting:
Indirect, even illumination
Consistent throughout environment
Poor lighting:
Direct sunlight (overexposes)
Backlit scenes (subject too dark)
Rapid changes (drives in/out of shadows)
Very low light (noisy images)
Tip: Test perception algorithms in actual target lighting conditions!
Part 10: Knowledge Check
Why use HSV instead of RGB for color detection?
What does camera calibration provide?
What's the difference between /image_raw and /image_raw/compressed?
Can basic OpenCV detect "what" an object is (e.g., identify as "cup")?
Why is the camera mounted forward-facing at 8.8cm height?
Hands-On Challenge
Task: Color-based navigation system
Requirements:
Robot follows green markers on floor
Publishes cmd_vel based on vision
Displays annotated video showing detections
Deliverable:
Python script with vision processing
Video recording of robot navigating course
Documentation of color thresholds used
Discussion of challenges encountered
Bonus:
Add shape detection (only respond to green circles, not rectangles)
Implement smooth steering (PID control based on centroid error)
Handle cases where no marker visible
Part 11: What You've Learned
β
Congratulations!
You now understand:
Camera Fundamentals:
β
Camera specifications and mounting
β
Image topics and message formats
β
Viewing camera streams (rqt, RViz)
β
Recording and playing back video
Image Processing:
β
OpenCV basics (CvBridge, cv2 functions)
β
Image filtering (blur, edge detection)
β
Color detection (HSV color space)
β
Shape detection (contours, polygons)
Practical Applications:
β
Obstacle classification by color
β
Object tracking (centroids)
β
Marker detection (AprilTags)
Advanced Topics:
β
Camera calibration concepts
β
Offline video processing
β
Limitations of basic vision
π― You're Now Ready For:
Immediate Next: β Localization Techniques - Combine vision with other sensors
Autonomous Navigation: β Autonomous Navigation - Vision-aided obstacle avoidance
Advanced Vision:
Machine learning object detection (YOLO, MobileNet)
Visual odometry (estimate motion from camera)
SLAM with visual features (ORB-SLAM)
Depth estimation (if adding depth camera)
Quick Reference
Essential Camera Commands
OpenCV Quick Reference
HSV Color Ranges (OpenCV)
Color
Hue Range
Typical Sat
Typical Val
Completed Camera-Based Perception! π
β Continue to Localization Techniques
β Or return to Tutorial Index
Last Updated: January 2026
Tutorial 9 of 11 - Advanced Level
Estimated completion time: 150 minutes