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

  • Draws 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

pip install zdraw

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=True)

# 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.2.1.tar.gz (3.5 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.2.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zdraw-0.1.2.1.tar.gz
  • Upload date:
  • Size: 3.5 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.2.1.tar.gz
Algorithm Hash digest
SHA256 a4a4f3e1a230e993af6f4d76af9fd85280048948f36960c159e404bd908c53bc
MD5 03c43f412601be94f0b39cf6da977139
BLAKE2b-256 a0b8f383462254821e779d6c5b3652f844330c5e219bf60b23517e3e517fd80b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zdraw-0.1.2.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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ef1d62dbc2f26c40a45f7a77a1f70186bb566cae77888331b8bdc2f0acf0d0b3
MD5 69c2eb87fc6df3fbd3e7cf339a0fd690
BLAKE2b-256 09a546f99553d71378a13f606a2f849bd0ca87c118ed0b1a1f93e8ffe8162be4

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