Advanced Features and Tracking
This chapter describes the system's automatic tracking features in detail, including color tracking, face tracking, and QR code tracking, as well as the target lock mechanism and parameter tuning.
Automatic Tracking Modes Overview
The system supports three automatic tracking modes:
- Color tracking: track objects of a specified color
- Face tracking: track faces
- QR code tracking: track QR codes
Color Tracking
Color Selection
The system supports tracking of several colors:
- Red
- Green
- Blue You can switch colors with keys in the program:
X: select redY: select greenZ: select blue
Color Tracking Workflow
- Press
Cto connect the gimbal - Press
2to enter color tracking mode - Place the object of the target color in the center of the frame
- Press
Tto lock the target - Move the target and observe the gimbal following it
Simple Color Tracking Example
You can also use the simple color tracking example program:
python examples/04_color_track_simple.py --camera 0 --port COM3 --color redThis program provides the most basic color tracking functionality and is good for learning.
Face Tracking
How Face Tracking Works
The system uses OpenCV's Haar cascade classifier for face detection. Once a face is detected, the system automatically calculates the target position and controls the gimbal to follow it.
Face Tracking Workflow
- Press
Cto connect the gimbal - Press
1to enter face tracking mode - Place your face in the center of the frame
- Press
Tto lock the target - Move your face; the gimbal follows automatically
Tips for Improving Face Detection
- Keep the lighting adequate and avoid backlight
- Face the camera directly
- Keep an appropriate distance (1-3 m recommended)
- Avoid scenes with multiple faces, or use the lock mechanism to keep the tracking target fixed
QR Code Tracking
QR code tracking mode uses OpenCV's QRCodeDetector for QR code recognition and localization. It works in a similar way to the previous two tracking modes:
- Connect the gimbal and enter QR code tracking mode
- Place the QR code in the center of the frame and press
Tto lock - Move the QR code and observe the gimbal following it
Target Lock Mechanism
What Locking Does
The target lock mechanism is a key feature of the system. It:
- Records the target's center position and size at the moment of locking
- Prefers the target closest to the lock point when multiple targets appear
- Prevents the target from jumping around frequently, keeping tracking stable
Locking Workflow
- Place the target object in the center of the frame
- Press
Tto lock - After a successful lock, the system prioritizes the target most similar to the one locked
- Press
Sto cancel the lock and stop tracking
Target Selection Logic After Locking
When selecting a target after locking, the system considers two factors:
- Distance: how close the target center is to the lock point (weight 70%)
- Size: how similar the target's size is to the locked size (weight 30%)
- The system tracks the target with the highest combined score
Tuning Tracking Control Parameters
The following tunable parameters are in src/trackers/tracking_controller.py:
| Parameter | Default | Description |
|---|---|---|
| kp_pan | 0.08 | Proportional gain for pan tracking |
| kp_tilt | 0.12 | Proportional gain for tilt tracking |
| dead_zone | 30 | Dead zone (pixels); the gimbal does not move within this range |
| min_move_interval | 0.15 | Minimum move interval (seconds); limits how often the gimbal moves |
How to Adjust the Parameters
- Tracking too slow: increase
kp_panandkp_tilt - Tracking too sensitive, causing jitter: decrease
kp_panandkp_tilt, increasemin_move_interval, or increasedead_zone - Frequent small adjustments causing jitter: increase
dead_zone - Direction reversed: change the sign of
delta_panordelta_tiltin thecalculate_movemethod
Complete Tracking Example
Here is a complete usage example:
- Start the program:
python examples/auto_tracking_demo.py --camera 0 --port COM3 --color red- Press
Cto connect the gimbal - Press
2to select color tracking mode - Place the red object in the center of the frame
- Press
Tto lock the target - Move the object and observe the gimbal following it
- To switch to green, press
Yand then pressTagain to lock - Press
Sto stop tracking and pressRto return to center - Press
Qto quit
Advanced Development Tips
If you need custom features or further development, refer to:
src/sc_servo.py: low-level servo communicationsrc/gimbal.py: gimbal controlsrc/trackers/tracking_controller.py: tracking controllersrc/detectors/: various target detectors

