This repository contains a comprehensive implementation of Oriented Bounding Box detection using multiple approaches. The implementation includes various methods for detecting rotated objects in images and provides visualization tools.
- Multiple detection methods:
- Contour-based detection
- Connected Components analysis
- MSER (Maximally Stable Extremal Regions)
- Image preprocessing with CLAHE enhancement
- Configurable parameters for detection
- Visualization tools with angle and center point display
- Result export to JSON format
- Type hints and comprehensive documentation
Install the required packages using:
pip install -r requirements.txtfrom enhanced_obb_detection import EnhancedOBBDetector
# Create detector instance
detector = EnhancedOBBDetector()
# Load image
image = cv2.imread("your_image.jpg")
# Detect objects (choose method: 'contour', 'connected_components', or 'mser')
detections = detector.detect_objects(image, method='contour')
# Visualize results
result = detector.visualize_detections(image, detections)
# Display
cv2.imshow("Detection Results", result)
cv2.waitKey(0)
# Save results
detector.save_results(detections, "detections.json")You can customize the detector's parameters:
config = {
'min_area': 150,
'max_area': 3000,
'min_aspect': 1.5,
'max_aspect': 4.0,
'canny_low': 30,
'canny_high': 200,
'clahe_clip_limit': 3.0,
'clahe_grid_size': (8, 8),
'morph_kernel_size': (3, 3)
}
detector = EnhancedOBBDetector(config)-
Contour-based Detection
- Uses edge detection and contour analysis
- Best for objects with clear boundaries
- Configurable edge detection parameters
-
Connected Components
- Uses region labeling and properties
- Good for separated objects
- Supports different connectivity options
-
MSER Detection
- Uses Maximally Stable Extremal Regions
- Effective for text and blob detection
- Configurable region parameters
The detection results are returned as a list of dictionaries, each containing:
box: Corner points of the oriented bounding boxcenter: Center coordinateswidth: Box widthheight: Box heightangle: Rotation angle in degreesarea: Area of the detected regionconfidence: Detection confidence score
Run the example script:
python enhanced_obb_detection.pyThis will:
- Load a sample image
- Apply all three detection methods
- Display the results side by side
- Save the detections to a JSON file
This project is licensed under the MIT License - see the LICENSE file for details.
Contributors Name: Dhruv Patel and Devanshi Rathod