Skip to content

Commit d9213c8

Browse files
authored
Merge pull request #287 from VikParuchuri/dev
Better type checks for polygon
2 parents 9e93438 + e588758 commit d9213c8

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "surya-ocr"
3-
version = "0.9.1"
3+
version = "0.9.2"
44
description = "OCR, layout, reading order, and table recognition in 90+ languages"
55
authors = ["Vik Paruchuri <[email protected]>"]
66
readme = "README.md"

surya/common/polygon.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import numpy as np
55
from pydantic import BaseModel, field_validator, computed_field
6+
import numbers
67

78

89
class PolygonBox(BaseModel):
@@ -13,7 +14,8 @@ class PolygonBox(BaseModel):
1314
@classmethod
1415
def convert_bbox_to_polygon(cls, value):
1516
if isinstance(value, (list, tuple)) and len(value) == 4:
16-
if all(isinstance(x, (int, float, np.int32)) for x in value):
17+
if all(isinstance(x, numbers.Number) for x in value):
18+
value = [float(v) for v in value]
1719
x_min, y_min, x_max, y_max = value
1820
polygon = [
1921
[x_min, y_min],
@@ -23,6 +25,7 @@ def convert_bbox_to_polygon(cls, value):
2325
]
2426
return polygon
2527
elif all(isinstance(point, (list, tuple)) and len(point) == 2 for point in value):
28+
value = [[float(v) for v in point] for point in value]
2629
return value
2730
elif isinstance(value, np.ndarray):
2831
if value.shape == (4, 2):

0 commit comments

Comments
 (0)