A modular object detection system using OpenCV and Python that identifies objects in camera feed and determines their colors.
- Real-time object detection from camera feed
- Color identification for detected objects
- Multiple object detection capability
- Modular architecture following SOLID principles
- Easy to extend and maintain
The system follows SOLID principles with a modular design:
-
Camera Interface (
camera/)camera_interface.py: Abstract camera interfaceopencv_camera.py: OpenCV camera implementation
-
Object Detection (
detection/)detector_interface.py: Abstract detector interfacecontour_detector.py: Contour-based object detectionobject_tracker.py: Object tracking and management
-
Color Analysis (
color/)color_analyzer_interface.py: Abstract color analyzer interfacehsv_color_analyzer.py: HSV-based color analysiscolor_classifier.py: Color classification logic
-
Image Processing (
processing/)image_processor.py: Image preprocessing utilitiesfilters.py: Various image filters
-
Main Application (
main.py)- Entry point that orchestrates all components
# Install dependencies
poetry install
# Run the application
poetry run python main.py- Run the application:
poetry run python main.py - Point your camera at objects
- The system will detect objects and display their colors
- Press 'q' to quit
The system uses configuration files to adjust detection parameters:
config/detection_config.yaml: Object detection parametersconfig/color_config.yaml: Color classification settings
Thanks to the modular architecture, you can easily:
- Add new detection algorithms by implementing
DetectorInterface - Add new color analysis methods by implementing
ColorAnalyzerInterface - Add new camera sources by implementing
CameraInterface - Modify processing pipelines in the
processingmodule
- Single Responsibility: Each class has one clear purpose
- Open/Closed: Easy to extend with new implementations
- Liskov Substitution: Interfaces ensure substitutability
- Interface Segregation: Small, focused interfaces
- Dependency Inversion: Depends on abstractions, not concretions