๐ฅ Vision System (dvision) โ
The vision system is the "eyes" of the robot soccer application, responsible for real-time field perception, target object recognition, and autonomous localization.
๐ System Overview โ
The dvision module is based on computer vision technology and provides complete field perception capabilities:
- Real-time Object Detection: Identify soccer balls, goals, obstacles, and field markers
- Robot Localization: Autonomous localization based on AMCL particle filter
- Multi-camera Support: Compatible with USB cameras, GStreamer, and ZED stereo cameras
- Neural Network Detection: YOLO deep learning model
- Data Recording and Playback: Support for offline analysis and algorithm optimization
๐ฏ Core Functions โ
1. Object Detection โ
Ball Detection โ
- Detection Method: Color segmentation + shape matching + YOLO neural network
- Tracking Algorithm: Kalman filter for smooth trajectory
- Output Information:
- Ball position (relative to robot coordinates)
- Ball velocity and direction
- Detection confidence
# Configuration example: dvision/config/ball_detection.yaml
ball_detection:
color_range:
h_min: 0
h_max: 20
s_min: 100
v_min: 100
min_radius: 10
max_radius: 100
confidence_threshold: 0.7Goal Detection โ
- Detection Targets: Own goal (blue), opponent goal (yellow)
- Detection Features: Color, shape, positional relationships
- Output Information:
- Goal post positions
- Goal center point
- Distance and angle
Obstacle Detection โ
- Detection Objects: Opponent robots, referees, field boundaries
- Detection Method: Depth information + color segmentation
- Avoidance Strategy: Real-time path planning
Field Marker Detection โ
- Detection Targets:
- Field lines (sidelines, center line, penalty area lines)
- Circles (center circle, penalty spot)
- Corners (field corners)
- Purpose: Assist localization and navigation
2. Robot Localization (AMCL) โ
Localization Principle โ
Uses AMCL (Adaptive Monte Carlo Localization) particle filter algorithm:
- Particle Initialization: Randomly distribute particles on the field
- Motion Update: Update particle positions based on odometry
- Observation Update: Update particle weights based on visual observations (field lines, goals)
- Resampling: Keep high-weight particles, eliminate low-weight particles
- Position Estimation: Weighted average to obtain robot position
Localization Accuracy โ
- Position Accuracy: ยฑ5cm
- Angle Accuracy: ยฑ3ยฐ
- Update Frequency: 30Hz
# Configuration example: dvision/config/localization.yaml
amcl:
min_particles: 500
max_particles: 5000
kld_err: 0.01
kld_z: 0.99
update_min_d: 0.1
update_min_a: 0.23. Camera System โ
Supported Camera Types โ
USB Camera (V4L2)
# Start USB camera
roslaunch dvision default.launch camera_type:=v4l2 device:=/dev/video0GStreamer Stream
# Start network stream
roslaunch dvision default.launch camera_type:=gstreamer \
pipeline:="udpsrc port=5000 ! ..."ZED Stereo Camera
# Start ZED camera (supports depth information)
roslaunch dvision default.launch camera_type:=zedCamera Calibration โ
Camera calibration is used to eliminate lens distortion and improve detection accuracy.
Calibration Steps:
- Print checkerboard calibration pattern
- Run calibration program:
rosrun dvision camera_calibration- Move calibration board to capture images from multiple angles
- Save calibration parameters to configuration file
Calibration Parameters Example:
camera_matrix:
rows: 3
cols: 3
data: [615.123, 0.0, 320.0,
0.0, 615.123, 240.0,
0.0, 0.0, 1.0]
distortion_coefficients:
rows: 1
cols: 5
data: [-0.123, 0.045, 0.001, -0.002, 0.0]4. Image Processing Pipeline โ
Raw Image โ Distortion Correction โ Color Space Conversion โ Object Detection โ Coordinate Transform โ Output Results
โ โ โ โ โ โ
640x480 Undistort RGBโHSV YOLO/Traditional PixelโWorld VisionInfoCoordinate System Transformation โ
Pixel Coordinates โ Camera Coordinates โ Robot Coordinates โ World Coordinates
# Coordinate transformation example
def pixel_to_world(pixel_x, pixel_y, camera_matrix, robot_pose):
# 1. Pixel coordinates โ Camera coordinates
camera_point = inverse_project(pixel_x, pixel_y, camera_matrix)
# 2. Camera coordinates โ Robot coordinates
robot_point = camera_to_robot_transform(camera_point)
# 3. Robot coordinates โ World coordinates
world_point = robot_to_world_transform(robot_point, robot_pose)
return world_point๐ Output Data Format โ
VisionInfo Message โ
# ROS message definition
VisionInfo:
header:
stamp: timestamp
frame_id: "base_link"
# Ball information
ball:
detected: True/False
position: [x, y, z] # Relative to robot
velocity: [vx, vy]
confidence: 0.95
# Goal information
goals:
- color: "yellow" # Opponent goal
position: [x, y]
distance: 3.5
angle: 0.2
- color: "blue" # Own goal
position: [x, y]
distance: 8.0
angle: 3.14
# Obstacles
obstacles:
- type: "robot"
position: [x, y]
radius: 0.2
# Field features
field_features:
lines: [...]
circles: [...]
corners: [...]
# Localization information
localization:
position: [x, y, theta] # World coordinates
confidence: 0.85๐ง Configuration and Tuning โ
Detection Parameter Tuning โ
Color Threshold Adjustment
# Start debugging tool
rosrun dvision color_tunerAdjust HSV thresholds in the GUI and view detection results in real-time.
YOLO Model Configuration
yolo:
model_path: "/path/to/yolo_model.pt"
confidence_threshold: 0.5
nms_threshold: 0.4
input_size: [416, 416]Performance Optimization โ
Reduce Resolution
camera:
width: 640 # Reduce to 320 for speed
height: 480 # Reduce to 240 for speed
fps: 30ROI (Region of Interest)
roi:
enabled: true
x: 0
y: 240 # Process only bottom half of image
width: 640
height: 240๐ฌ Recording and Playback โ
Record Vision Data โ
# Record all vision topics
rosbag record /vision_info /camera/image_raw /camera/camera_infoPlayback Data โ
# Playback recorded data
roslaunch dvision replay.launch bag_file:=/path/to/data.bagOffline Analysis โ
# Python script to analyze recorded data
import rosbag
bag = rosbag.Bag('data.bag')
for topic, msg, t in bag.read_messages(topics=['/vision_info']):
if msg.ball.detected:
print(f"Ball at: {msg.ball.position}")๐ Debugging Tools โ
Visualization Tools โ
# Start RViz visualization
rosrun rviz rviz -d $(rospack find dvision)/rviz/vision.rvizImage Viewing โ
# View raw image
rosrun image_view image_view image:=/camera/image_raw
# View detection results
rosrun image_view image_view image:=/dvision/debug_imagePerformance Monitoring โ
# View topic frequency
rostopic hz /vision_info
# View message latency
rostopic delay /vision_info๐ Performance Metrics โ
| Metric | Value |
|---|---|
| Detection Frame Rate | 30 FPS |
| Ball Detection Accuracy | 95% |
| Localization Accuracy | ยฑ5cm |
| Processing Latency | <50ms |
| CPU Usage | ~40% |
๐ Related Documentation โ
- Behavior Decision System - How to use vision information for decision making
- Configuration Management - Detailed vision parameter configuration
- Complete Tutorial - Deploy vision system from scratch
๐ก FAQ โ
Q: Ball detection is inaccurate, what should I do? A: Adjust color thresholds, ensure good lighting conditions, use the color_tuner tool for optimization.
Q: Localization drift, what should I do? A: Check if field markers are clear, increase particle count, adjust AMCL parameters.
Q: Frame rate is too low, what should I do? A: Reduce image resolution, use ROI, disable unnecessary detection features.
Q: How to add new detection targets? A: Refer to existing detector code, implement new detection class, enable in configuration file.
