Skip to main content

polyroi

polyroi.py

Status GitHub Issues GitHub Pull Requests License


Select and manipulate Region of interest.

📝 Table of Contents

🧐 About

A small python module to select a polygonal region of interest (ROI) in a given image that is stored as a Shape object. You can use this Shape object later to manipulate the polygon selected. You can also extract the inner content from an image, calculate the histogram of the created shape, calculate the center of the shape, rotate the shape around its center, or translate the shape.

🏁 Getting Started

import cv2 as cv
from polyroi import Shape
img = cv.imread('image.jpg')
shape = Shape.get_roi(img) #returns a Shape object
shape.draw_shape(img, color=(0, 255, 255), thickness=1)
while(1):
    cv.imshow("Getting Started", img)

    k = cv.waitKey(1) & 0xFF
    if k == 27:
        break
cv.destroyAllWindows()

Prerequisites

pip install cv2
pip install numpy

Installing

pip install polyroi 

🎈 Usage

Some time ago, I looked for an efficient tool to draw and manipulate polygons in a python environment. But I didn't find anything useful for my case. I did find some tools that can draw and extract a NumPy array, but as for the manipulation of shapes, I had to develop the logic myself. So I decided to create one. I was trying to implement the particle filter from Part-Based Lumbar Vertebrae Tracking in Videofluoroscopy Using Particle Filter. You can check the repository of how I did manage to work with this package.

img = cv.imread('image.jpg')

# returns a Shape object
shape = Shape.get_roi(img) 

# Copy the shape
shape2 = Shape.copy(shape) 

# Rotate the shape
shape2.rotate_around_center(np.pi/4) 

# x translate the shape by 5
shape2.translate_x(5) 

# y translate the shape by 5
shape2.translate_y(5) 

# recalculate the center of the shape
shape2.centroid() 

# translate the shape first point to (10, 15) along with the shape
shape2.translate_to(10, 15) 

# x translate, y translate, and rotate around the center by np.pi / 12
shape2.update(5, 3, np.pi / 12) 

# Drawing the shapes
shape.draw_shape(img, color=(0, 255, 255), thickness=1)
shape2.draw_shape(img, color=(0, 255, 0), thickness=1)

# return the bounding box points (upper left, bottom right)
p1, p2 = shape2.to_rectangle() 

# plotting the image
while(1):
    cv.imshow("Getting Started", img)

    k = cv.waitKey(1) & 0xFF
    if k == 27:
        break
cv.destroyAllWindows()

⛏️ Built Using

✍️ Authors

See also the list of contributors who participated in this project.

🎉 Acknowledgements

Metadata

Release files for polyroi 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polyroi 0.0.4
File Size Uploaded Provenance Actions
polyroi-0.0.4.tar.gz 6.9 kB Without provenance Details for polyroi-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for polyroi 0.0.4
File Interpreter ABI Platform Actions
polyroi-0.0.4-py3-none-any.whl Python 3 none any Details for polyroi-0.0.4-py3-none-any.whl

Total release size: 13.9 kB

Release files / polyroi-0.0.4.tar.gz

Download URL polyroi-0.0.4.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
52125f1f02c13ba7b829bfe51ad5375807250b47c6544386d5d2c2415784cb5a
BLAKE2b-256 checksum
How to use checksums
f8a102e348084dc81a81ef1bb62e3e94c14dd8805af34ab8ac81cfb90606df5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.6.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

Release files / polyroi-0.0.4-py3-none-any.whl

Download URL polyroi-0.0.4-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea3f7161055069397561ee67ad6d51b1aa58040f26f9229c3c884fa833eded33
BLAKE2b-256 checksum
How to use checksums
d5001c7c1e99dafc0559595418f3b3074e5f49298e9fcf9c451b8aef02edae01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.6.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

Security for polyroi 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page