Skip to content

Validate that polygon has at least 1 vertex in geometry utils.py#1602

Merged
LinasKo merged 3 commits intoroboflow:developfrom
ablazejuk:patch-1
Oct 17, 2024
Merged

Validate that polygon has at least 1 vertex in geometry utils.py#1602
LinasKo merged 3 commits intoroboflow:developfrom
ablazejuk:patch-1

Conversation

@ablazejuk
Copy link
Contributor

Description

Please include a summary of the change and which issue is fixed or implemented. Please also include relevant motivation and context (e.g. links, docs, tickets etc.).

List any dependencies that are required for this change.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How has this change been tested, please provide a testcase or example of how you tested the change?

Just added a validation

Any specific deployment considerations

For example, documentation changes, usability, usage/costs, secrets, etc.

Docs

  • Docs updated? What were the changes:

@CLAassistant
Copy link

CLAassistant commented Oct 17, 2024

CLA assistant check
All committers have signed the CLA.

@LinasKo LinasKo self-requested a review October 17, 2024 18:01
@LinasKo
Copy link
Contributor

LinasKo commented Oct 17, 2024

Hi @ablazejuk 👋

I'll have a quick look and merge this soon. It's great when we can replace OpenCV errors with more meaningful messages.

@LinasKo
Copy link
Contributor

LinasKo commented Oct 17, 2024

Upon closer inspection, the method works fine with 1 and 2 points, and emits warnings when no points are passed. There is a possible rounding issue, but the update for polygon is slightly different than the one proposed.

Test code:

import supervision as sv
import numpy as np

polygon_0 = np.array([], dtype=np.float32).reshape(0, 2)
polygon_1 = np.array([[1, 1]], dtype=np.float32)
polygon_2 = np.array([[1, 1], [2, 2]], dtype=np.float32)
polygon_3 = np.array([[1, 1], [2, 1], [2, 2]], dtype=np.float32)
polygon_4 = np.array([[1, 1], [2, 1], [2, 1], [1, 2]], dtype=np.float32)

try:
    center_0 = sv.get_polygon_center(polygon_0)
except ValueError as e:
    print(e)

center_1 = sv.get_polygon_center(polygon_1)
center_2 = sv.get_polygon_center(polygon_2)
center_3 = sv.get_polygon_center(polygon_3)
center_4 = sv.get_polygon_center(polygon_4)

try:
    print(center_0)
except NameError:
    pass

print(center_1)
print(center_2)
print(center_3)
print(center_4)

@LinasKo LinasKo changed the title Validate that polygon has at least 3 vertices in geometry utils.py Validate that polygon has at least 1 vertex in geometry utils.py Oct 17, 2024
@LinasKo LinasKo merged commit f60d89f into roboflow:develop Oct 17, 2024
@LinasKo
Copy link
Contributor

LinasKo commented Oct 17, 2024

Thank you for the contribution @ablazejuk!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants