Validate that polygon has at least 1 vertex in geometry utils.py#1602
Merged
LinasKo merged 3 commits intoroboflow:developfrom Oct 17, 2024
ablazejuk:patch-1
Merged
Validate that polygon has at least 1 vertex in geometry utils.py#1602LinasKo merged 3 commits intoroboflow:developfrom ablazejuk:patch-1
LinasKo merged 3 commits intoroboflow:developfrom
ablazejuk:patch-1
Conversation
Contributor
|
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. |
Contributor
|
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
approved these changes
Oct 17, 2024
Contributor
|
Thank you for the contribution @ablazejuk! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
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