Skip to content

Commit ac23b67

Browse files
committed
docs: enhance documentation with quick start guide, usage examples, and troubleshooting tips
1 parent 72bd5c6 commit ac23b67

File tree

2 files changed

+124
-2
lines changed

2 files changed

+124
-2
lines changed

docs/index.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@ The package is organized into several modules for different visualization needs:
88
* **Label Drawing**: Functions for adding text labels to boxes
99
* **Special Labels**: T-shaped and flag-style label visualizations
1010

11+
Quick Start
12+
----------
13+
14+
Get started with bbox-visualizer in just a few lines:
15+
16+
.. code-block:: python
17+
18+
import bbox_visualizer as bbv
19+
import cv2
20+
import numpy as np
21+
22+
# Create a sample image
23+
image = np.ones((400, 600, 3), dtype=np.uint8) * 255
24+
25+
# Draw a bounding box with label
26+
bbox = (100, 100, 300, 200)
27+
image = bbv.draw_rectangle(image, bbox, bbox_color=(0, 255, 0))
28+
image = bbv.add_label(image, "Object", bbox)
29+
30+
# Display the result
31+
cv2.imshow('Result', image)
32+
cv2.waitKey(0)
33+
1134
.. toctree::
1235
:maxdepth: 2
1336
:caption: Contents:
@@ -16,6 +39,13 @@ The package is organized into several modules for different visualization needs:
1639
usage
1740
api
1841

42+
Examples
43+
--------
44+
45+
Check out the Jupyter notebook examples in the `examples/` directory:
46+
* `single_object_example.ipynb` - Basic usage with single objects
47+
* `multiple_objects_example.ipynb` - Working with multiple bounding boxes
48+
1949
Indices and tables
2050
==================
2151
* :ref:`genindex`

docs/usage.rst

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)