Skip to main content

A library for drawing custom bounding boxes with rounded corners.

Project description

ZRect

ZRect is a Python library for drawing custom bounding boxes with rounded corners on images using OpenCV. It supports dynamic adjustment of corner radius and border thickness, along with options for adding labels to the bounding boxes.

Features

  • Draw rounded rectangles on images.
  • Dynamically adjusts corner radius and border thickness based on box dimensions.
  • Add custom labels with solid background and rounded edges.
  • Assign random colors to classes for better visualization.

Installation

Install from Source

If the package is distributed as a file:

pip install /path/to/zrect-0.1.0.tar.gz

Install from Private Repository

If hosted on a private repository:

pip install git+ssh://git@your-private-repo-url/zrect.git

Usage Example

import cv2
from zdraw import ZDraw
# Initialize ZRect with an optional class color map
# Initialize ZRect
zdraw = ZDraw()

# Load an image
frame = cv2.imread("image.jpg")

# Define bounding box coordinates and class
x1, y1, x2, y2 = 100, 150, 400, 300
class_name = "DynamicObject"

# Draw bounding box with label
original_frame, modified_frame = zdraw.ZRectDraw(frame, x1, y1, x2, y2, class_name, return_original_frame)

# Display the result
cv2.imshow("Original Frame", original_frame)
cv2.imshow("Modified Frame", modified_frame)
cv2.waitKey(0)
cv2.destroyAllWindows()

API Reference

ZDraw

__init__(class_colors={})

  • Initializes the ZDraw object.

  • Parameters:

    • class_colors (dict): A dictionary mapping class names to RGB tuples.

get_color_for_class(class_name)

  • Returns a random color for a given class if not already assigned.

__draw_rec__(frame, top_left, bottom_right, border_color, fill_color)

  • Draws a rounded rectangle on the frame, private.

ZRectDraw(frame, x1, y1, x2, y2)

  • Draws a bounding box with rounded corners and a label.

Dependencies

  • Python 3.8 or higher
  • OpenCV (opencv-python)
  • NumPy

License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zdraw-0.1.1.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zdraw-0.1.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file zdraw-0.1.1.tar.gz.

File metadata

  • Download URL: zdraw-0.1.1.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.4

File hashes

Hashes for zdraw-0.1.1.tar.gz
Algorithm Hash digest
SHA256 74148a0a6a78512abe23f5853ffeb277c69709c400d498bf22e67e80805ca42b
MD5 cad22892eec0e35c619363d958008661
BLAKE2b-256 27b4395dc73b0eea003a26a11db4d50df3b36f977f8ef6a18b852194ff3f0e2b

See more details on using hashes here.

File details

Details for the file zdraw-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: zdraw-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.4

File hashes

Hashes for zdraw-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2e0e6e9c887d12da61adc7e78b107ba1766404d4f281ab29dc77fe5c09df8c96
MD5 6c1bcee5d5813108d0c052688d63f0c0
BLAKE2b-256 bf6eba5f6dade7c0d57103ca31d2073b7cf55d61ab1473b0ca6dfff042bfc304

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page