Skip to content

Commit 7949cf5

Browse files
committed
Create coffee_vision package
1 parent 296e077 commit 7949cf5

File tree

13 files changed

+1052
-0
lines changed

13 files changed

+1052
-0
lines changed
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
# Coffee Vision Package
2+
3+
A ROS2 package providing computer vision capabilities for camera capture and face detection in the Coffee Buddy robot system.
4+
5+
## Overview
6+
7+
The `coffee_vision` package is a focused computer vision module that handles:
8+
- Camera capture and image streaming
9+
- Real-time face detection using OpenCV DNN
10+
- Face position tracking and data publishing
11+
12+
This package follows the single responsibility principle, focusing only on low-level computer vision tasks. Face recognition and memory management are handled by separate packages.
13+
14+
## Architecture
15+
16+
```
17+
┌─────────────────┐ /camera/image_raw ┌──────────────────────┐
18+
│ Camera Node ├────────────────────────►│ Face Detection Node │
19+
│ │ │ │
20+
├─────────────────┤ ├──────────────────────┤
21+
│ - Camera setup │ │ - OpenCV DNN │
22+
│ - Frame capture │ │ - Face detection │
23+
│ - Image publish │ │ - Position tracking │
24+
└─────────────────┘ └──────────────────────┘
25+
26+
27+
/vision/face_detection_data
28+
/vision/face_position
29+
```
30+
31+
## Nodes
32+
33+
### Camera Node (`camera_node`)
34+
35+
Handles camera initialization, frame capture, and image publishing.
36+
37+
**Publishers:**
38+
- `/camera/image_raw` (sensor_msgs/Image): Raw camera frames
39+
- `/camera/status` (std_msgs/String): Camera status
40+
41+
**Parameters:**
42+
- `camera_index` (int, default: 0): Camera device index
43+
- `frame_width` (int, default: 640): Frame width in pixels
44+
- `frame_height` (int, default: 480): Frame height in pixels
45+
- `target_fps` (int, default: 30): Target frames per second
46+
47+
### Face Detection Node (`face_detection_node`)
48+
49+
Subscribes to camera images and performs face detection using OpenCV DNN.
50+
51+
**Subscribers:**
52+
- `/camera/image_raw` (sensor_msgs/Image): Camera frames
53+
54+
**Publishers:**
55+
- `/vision/face_detection_data` (std_msgs/String): JSON-formatted face detection results
56+
- `/vision/face_position` (geometry_msgs/Vector3): Position of largest detected face
57+
- `/vision/face_detection_status` (std_msgs/String): Detection status
58+
59+
**Parameters:**
60+
- `confidence_threshold` (double, default: 0.5): Minimum confidence for face detection
61+
- `nms_threshold` (double, default: 0.4): Non-maximum suppression threshold
62+
- `enable_smoothing` (bool, default: true): Enable temporal smoothing of detections
63+
64+
## Installation
65+
66+
### Dependencies
67+
68+
The package requires the following dependencies:
69+
- OpenCV with DNN support
70+
- NumPy
71+
- Standard ROS2 packages (rclpy, sensor_msgs, etc.)
72+
73+
### Build Instructions
74+
75+
```bash
76+
# Navigate to your ROS2 workspace
77+
cd coffee_ws
78+
79+
# Build the package
80+
colcon build --packages-select coffee_vision
81+
82+
# Source the workspace
83+
source install/setup.bash
84+
```
85+
86+
## Usage
87+
88+
### Launch All Vision Nodes
89+
90+
```bash
91+
# Launch camera and face detection nodes together
92+
ros2 launch coffee_vision vision_nodes.launch.py
93+
94+
# Launch with custom parameters
95+
ros2 launch coffee_vision vision_nodes.launch.py camera_index:=1 confidence_threshold:=0.7
96+
```
97+
98+
### Run Individual Nodes
99+
100+
```bash
101+
# Camera node only
102+
ros2 run coffee_vision camera_node
103+
104+
# Face detection node only (requires camera feed)
105+
ros2 run coffee_vision face_detection_node
106+
```
107+
108+
### Monitor Topics
109+
110+
```bash
111+
# View camera feed
112+
ros2 topic echo /camera/image_raw
113+
114+
# Monitor face detection results
115+
ros2 topic echo /vision/face_detection_data
116+
117+
# Watch face positions
118+
ros2 topic echo /vision/face_position
119+
```
120+
121+
## Data Formats
122+
123+
### Face Detection Data
124+
125+
Published on `/vision/face_detection_data` as JSON:
126+
127+
```json
128+
{
129+
"timestamp": 1672531200,
130+
"faces": [
131+
{
132+
"x1": 100,
133+
"y1": 120,
134+
"x2": 200,
135+
"y2": 220,
136+
"center_x": 150,
137+
"center_y": 170,
138+
"confidence": 0.85
139+
}
140+
],
141+
"count": 1
142+
}
143+
```
144+
145+
### Face Position
146+
147+
Published on `/vision/face_position` as Vector3:
148+
- `x`: Center X coordinate of largest face
149+
- `y`: Center Y coordinate of largest face
150+
- `z`: Confidence score
151+
152+
## Configuration
153+
154+
### Camera Settings
155+
156+
The camera node automatically configures optimal settings but can be customized:
157+
158+
```bash
159+
ros2 run coffee_vision camera_node --ros-args \
160+
-p camera_index:=0 \
161+
-p frame_width:=1280 \
162+
-p frame_height:=720 \
163+
-p target_fps:=30
164+
```
165+
166+
### Face Detection Tuning
167+
168+
Adjust detection sensitivity and performance:
169+
170+
```bash
171+
ros2 run coffee_vision face_detection_node --ros-args \
172+
-p confidence_threshold:=0.7 \
173+
-p nms_threshold:=0.3 \
174+
-p enable_smoothing:=true
175+
```
176+
177+
## Models
178+
179+
The face detection node automatically downloads OpenCV's pre-trained face detection models:
180+
- `opencv_face_detector_uint8.pb`
181+
- `opencv_face_detector.pbtxt`
182+
183+
Models are stored in `coffee_vision/models/` directory.
184+
185+
## Performance
186+
187+
### GPU Acceleration
188+
189+
The face detection node automatically attempts to use CUDA acceleration if available, falling back to CPU processing otherwise.
190+
191+
### Optimization Tips
192+
193+
1. **Lower resolution** for better performance: Set smaller `frame_width` and `frame_height`
194+
2. **Adjust confidence threshold**: Higher values reduce false positives but may miss faces
195+
3. **Disable smoothing** for faster processing: Set `enable_smoothing:=false`
196+
197+
## Integration
198+
199+
This package is designed to integrate with other Coffee Buddy packages:
200+
201+
- **coffee_recognition**: Subscribes to face detection data for recognition tasks
202+
- **coffee_head_control**: Uses face positions for head tracking
203+
- **coffee_expressions**: Responds to face detection for emotional expressions
204+
205+
## Troubleshooting
206+
207+
### Camera Issues
208+
209+
```bash
210+
# List available cameras
211+
ls /dev/video*
212+
213+
# Test camera directly
214+
ros2 run coffee_vision camera_node --ros-args -p camera_index:=1
215+
```
216+
217+
### Detection Issues
218+
219+
```bash
220+
# Lower confidence threshold for more detections
221+
ros2 run coffee_vision face_detection_node --ros-args -p confidence_threshold:=0.3
222+
223+
# Check model download
224+
ls coffee_ws/src/coffee_vision/coffee_vision/models/
225+
```
226+
227+
## Development
228+
229+
### Adding New Detection Models
230+
231+
1. Place model files in `coffee_vision/models/`
232+
2. Update `initialize_face_detector()` in `face_detection_node.py`
233+
3. Test with various lighting conditions
234+
235+
### Extending Functionality
236+
237+
This package is designed to be minimal and focused. For additional computer vision features:
238+
- Create separate specialized packages
239+
- Use the same topic interfaces for compatibility
240+
- Follow the modular architecture pattern
241+
242+
## License
243+
244+
TODO: License declaration

coffee_ws/src/coffee_vision/coffee_vision/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)