This repository contains the computer vision pipeline used for crab detection and counting in the MATE ROV context. The runtime path in main.py uses a YOLO-based detector, receives camera frames from a ROS web video stream, and publishes both crab count and annotated detection frames through ROS Bridge.
Files:
main.pyYOLO_Detection.pyvideo_stream_web.pyros_publisher.py
Pipeline summary:
VideoStreamopens the HTTP stream from a ROS web endpoint.CrabDetectorloads the trained YOLO model frombest.pt.- Inference runs per frame with confidence threshold
0.6. - Bounding boxes are drawn using Ultralytics plotting utilities.
- Only detections with class label
European Green Crabare counted. - Annotated frame and crab count are published to ROS Bridge.
Design intent:
- Use a trained detector to improve robustness over illumination and background variation.
- Keep the count logic class-specific to avoid counting non-target detections.
Files:
color_based_detection/crab_detection.pycolor_based_detection/crab_detection_with_video.py
Pipeline summary:
- Convert frame from BGR to HSV.
- Segment crab-like pixels using fixed HSV thresholds.
- Clean masks with morphological opening and closing.
- Extract contours and filter small regions by area.
- Track objects across frames with centroid-distance tracking.
- Estimate crab appearance type (Light/Dark) from region intensity.
Design intent:
- Provide a lightweight fallback or baseline without model inference.
- Demonstrate classical vision + tracking methods for controlled scenes.
Published:
/crab_countasstd_msgs/Int32/AI_Detectionassensor_msgs/Image
Consumed:
- HTTP stream endpoint on port
8080using topic query/cam_front/image_raw
The image frame is published as standard sensor_msgs/Image payload where data contains a raw uint8[] array.
This aligns with standard ROS image semantics and improves interoperability with typical ROS consumers.
Install dependencies in your active Python environment:
pip install ultralytics opencv-python roslibpy numpy matplotlibNotes:
matplotlibis used by experimental scripts incolor_based_detection.- Ensure ROS Bridge is reachable from the machine running this code.
Run from the project root:
python main.py- The script connects to:
- Video stream:
http://192.168.1.100:8080/stream?topic=/cam_front/image_raw - ROS Bridge:
192.168.1.100:9090
- Video stream:
- A live window named
AI Detectionis shown. - Press
qto stop.
best.pt must exist in the project root directory for the current runtime configuration.