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

pip install zrect

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.tar.gz (3.7 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-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zdraw-0.1.2.tar.gz
  • Upload date:
  • Size: 3.7 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.tar.gz
Algorithm Hash digest
SHA256 bc0f9e9e6be730226786f279fe10c3c426e2abd12ad3303378115cf79cf292dd
MD5 385ecc9400041c5539cf50d372cee0e7
BLAKE2b-256 ee06e5be2b37554cbc72d1bd929df697e60860cac36dab5168a484a1f6da4a20

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zdraw-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.1 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-py3-none-any.whl
Algorithm Hash digest
SHA256 df03a880bcc31b9fe8411d92b131ec18d667b73f31eb1e62f108ab3d237eadc5
MD5 67efe14ee6eed6894f42e201f508158a
BLAKE2b-256 3c5258abfa4e9eb839558b44273c6cd619d1a7eda7615b7b508e6a52350fcc12

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