### Install bbox-visualizer from Source with uv Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/docs/installation.md Install bbox-visualizer from its source code using `uv` for an editable installation. ```console uv pip install -e . ``` -------------------------------- ### Set up development environment Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/CONTRIBUTING.md Install uv, create a virtual environment, and install development dependencies. ```bash pip install uv cd bbox_visualizer uv venv uv pip install -e ".[dev]" ``` -------------------------------- ### Install bbox-visualizer from Source with pip Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/docs/installation.md Install bbox-visualizer from its source code using `pip` for an editable installation. ```console pip install -e . ``` -------------------------------- ### Install bbox-visualizer Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/README.md Install the package using pip. This is the primary method for adding the library to your project. ```bash pip install bbox-visualizer ``` -------------------------------- ### Install bbox-visualizer with uv Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/docs/installation.md Install the bbox-visualizer package using the `uv` package manager. ```console uv pip install bbox-visualizer ``` -------------------------------- ### Install bbox-visualizer from Source with uv (Development) Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/docs/installation.md Install bbox-visualizer from its source code with development dependencies using `uv`. ```console uv pip install -e ".[dev]" ``` -------------------------------- ### Install uv Package Manager Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/docs/installation.md Install the `uv` package manager, a fast Python package installer and resolver. ```console pip install uv ``` -------------------------------- ### Install bbox-visualizer from Source with pip (Development) Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/docs/installation.md Install bbox-visualizer from its source code with development dependencies using `pip`. ```console pip install -e ".[dev]" ``` -------------------------------- ### Clone the repository Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/CONTRIBUTING.md Clone your forked repository locally to start development. ```bash git clone git@github.com:your_name_here/bbox_visualizer.git ``` -------------------------------- ### Object Detection Visualization Example Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/docs/usage.md Visualize object detection results by drawing bounding boxes and labels with confidence scores on an image. This example simulates detection results. ```python import bbox_visualizer as bbv import cv2 import numpy as np # Simulate object detection results detections = [ {"bbox": (50, 50, 150, 150), "label": "Person", "confidence": 0.95}, {"bbox": (200, 100, 300, 200), "label": "Car", "confidence": 0.87}, {"bbox": (350, 150, 450, 250), "label": "Dog", "confidence": 0.92} ] # Load image image = cv2.imread('detection_image.jpg') # Visualize each detection for det in detections: bbox = det["bbox"] label = f"{det['label']} ({det['confidence']:.2f})" # Draw box and label image = bbv.draw_box(image, bbox, bbox_color=(0, 255, 0)) image = bbv.add_label(image, label, bbox) ``` -------------------------------- ### Full Object Detection Pipeline Example Source: https://context7.com/shoumikchow/bbox-visualizer/llms.txt Demonstrates a full object detection pipeline using simulated detector output. Iterates through detections, assigns per-class colors, and draws boxes with confidence labels using `draw_box` and `add_label`. ```python import bbox_visualizer as bbv import cv2 # Simulated detector output: (bbox, class_name, confidence) detections = [ ([45, 60, 180, 230], "person", 0.97), ([210, 85, 370, 260], "car", 0.89), ([390, 50, 540, 210], "dog", 0.93), ] # Per-class BGR colors class_colors = { "person": (0, 255, 0), # Green "car": (255, 0, 0), # Blue "dog": (0, 0, 255), # Red } image = cv2.imread("scene.jpg") for bbox, cls, conf in detections: color = class_colors.get(cls, (200, 200, 200)) label = f"{cls} {conf:.2f}" image = bbv.draw_box(image, bbox, bbox_color=color, thickness=2) image = bbv.add_label(image, label, bbox, text_bg_color=color, text_color=(0, 0, 0)) cv2.imwrite("annotated_scene.jpg", image) # => Saves annotated image with colored boxes and confidence labels ``` -------------------------------- ### Basic bbox-visualizer Usage Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/docs/usage.md Import the library and use its functions to draw bounding boxes and add labels to an image. Ensure you have OpenCV and NumPy installed. ```python import bbox_visualizer as bbv import cv2 import numpy as np # Load an image image = cv2.imread('image.jpg') # Draw a bounding box bbox = (100, 100, 200, 200) # (x1, y1, x2, y2) format image = bbv.draw_box(image, bbox) # Add a label image = bbv.add_label(image, "Object", bbox) ``` -------------------------------- ### Create feature branch from dev Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/CONTRIBUTING.md Start feature development by creating a new branch from the 'dev' branch and pulling the latest changes. ```bash git checkout dev git pull origin dev git checkout -b name-of-your-bugfix-or-feature ``` -------------------------------- ### Import necessary libraries Source: https://context7.com/shoumikchow/bbox-visualizer/llms.txt Import bbox_visualizer and cv2 for image manipulation. ```python import bbox_visualizer as bbv import cv2 ``` -------------------------------- ### Import bbox-visualizer Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/README.md Import the library into your Python script. This is a prerequisite for using any of its functions. ```python import bbox_visualizer as bbv ``` -------------------------------- ### Format and lint code with ruff Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/CONTRIBUTING.md Use ruff to format code and run linting checks. Auto-fix issues where possible. ```bash # Format with ruff uv run ruff format . # Run linting checks with ruff uv run ruff check . # Auto-fix ruff issues where possible uv run ruff check --fix . # Run tests uv run pytest ``` -------------------------------- ### Clone bbox-visualizer Repository Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/docs/installation.md Clone the bbox-visualizer source code from the GitHub repository. ```console git clone git://github.com/shoumikchow/bbox-visualizer ``` -------------------------------- ### Load Image and Annotations Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/examples/multiple_objects_example.ipynb Loads an image and its corresponding annotations from JSON. Converts the image from BGR to RGB format. ```python import json import cv2 import matplotlib.pyplot as plt import bbox_visualizer as bbv img = cv2.imread("../images/source_multiple.jpg") annotation = json.load(open("../images/source_multiple.json")) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) ``` -------------------------------- ### Prepare Bounding Box Coordinates Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/examples/single_object_example.ipynb Unpacks the bounding box points into individual variables (xmin, ymin, xmax, ymax) and prints them. This step prepares the coordinates for use with the bbox-visualizer functions. ```python (xmin, ymin), (xmax, ymax) = points print((xmin, ymin), (xmax, ymax)) ``` -------------------------------- ### Troubleshooting: Saving Image Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/docs/usage.md If the image is not displaying, use `cv2.imwrite()` to save the output image to a file. This is useful in environments without a display server. ```python cv2.imwrite('output.jpg', image) ``` -------------------------------- ### Create a feature branch Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/CONTRIBUTING.md Create a new branch for local development, specifying the type of task. ```bash git checkout -b task/what-you-are-doing ``` -------------------------------- ### Prepare Bounding Boxes and Labels Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/examples/multiple_objects_example.ipynb Extracts labels and bounding box coordinates from the annotation data. Bounding boxes are formatted as [xmin, ymin, xmax, ymax]. ```python labels = [] bboxes = [] for shape in annotation["shapes"]: labels.append(shape["label"]) mins = shape["points"][0] maxs = shape["points"][1] bboxes.append(mins + maxs) ``` -------------------------------- ### Draw Bounding Box and Add Label Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/docs/index.md This snippet shows how to draw a basic bounding box and add a text label to it on a sample image using bbox-visualizer and OpenCV. ```python import bbox_visualizer as bbv import cv2 import numpy as np # Create a sample image image = np.ones((400, 600, 3), dtype=np.uint8) * 255 # Draw a bounding box with labelbox = (100, 100, 300, 200) image = bbv.draw_box(image, bbox, bbox_color=(0, 255, 0)) image = bbv.add_label(image, "Object", bbox) # Display the result cv2.imshow('Result', image) cv2.waitKey(0) ``` -------------------------------- ### Commit and push changes Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/CONTRIBUTING.md Stage, commit, and push your changes to your feature branch on GitHub. ```bash git add . git commit -m "Your detailed description of your changes." git push origin task/what-you-are-doing ``` -------------------------------- ### Display Image with Flags and Labels Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/examples/multiple_objects_example.ipynb Displays the image with flags and labels for multiple bounding boxes using matplotlib. ```python plt.imshow(img_with_flags); ``` -------------------------------- ### Drawing a bounding box with an opaque overlay and label inside Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/README.md Draws a bounding box with an opaque background and places the label inside. This ensures the label is clearly visible even on busy image backgrounds. ```APIDOC ## draw_box with opaque overlay and add_label (label inside, no background draw) ### Description Draws a bounding box with an opaque background and places the label inside. This ensures the label is clearly visible even on busy image backgrounds. ### Method ```python img = bbv.draw_box(image, bbox, is_opaque=True) img = bbv.add_label(img, label, bbox, draw_bg=False, top=False) ``` ### Parameters - `image`: The input image. - `bbox`: A tuple representing the bounding box in the format (xmin, ymin, xmax, ymax). - `is_opaque` (bool): If True, the bounding box will have an opaque background. Defaults to False. - `label`: The text label to be added. - `draw_bg` (bool): If False, the background for the label will not be drawn. Defaults to True. - `top` (bool): If False, the label is positioned inside the bounding box. Defaults to False. ``` -------------------------------- ### Load Image and Annotation Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/examples/single_object_example.ipynb Loads an image using OpenCV and an annotation file in JSON format. Converts the image from BGR to RGB color space for compatibility with matplotlib. ```python import json import cv2 import matplotlib.pyplot as plt import bbox_visualizer as bbv img = cv2.imread("../images/source_single.jpg") annotation = json.load(open("../images/source_single.json")) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) ``` -------------------------------- ### Draw Multiple Bounding Boxes and Labels Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/README.md Draws multiple bounding boxes and their corresponding labels on an image. The `bboxes` and `labels` arguments expect lists. ```python img = bbv.draw_multiple_boxes(img, bboxes) img = bbv.add_multiple_labels(img, labels, bboxes) ``` -------------------------------- ### Draw Multiple Flags with Labels Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/README.md Draws multiple bounding boxes, each with a flag-style label. Requires lists of labels and bounding boxes. ```python img = bbv.draw_multiple_flags_with_labels(img, labels, bboxes) ``` -------------------------------- ### Draw Bounding Box with Label Inside Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/README.md Draws a bounding box and places the label inside the box. The `top=False` argument positions the label within the box. ```python img = bbv.draw_box(img, bbox) img = bbv.add_label(img, label, bbox, top=False) ``` -------------------------------- ### Display Image with Flag Label Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/examples/single_object_example.ipynb Displays the image with the flag and label using matplotlib.pyplot. ```python plt.imshow(img_flag); ``` -------------------------------- ### Draw Bounding Box with Label on Top Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/README.md Draws a bounding box and places the label above the box. Ensure the image object and bbox are correctly formatted. ```python img = bbv.draw_box(img, bbox) img = bbv.add_label(img, label, bbox, top=True) ``` -------------------------------- ### Adding Simple and Multiple Labels Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/docs/usage.md Add text labels to bounding boxes. Labels can be placed above or inside the box. Supports adding multiple labels for multiple boxes. ```python # Add label above the box bbox = (100, 100, 200, 200) label = "Object" image = bbv.add_label(image, label, bbox) # Add label inside the box image = bbv.add_label(image, label, bbox, top=False) # Multiple labels bboxes = [(100, 100, 200, 200), (300, 300, 400, 400)] labels = ["Object 1", "Object 2"] image = bbv.add_multiple_labels(image, labels, bboxes) ``` -------------------------------- ### Draw Multiple Boxes Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/examples/multiple_objects_example.ipynb Draws multiple bounding boxes on the image using the prepared bounding box data. Prints the type of the resulting image object. ```python img_with_boxes = bbv.draw_multiple_boxes(img, bboxes) print(type(img_with_boxes)) ``` -------------------------------- ### Draw Bounding Box on Image Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/examples/single_object_example.ipynb Uses the `draw_box` function from the bbox-visualizer library to draw a bounding box on the image. Prints the type of the returned image object. ```python img_with_box = bbv.draw_box(img, bbox) print(type(img_with_box)) ``` -------------------------------- ### Display Image with Boxes Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/examples/multiple_objects_example.ipynb Displays the image with the drawn bounding boxes using matplotlib. ```python plt.imshow(img_with_boxes); ``` -------------------------------- ### Draw Bounding Box with Label Inside (T-style) Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/README.md Draws a bounding box and places the label inside the box, styled as a 'T'. This is useful for compact labeling. ```python img = bbv.draw_box(img, bbox) img = bbv.add_T_label(img, label, bbox) ``` -------------------------------- ### Display Image with T-Format Labels Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/examples/multiple_objects_example.ipynb Displays the image with bounding boxes and 'T' format labels using matplotlib. ```python plt.imshow(img_with_T_labels); ``` -------------------------------- ### Display Image with Label Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/examples/single_object_example.ipynb Displays the image with the added label using matplotlib.pyplot. ```python plt.imshow(img_label); ``` -------------------------------- ### Multiple Object Classes with Custom Colors Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/docs/usage.md Visualize detections from multiple object classes by assigning a unique color to each class. This helps differentiate between various object types. ```python # Define color scheme for different classes class_colors = { "person": (0, 255, 0), # Green "car": (255, 0, 0), # Blue "dog": (0, 0, 255), # Red "cat": (255, 255, 0) # Cyan } # Process detections with class-specific colors for det in detections: bbox = det["bbox"] label = det["label"] color = class_colors.get(label.lower(), (128, 128, 128)) image = bbv.draw_box(image, bbox, bbox_color=color) image = bbv.add_label(image, label, bbox) ``` -------------------------------- ### Add labels to multiple bounding boxes Source: https://context7.com/shoumikchow/bbox-visualizer/llms.txt Apply `add_label` to multiple (label, bbox) pairs using `add_multiple_labels`. Ensures lists have matching lengths and raises `ValueError` if either list is empty. ```python import bbox_visualizer as bbv import cv2 image = cv2.imread("image.jpg") bboxes = [[50, 50, 150, 150], [200, 100, 350, 280], [400, 60, 500, 200]] labels = ["Person", "Car", "Dog"] # Labels above each box image = bbv.draw_multiple_boxes(image, bboxes, bbox_color=(0, 255, 0)) image = bbv.add_multiple_labels(image, labels, bboxes, top=True) # Labels inside boxes with custom colors image = bbv.add_multiple_labels( image, labels, bboxes, top=False, text_bg_color=(50, 50, 50), text_color=(255, 255, 255), ) cv2.imwrite("output.jpg", image) ``` -------------------------------- ### Draw Opaque Bounding Box with Label Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/README.md Draws a bounding box with an opaque background and places the label inside. Use `draw_bg=False` in `add_label` to prevent drawing the background again if `draw_box` already handled it. ```python img = bbv.draw_box(image, bbox, is_opaque=True) img = bbv.add_label(img, label, bbox, draw_bg=False, top=False) ``` -------------------------------- ### Extract Bounding Box Points and Label Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/examples/single_object_example.ipynb Extracts the bounding box coordinates and the corresponding label from the loaded annotation data. Prints the extracted points and label along with their types. ```python points = annotation["shapes"][0]["points"] label = annotation["shapes"][0]["label"] print(f"Points box: {points}, {type(points)}") print(f"Label box: {label}, {type(label)}") ``` -------------------------------- ### Drawing multiple bounding boxes with labels Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/README.md Draws multiple bounding boxes and their corresponding labels on an image. This is useful for annotating several objects in a single image. ```APIDOC ## draw_multiple_boxes and add_multiple_labels ### Description Draws multiple bounding boxes and their corresponding labels on an image. This is useful for annotating several objects in a single image. ### Method ```python img = bbv.draw_multiple_boxes(img, bboxes) img = bbv.add_multiple_labels(img, labels, bboxes) ``` ### Parameters - `img`: The input image. - `bboxes`: A list of tuples, where each tuple represents a bounding box in the format (xmin, ymin, xmax, ymax). - `labels`: A list of strings, where each string is a label corresponding to a bounding box. ``` -------------------------------- ### Draw Multiple Flags with Labels Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/examples/multiple_objects_example.ipynb Draws flags with labels directly onto the image for multiple bounding boxes. Prints the type of the resulting image object. ```python img_with_flags = bbv.draw_multiple_flags_with_labels(img, labels, bboxes) print(type(img_with_flags)) ``` -------------------------------- ### Add Multiple T-Format Labels Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/examples/multiple_objects_example.ipynb Adds labels in a 'T' format to the bounding boxes on the image. Prints the type of the resulting image object. ```python img_with_T_labels = bbv.add_multiple_T_labels(img_with_boxes_2, labels, bboxes) print(type(img_with_T_labels)) ``` -------------------------------- ### Customizing Colors and Styles Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/docs/usage.md Customize the appearance of bounding boxes and labels by specifying custom colors for boxes, text, and background. This applies to various drawing functions. ```python # Custom colors bbox_color = (0, 255, 0) # Green in BGR text_color = (0, 0, 0) # Black bg_color = (255, 255, 255) # White # Draw box with custom color image = bbv.draw_box(image, bbox, bbox_color=bbox_color) # Add label with custom colors image = bbv.add_label( image, label, bbox, text_color=text_color, text_bg_color=bg_color ) # T-label with custom style image = bbv.add_T_label( image, label, bbox, text_color=text_color, text_bg_color=bg_color ) # Flag with custom colors image = bbv.draw_flag_with_label( image, label, bbox, line_color=bbox_color, text_color=text_color, text_bg_color=bg_color ) # Display the result cv2.imshow('Image with bounding boxes', image) cv2.waitKey(0) cv2.destroyAllWindows() ``` -------------------------------- ### Display Image with Bounding Box Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/examples/single_object_example.ipynb Displays the image with the bounding box drawn on it using matplotlib.pyplot. This is typically used after drawing operations to visualize the result. ```python plt.imshow(img_with_box); ``` -------------------------------- ### Add Multiple Labels to Boxes Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/examples/multiple_objects_example.ipynb Adds multiple labels to the existing bounding boxes on the image. Creates a copy of the image before adding labels. Prints the type of the resulting image object. ```python img_with_boxes_2 = img_with_boxes.copy() img_with_boxes = bbv.add_multiple_labels(img_with_boxes, labels, bboxes) print(type(img_with_boxes)) ``` -------------------------------- ### Rectangle Drawing Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/docs/api.md Functions for drawing rectangles and bounding boxes. ```APIDOC ## Rectangle Drawing ### Description Functions for drawing rectangles and bounding boxes. ### Methods - `bbox_visualizer.draw_box` - `bbox_visualizer.draw_multiple_boxes` - `bbox_visualizer.draw_rectangle` - `bbox_visualizer.draw_multiple_rectangles` ``` -------------------------------- ### Drawing a single bounding box with a label inside Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/README.md Draws a bounding box around an object and adds a label positioned inside the box. This is suitable when space is limited or for a more compact visualization. ```APIDOC ## draw_box and add_label (label inside) ### Description Draws a bounding box around an object and adds a label positioned inside the box. This is suitable when space is limited or for a more compact visualization. ### Method ```python img = bbv.draw_box(img, bbox) img = bbv.add_label(img, label, bbox, top=False) ``` ### Parameters - `img`: The input image. - `bbox`: A tuple representing the bounding box in the format (xmin, ymin, xmax, ymax). - `label`: The text label to be added. - `top` (bool): If False, the label is positioned inside the bounding box. Defaults to False. ``` -------------------------------- ### Draw multiple bounding boxes efficiently Source: https://context7.com/shoumikchow/bbox-visualizer/llms.txt Use `draw_multiple_boxes` for batched drawing of boxes, which is more efficient than individual calls. Raises `ValueError` if the list of boxes is empty. ```python import bbox_visualizer as bbv import cv2 image = cv2.imread("image.jpg") bboxes = [ [50, 50, 150, 150], [200, 100, 350, 280], [400, 60, 500, 200], ] # All boxes in one call (same color) image = bbv.draw_multiple_boxes(image, bboxes, bbox_color=(255, 100, 0), thickness=2) # Opaque filled boxes image = bbv.draw_multiple_boxes(image, bboxes, is_opaque=True, alpha=0.4) cv2.imwrite("output.jpg", image) ``` -------------------------------- ### Draw a single bounding box on an image Source: https://context7.com/shoumikchow/bbox-visualizer/llms.txt Use `draw_box` to add a rectangle outline or a semi-transparent overlay to an image. Customize color, thickness, and opacity. ```python import bbox_visualizer as bbv import cv2 image = cv2.imread("image.jpg") bbox = [100, 80, 300, 250] # [xmin, ymin, xmax, ymax] # Outline box (default white, thickness 3) image = bbv.draw_box(image, bbox) # Custom color and thickness image = bbv.draw_box(image, bbox, bbox_color=(0, 255, 0), thickness=2) # Semi-transparent filled box (50% opacity) image = bbv.draw_box(image, bbox, is_opaque=True, alpha=0.5, bbox_color=(0, 200, 0)) cv2.imwrite("output.jpg", image) ``` -------------------------------- ### Draw Flag Labels for Multiple Boxes Source: https://context7.com/shoumikchow/bbox-visualizer/llms.txt Applies `draw_flag_with_label` to each (label, bbox) pair. Raises `ValueError` if lists are empty or mismatched. Configurable line, text background, and text colors. ```python import bbox_visualizer as bbv import cv2 image = cv2.imread("image.jpg") bboxes = [[30, 80, 160, 240], [200, 70, 360, 260], [400, 90, 560, 270]] labels = ["Cat", "Dog", "Bird"] image = bbv.draw_multiple_flags_with_labels( image, labels, bboxes, line_color=(200, 200, 0), text_bg_color=(200, 200, 0), text_color=(0, 0, 0), ) cv2.imwrite("output.jpg", image) ``` -------------------------------- ### Label Drawing Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/docs/api.md Functions for adding labels to bounding boxes. ```APIDOC ## Label Drawing ### Description Functions for adding labels to bounding boxes. ### Methods - `bbox_visualizer.add_label` - `bbox_visualizer.add_multiple_labels` ``` -------------------------------- ### Context Manager for Warning Suppression Source: https://context7.com/shoumikchow/bbox-visualizer/llms.txt Temporarily suppresses warnings within a `with` block, then restores the previous state automatically. Useful for localized suppression without affecting global settings. ```python import bbox_visualizer as bbv import cv2 image = cv2.imread("image.jpg") bboxes_near_top = [[5, 5, 120, 60], [150, 2, 280, 55]] labels = ["Label A", "Label B"] # Suppress only for this block; state is restored after with bbv.warnings_suppressed(): for bbox, label in zip(bboxes_near_top, labels): image = bbv.draw_flag_with_label(image, label, bbox) cv2.imwrite("output.jpg", image) ``` -------------------------------- ### Drawing a single bounding box with a label on top Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/README.md Draws a bounding box around an object and adds a label positioned above the box. This is useful for clearly identifying objects. ```APIDOC ## draw_box and add_label (label on top) ### Description Draws a bounding box around an object and adds a label positioned above the box. This is useful for clearly identifying objects. ### Method ```python img = bbv.draw_box(img, bbox) img = bbv.add_label(img, label, bbox, top=True) ``` ### Parameters - `img`: The input image. - `bbox`: A tuple representing the bounding box in the format (xmin, ymin, xmax, ymax). - `label`: The text label to be added. - `top` (bool): If True, the label is positioned above the bounding box. Defaults to True. ``` -------------------------------- ### Reconcile dev and master branches Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/CONTRIBUTING.md After merging a feature to 'dev', reconcile 'dev' with 'master' by pulling from 'master' and pushing to 'dev'. ```bash git checkout dev git pull origin master git push origin dev ``` -------------------------------- ### Control Warning Messages Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/docs/usage.md Manage warning messages from the library. You can suppress all warnings, enable them, or use a context manager for temporary suppression. ```python # Suppress all warnings bbv.suppress_warnings(True) # Enable warnings bbv.suppress_warnings(False) # Temporarily suppress warnings using context manager with bbv.warnings_suppressed(): # Warnings will be suppressed in this block image = bbv.draw_flag_with_label(image, "Object", bbox) ``` -------------------------------- ### add_label Source: https://context7.com/shoumikchow/bbox-visualizer/llms.txt Adds a text label with an optional background rectangle to a bounding box on an image. The label is placed above the box by default, but can be placed inside if space is limited. ```APIDOC ## add_label ### Description Places a text label with an optional background rectangle either above the bounding box (default) or inside it. Automatically falls back to placing the label inside if there is not enough vertical space above the box. ### Parameters - **image** (numpy.ndarray) - The input image. - **label** (str) - The text label to add. - **bbox** (list) - A list containing the bounding box coordinates in [xmin, ymin, xmax, ymax] format. - **top** (bool, optional) - If True, attempts to place the label above the bounding box. Defaults to True. - **draw_bg** (bool, optional) - If True, draws a background rectangle for the label. Defaults to True. - **size** (float, optional) - The font size for the label. Defaults to 0.5. - **thickness** (int, optional) - The thickness of the label's text and background border. Defaults to 1. - **text_color** (tuple, optional) - The color of the text in BGR format. Defaults to (0, 0, 0) (black). - **text_bg_color** (tuple, optional) - The color of the background rectangle in BGR format. Defaults to (255, 255, 255) (white). ### Request Example ```python import bbox_visualizer as bbv import cv2 image = cv2.imread("image.jpg") bbox = [100, 80, 300, 250] # Label above the box (default) image = bbv.draw_box(image, bbox, bbox_color=(0, 255, 0)) image = bbv.add_label(image, "Person 0.95", bbox, top=True) # Label inside the box, no background image = bbv.add_label(image, "Car", bbox, top=False, draw_bg=False, text_color=(255, 255, 255)) # Custom font size and colors image = bbv.add_label( image, "Dog", bbox, size=0.7, thickness=1, text_bg_color=(0, 0, 255), # Red background (BGR) text_color=(255, 255, 255), # White text top=True, ) cv2.imwrite("output.jpg", image) ``` ### Response - **image** (numpy.ndarray) - The image with the label added. ``` -------------------------------- ### Drawing a flag with a label Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/README.md Creates a visual representation of a flag originating from inside the object, with a label attached. This provides a distinct way to mark objects. ```APIDOC ## draw_flag_with_label ### Description Creates a visual representation of a flag originating from inside the object, with a label attached. This provides a distinct way to mark objects. ### Method ```python img = bbv.draw_flag_with_label(img, label, bbox) ``` ### Parameters - `img`: The input image. - `label`: The text label to be added. - `bbox`: A tuple representing the bounding box in the format (xmin, ymin, xmax, ymax). ``` -------------------------------- ### Draw a Flag-Style Label Source: https://context7.com/shoumikchow/bbox-visualizer/llms.txt Draws a vertical pole from inside the bounding box upward, with a rectangular text banner at the top. Falls back to a box + regular label if the flag would go out of frame. Pole color and text background are independently configurable. Can draw pole only by setting `write_label=False`. ```python import bbox_visualizer as bbv import cv2 image = cv2.imread("image.jpg") bbox = [150, 150, 350, 350] # Flag with default white colors image = bbv.draw_flag_with_label(image, "Object", bbox) # Custom pole/background/text colors image = bbv.draw_flag_with_label( image, "Traffic Sign", bbox, line_color=(0, 255, 255), # Yellow pole (BGR) text_bg_color=(0, 255, 255), text_color=(0, 0, 0), ) # Flag without text label (pole only) image = bbv.draw_flag_with_label(image, "", bbox, write_label=False) cv2.imwrite("output.jpg", image) ``` -------------------------------- ### draw_multiple_boxes / draw_multiple_rectangles Source: https://context7.com/shoumikchow/bbox-visualizer/llms.txt Efficiently draws multiple bounding boxes on an image in a single batched operation. Raises ValueError if the list of bounding boxes is empty. ```APIDOC ## draw_multiple_boxes / draw_multiple_rectangles ### Description Draws all boxes in a single batched OpenCV operation using `cv2.polylines`, making it more efficient than looping over `draw_box`. Raises `ValueError` if the list is empty. ### Parameters - **image** (numpy.ndarray) - The input image. - **bboxes** (list of lists) - A list where each element is a bounding box in [xmin, ymin, xmax, ymax] format. - **bbox_color** (tuple, optional) - The color of the bounding boxes in BGR format. Defaults to (255, 255, 255) (white). - **thickness** (int, optional) - The thickness of the bounding box outlines. Defaults to 3. - **is_opaque** (bool, optional) - If True, draws filled semi-transparent boxes. Defaults to False. - **alpha** (float, optional) - The opacity level for the filled boxes when `is_opaque` is True. Defaults to 0.5. ### Request Example ```python import bbox_visualizer as bbv import cv2 image = cv2.imread("image.jpg") bboxes = [ [50, 50, 150, 150], [200, 100, 350, 280], [400, 60, 500, 200], ] # All boxes in one call (same color) image = bbv.draw_multiple_boxes(image, bboxes, bbox_color=(255, 100, 0), thickness=2) # Opaque filled boxes image = bbv.draw_multiple_boxes(image, bboxes, is_opaque=True, alpha=0.4) cv2.imwrite("output.jpg", image) ``` ### Response - **image** (numpy.ndarray) - The image with the bounding boxes drawn. ``` -------------------------------- ### Format Bounding Box as List Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/examples/single_object_example.ipynb Formats the extracted bounding box coordinates into a list in the [xmin, ymin, xmax, ymax] format. This is a common input format for many visualization functions. ```python bbox = [xmin, ymin, xmax, ymax] print(bbox) ``` -------------------------------- ### Warning Control Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/docs/api.md Functions to manage warning suppression within the visualizer. ```APIDOC ## Warning Control ### Description Functions to manage warning suppression within the visualizer. ### Methods - `bbox_visualizer.suppress_warnings` - `bbox_visualizer.warnings_suppressed` ``` -------------------------------- ### Drawing multiple bounding boxes with T-shaped labels Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/README.md Draws multiple bounding boxes and attaches T-shaped labels to them. This is an alternative labeling style for multiple objects. ```APIDOC ## draw_multiple_boxes and add_multiple_T_labels ### Description Draws multiple bounding boxes and attaches T-shaped labels to them. This is an alternative labeling style for multiple objects. ### Method ```python img = bbv.draw_multiple_boxes(img, bboxes) img = bbv.add_multiple_T_labels(img, labels, bboxes) ``` ### Parameters - `img`: The input image. - `bboxes`: A list of tuples, where each tuple represents a bounding box in the format (xmin, ymin, xmax, ymax). - `labels`: A list of strings, where each string is a label corresponding to a bounding box. ``` -------------------------------- ### Draw Multiple Bounding Boxes with T-style Labels Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/README.md Draws multiple bounding boxes, each with a T-style label inside. This function is suitable for images with numerous objects to label. ```python img = bbv.draw_multiple_boxes(img, bboxes) img = bbv.add_multiple_T_labels(img, labels, bboxes) ``` -------------------------------- ### Drawing multiple flags with labels Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/README.md Draws multiple flags originating from objects, each with an associated label. This provides a clear and distinct way to annotate multiple items. ```APIDOC ## draw_multiple_flags_with_labels ### Description Draws multiple flags originating from objects, each with an associated label. This provides a clear and distinct way to annotate multiple items. ### Method ```python img = bbv.draw_multiple_flags_with_labels(img, labels, bboxes) ``` ### Parameters - `img`: The input image. - `labels`: A list of strings, where each string is a label corresponding to a bounding box. - `bboxes`: A list of tuples, where each tuple represents a bounding box in the format (xmin, ymin, xmax, ymax). ``` -------------------------------- ### Drawing Single and Multiple Boxes Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/docs/usage.md Draw single or multiple bounding boxes on an image. The library supports the standard (x1, y1, x2, y2) format for bounding boxes. ```python # Single box bbox = (100, 100, 200, 200) # (x1, y1, x2, y2) format image = bbv.draw_box(image, bbox) # Multiple boxes bboxes = [(100, 100, 200, 200), (300, 300, 400, 400)] image = bbv.draw_multiple_boxes(image, bboxes) # Filled box with transparency image = bbv.draw_box(image, bbox, is_opaque=True, alpha=0.5) ``` -------------------------------- ### Draw Flag with Label Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/README.md Draws a bounding box with a label that resembles a flag, with the pole originating from inside the object's bounding box. ```python img = bbv.draw_flag_with_label(img, label, bbox) ``` -------------------------------- ### add_multiple_labels Source: https://context7.com/shoumikchow/bbox-visualizer/llms.txt Applies the `add_label` function to multiple bounding boxes and their corresponding labels. It requires that the lists of labels and bounding boxes have the same length and raises ValueError if either list is empty. ```APIDOC ## add_multiple_labels ### Description Applies `add_label` to each (label, bbox) pair. Validates that the two lists have the same length and raises `ValueError` if either is empty. ### Parameters - **image** (numpy.ndarray) - The input image. - **labels** (list of str) - A list of text labels. - **bboxes** (list of lists) - A list where each element is a bounding box in [xmin, ymin, xmax, ymax] format. - **top** (bool, optional) - If True, attempts to place the labels above the bounding boxes. Defaults to True. - **draw_bg** (bool, optional) - If True, draws a background rectangle for each label. Defaults to True. - **size** (float, optional) - The font size for the labels. Defaults to 0.5. - **thickness** (int, optional) - The thickness of the labels' text and background borders. Defaults to 1. - **text_color** (tuple, optional) - The color of the text in BGR format. Defaults to (0, 0, 0) (black). - **text_bg_color** (tuple, optional) - The color of the background rectangles in BGR format. Defaults to (255, 255, 255) (white). ### Request Example ```python import bbox_visualizer as bbv import cv2 image = cv2.imread("image.jpg") bboxes = [[50, 50, 150, 150], [200, 100, 350, 280], [400, 60, 500, 200]] labels = ["Person", "Car", "Dog"] # Labels above each box image = bbv.draw_multiple_boxes(image, bboxes, bbox_color=(0, 255, 0)) image = bbv.add_multiple_labels(image, labels, bboxes, top=True) # Labels inside boxes with custom colors image = bbv.add_multiple_labels( image, labels, bboxes, top=False, text_bg_color=(50, 50, 50), text_color=(255, 255, 255), ) cv2.imwrite("output.jpg", image) ``` ### Response - **image** (numpy.ndarray) - The image with the labels added. ``` -------------------------------- ### draw_box / draw_rectangle Source: https://context7.com/shoumikchow/bbox-visualizer/llms.txt Draws a rectangle outline or a semi-transparent filled overlay around an object in an image. These functions are aliases for each other. ```APIDOC ## draw_box / draw_rectangle ### Description Draws a rectangle outline (or filled semi-transparent overlay) around an object. `draw_box` and `draw_rectangle` are identical aliases. ### Parameters - **image** (numpy.ndarray) - The input image. - **bbox** (list) - A list containing the bounding box coordinates in [xmin, ymin, xmax, ymax] format. - **bbox_color** (tuple, optional) - The color of the bounding box in BGR format. Defaults to (255, 255, 255) (white). - **thickness** (int, optional) - The thickness of the bounding box outline. Defaults to 3. - **is_opaque** (bool, optional) - If True, draws a filled semi-transparent box. Defaults to False. - **alpha** (float, optional) - The opacity level for the filled box when `is_opaque` is True. Defaults to 0.5. ### Request Example ```python import bbox_visualizer as bbv import cv2 image = cv2.imread("image.jpg") bbox = [100, 80, 300, 250] # [xmin, ymin, xmax, ymax] # Outline box (default white, thickness 3) image = bbv.draw_box(image, bbox) # Custom color and thickness image = bbv.draw_box(image, bbox, bbox_color=(0, 255, 0), thickness=2) # Semi-transparent filled box (50% opacity) image = bbv.draw_box(image, bbox, is_opaque=True, alpha=0.5, bbox_color=(0, 200, 0)) cv2.imwrite("output.jpg", image) ``` ### Response - **image** (numpy.ndarray) - The image with the bounding box drawn. ``` -------------------------------- ### Add Label in T Format Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/examples/single_object_example.ipynb Adds a text label to the bounding box in a 'T' format using the `add_T_label` function. Prints the type of the resulting image. ```python img_T_label = bbv.add_T_label(img_with_box_2, label, bbox) print(type(img_T_label)) ``` -------------------------------- ### draw_multiple_flags_with_labels Source: https://context7.com/shoumikchow/bbox-visualizer/llms.txt Applies the `draw_flag_with_label` function to multiple bounding boxes and their corresponding labels. This is useful for annotating several objects in an image with flag-style labels. ```APIDOC ## `draw_multiple_flags_with_labels` — Draw Flag Labels for Multiple Boxes Applies `draw_flag_with_label` to each (label, bbox) pair. Raises `ValueError` if lists are empty or mismatched. ```python import bbox_visualizer as bbv import cv2 image = cv2.imread("image.jpg") bboxes = [[30, 80, 160, 240], [200, 70, 360, 260], [400, 90, 560, 270]] labels = ["Cat", "Dog", "Bird"] image = bbv.draw_multiple_flags_with_labels( image, labels, bboxes, line_color=(200, 200, 0), text_bg_color=(200, 200, 0), text_color=(0, 0, 0), ) cv2.imwrite("output.jpg", image) ``` ``` -------------------------------- ### Add T-Shaped Labels to Multiple Boxes Source: https://context7.com/shoumikchow/bbox-visualizer/llms.txt Applies `add_T_label` to each (label, bbox) pair. Raises `ValueError` if lists are empty or mismatched. Configure text background and text colors. ```python import bbox_visualizer as bbv import cv2 image = cv2.imread("image.jpg") bboxes = [[50, 100, 180, 250], [220, 90, 380, 260], [410, 80, 550, 230]] labels = ["Pedestrian", "Cyclist", "Vehicle"] image = bbv.draw_multiple_boxes(image, bboxes) image = bbv.add_multiple_T_labels( image, labels, bboxes, text_bg_color=(255, 255, 200), text_color=(0, 0, 0), ) cv2.imwrite("output.jpg", image) ``` -------------------------------- ### Globally Toggle Warning Messages Source: https://context7.com/shoumikchow/bbox-visualizer/llms.txt Enables or disables logging warnings emitted when a label style (T or Flag) goes out of the image frame and falls back to a simpler style. Use `suppress_warnings(True)` to disable and `suppress_warnings(False)` to re-enable. ```python import bbox_visualizer as bbv import cv2 image = cv2.imread("image.jpg") bbox = [10, 10, 100, 50] # Near top edge — T/flag label will overflow # Suppress warnings globally bbv.suppress_warnings(True) image = bbv.add_T_label(image, "Edge Object", bbox) # No warning logged # Re-enable warnings bbv.suppress_warnings(False) ``` -------------------------------- ### Display Image with T Label Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/examples/single_object_example.ipynb Displays the image with the 'T' formatted label using matplotlib.pyplot. ```python plt.imshow(img_T_label); ``` -------------------------------- ### Add Label to Bounding Box Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/examples/single_object_example.ipynb Adds a text label to the bounding box on the image using the `add_label` function. Creates a copy of the image before adding the label to preserve the original. Prints the type of the resulting image. ```python img_with_box_2 = img_with_box.copy() img_label = bbv.add_label(img_with_box, label, bbox) print(type(img_label)) ``` -------------------------------- ### Add a text label to a bounding box Source: https://context7.com/shoumikchow/bbox-visualizer/llms.txt Use `add_label` to place text above or inside a bounding box. The function automatically handles fallback positioning if space above is insufficient. Customize text and background colors, size, and thickness. ```python import bbox_visualizer as bbv import cv2 image = cv2.imread("image.jpg") bbox = [100, 80, 300, 250] # Label above the box (default) image = bbv.draw_box(image, bbox, bbox_color=(0, 255, 0)) image = bbv.add_label(image, "Person 0.95", bbox, top=True) # Label inside the box, no background image = bbv.add_label(image, "Car", bbox, top=False, draw_bg=False, text_color=(255, 255, 255)) # Custom font size and colors image = bbv.add_label( image, "Dog", bbox, size=0.7, thickness=1, text_bg_color=(0, 0, 255), # Red background (BGR) text_color=(255, 255, 255), # White text top=True, ) cv2.imwrite("output.jpg", image) ``` -------------------------------- ### Special Labels Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/docs/api.md Functions for drawing special labels and flags with labels. ```APIDOC ## Special Labels ### Description Functions for drawing special labels and flags with labels. ### Methods - `bbox_visualizer.add_T_label` - `bbox_visualizer.add_multiple_T_labels` - `bbox_visualizer.draw_flag_with_label` - `bbox_visualizer.draw_multiple_flags_with_labels` ``` -------------------------------- ### Special Label Styles: T-shaped and Flag Source: https://github.com/shoumikchow/bbox-visualizer/blob/master/docs/usage.md Utilize special label styles like T-shaped labels and flag-style labels for enhanced visualization. Supports adding multiple labels of these styles. ```python # T-shaped label image = bbv.add_T_label(image, "Object", bbox) # Flag-style label image = bbv.draw_flag_with_label(image, "Object", bbox) # Multiple T-shaped labels image = bbv.add_multiple_T_labels(image, labels, bboxes) # Multiple flag labels image = bbv.draw_multiple_flags_with_labels(image, labels, bboxes) ```