Skip to content

Commit 06a3cc6

Browse files
authored
Merge pull request #311 from VikParuchuri/hotfix/height
Fix height issue and add test
2 parents 780d351 + acacfbb commit 06a3cc6

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
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.10.2"
3+
version = "0.10.3"
44
description = "OCR, layout, reading order, and table recognition in 90+ languages"
55
authors = ["Vik Paruchuri <[email protected]>"]
66
readme = "README.md"

surya/detection/util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ def split_image(img, height):
2727
if bottom > img_height:
2828
bottom = img_height
2929
cropped = img.crop((0, top, img.size[0], bottom))
30-
height = bottom - top
31-
if height < height:
30+
chunk_height = bottom - top
31+
if chunk_height < height:
3232
cropped = ImageOps.pad(cropped, (img.size[0], height), color=255, centering=(0, 0))
3333
splits.append(cropped)
34-
split_heights.append(height)
34+
split_heights.append(chunk_height)
3535
return splits, split_heights
3636
return [img.copy()], [img_height]

tests/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,11 @@ def test_image():
5858
font_size=24)
5959
return image
6060

61+
@pytest.fixture()
62+
def test_image_tall():
63+
image = Image.new("RGB", (4096, 4096), "white")
64+
draw = ImageDraw.Draw(image)
65+
draw.text((10, 10), "Hello World", fill="black", font_size=72)
66+
draw.text((4000, 4000), "This is a sentence of text.\n\nNow it is a paragraph.\n\nA three-line one.", fill="black", font_size=24)
67+
return image
68+

tests/test_detection.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,15 @@ def test_detection(detection_predictor, test_image):
55
assert detection_results[0].image_bbox == [0, 0, 1024, 1024]
66

77
bboxes = detection_results[0].bboxes
8-
assert len(bboxes) == 4
8+
assert len(bboxes) == 4
9+
10+
11+
def test_detection_chunking(detection_predictor, test_image_tall):
12+
detection_results = detection_predictor([test_image_tall])
13+
14+
assert len(detection_results) == 1
15+
assert detection_results[0].image_bbox == [0, 0, 4096, 4096]
16+
17+
bboxes = detection_results[0].bboxes
18+
assert len(bboxes) >= 3 # Sometimes merges into 3
19+
assert abs(4000 - bboxes[1].polygon[0][0]) < 50

0 commit comments

Comments
 (0)