Skip to content

Commit

Permalink
add skipBoundsValidation option
Browse files Browse the repository at this point in the history
  • Loading branch information
almazgimaev committed Sep 2, 2024
1 parent d749939 commit b09c330
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ValidationReq(BaseModel):
height: int
width: int
figures: List[dict]
skipBoundsValidation: Optional[bool] = False


class ValidationResponse(BaseModel):
Expand All @@ -44,6 +45,7 @@ def validate_figures(req: ValidationReq):
img_width = req.width
img_size = (img_height, img_width)
canvas_rect = sly.Rectangle.from_size(img_size)
skip_bounds_validation = req.skipBoundsValidation

batch_result = []

Expand Down Expand Up @@ -102,14 +104,15 @@ def validate_figures(req: ValidationReq):
geometry_bbox = geometry.to_bbox()

# check figure is within image bounds
if canvas_rect.contains(geometry_bbox) is False:
corners = [
pos + str((xy.col, xy.row))
for pos, xy in zip(["ltop", "rtop", "rbot", "lbot"], geometry_bbox.corners)
]
raise Exception(
f"Figure with corners {corners} is out of image bounds: {img_height}x{img_width}"
)
if not skip_bounds_validation:
if canvas_rect.contains(geometry_bbox) is False:
corners = [
pos + str((xy.col, xy.row))
for pos, xy in zip(["ltop", "rtop", "rbot", "lbot"], geometry_bbox.corners)
]
raise Exception(
f"Figure with corners {corners} is out of image bounds: {img_height}x{img_width}"
)

# check if there are no contours with less than 3 points in polygon
if shape == sly.Polygon:
Expand Down

0 comments on commit b09c330

Please sign in to comment.