@@ -41,7 +41,7 @@ Basic rectangle drawing:
4141.. code-block :: python
4242
4343 # Single rectangle
44- bbox = (100 , 100 , 200 , 200 )
44+ bbox = (100 , 100 , 200 , 200 ) # (x1, y1, x2, y2) format
4545 image = bbv.draw_rectangle(image, bbox)
4646
4747 # Multiple rectangles
@@ -136,4 +136,96 @@ All functions support customization of colors and styles:
136136 # Display the result
137137 cv2.imshow(' Image with bounding boxes' , image)
138138 cv2.waitKey(0 )
139- cv2.destroyAllWindows()
139+ cv2.destroyAllWindows()
140+
141+ Common Use Cases
142+ --------------
143+
144+ Object Detection Visualization
145+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
146+
147+ .. code-block :: python
148+
149+ import bbox_visualizer as bbv
150+ import cv2
151+ import numpy as np
152+
153+ # Simulate object detection results
154+ detections = [
155+ {" bbox" : (50 , 50 , 150 , 150 ), " label" : " Person" , " confidence" : 0.95 },
156+ {" bbox" : (200 , 100 , 300 , 200 ), " label" : " Car" , " confidence" : 0.87 },
157+ {" bbox" : (350 , 150 , 450 , 250 ), " label" : " Dog" , " confidence" : 0.92 }
158+ ]
159+
160+ # Load image
161+ image = cv2.imread(' detection_image.jpg' )
162+
163+ # Visualize each detection
164+ for det in detections:
165+ bbox = det[" bbox" ]
166+ label = f " { det[' label' ]} ( { det[' confidence' ]:.2f } ) "
167+
168+ # Draw rectangle and label
169+ image = bbv.draw_rectangle(image, bbox, bbox_color = (0 , 255 , 0 ))
170+ image = bbv.add_label(image, label, bbox)
171+
172+ Multiple Object Classes
173+ ~~~~~~~~~~~~~~~~~~~~~~
174+
175+ .. code-block :: python
176+
177+ # Define color scheme for different classes
178+ class_colors = {
179+ " person" : (0 , 255 , 0 ), # Green
180+ " car" : (255 , 0 , 0 ), # Blue
181+ " dog" : (0 , 0 , 255 ), # Red
182+ " cat" : (255 , 255 , 0 ) # Cyan
183+ }
184+
185+ # Process detections with class-specific colors
186+ for det in detections:
187+ bbox = det[" bbox" ]
188+ label = det[" label" ]
189+ color = class_colors.get(label.lower(), (128 , 128 , 128 ))
190+
191+ image = bbv.draw_rectangle(image, bbox, bbox_color = color)
192+ image = bbv.add_label(image, label, bbox)
193+
194+ Troubleshooting
195+ -------------
196+
197+ Common Issues
198+ ~~~~~~~~~~~~
199+
200+ **Bounding box format errors **
201+ Make sure your bounding boxes are in (x1, y1, x2, y2) format where:
202+ - x1, y1: top-left corner coordinates
203+ - x2, y2: bottom-right corner coordinates
204+
205+ **Color format issues **
206+ OpenCV uses BGR color format, not RGB. For example:
207+ - Red: (0, 0, 255) in BGR
208+ - Green: (0, 255, 0) in BGR
209+ - Blue: (255, 0, 0) in BGR
210+
211+ **Image not displaying **
212+ Ensure you have a display environment or use cv2.imwrite() to save the image:
213+
214+ .. code-block :: python
215+
216+ cv2.imwrite(' output.jpg' , image)
217+
218+ Performance Tips
219+ ~~~~~~~~~~~~~~
220+
221+ - For multiple objects, use the batch functions (e.g., `draw_multiple_rectangles `) instead of loops
222+ - Pre-allocate image arrays when possible
223+ - Use appropriate image formats (uint8 for most cases)
224+ - Consider downsampling large images for faster processing
225+
226+ Getting Help
227+ -----------
228+
229+ - Check the `examples/ ` directory for complete working examples
230+ - Review the API documentation for detailed parameter descriptions
231+ - Open an issue on GitHub for bugs or feature requests
0 commit comments