Skip to content

Commit

Permalink
Fix tile cannot extend outside image (#856)
Browse files Browse the repository at this point in the history
* Fix tile cannot extend outside image

* Lint

---------
  • Loading branch information
dhruvkaliraman7 authored Oct 1, 2024
1 parent ca1d08b commit 4c5725f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/sycamore/sycamore/transforms/detr_partitioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,8 @@ def infer(self, images: List[Image.Image], threshold: float, use_cache: bool = F
(w, h) = image.size
elements = []
for score, label, box in zip(result["scores"], result["labels"], result["boxes"]):
# Potential fix if negative bbox is causing downstream failures
# box = [max(0.0, coord) for coord in box]
element = create_element(
type=self.labels[label],
bbox=BoundingBox(box[0] / w, box[1] / h, box[2] / w, box[3] / h).coordinates,
Expand Down Expand Up @@ -765,7 +767,10 @@ def extract_ocr(
cropped_image = image.crop(crop_box)

# TODO: Do we want to switch to easyocr here too?
text = pytesseract.image_to_string(cropped_image)
if 0 in cropped_image.size:
text = ""
else:
text = pytesseract.image_to_string(cropped_image)

elem.text_representation = text

Expand Down

0 comments on commit 4c5725f

Please sign in to comment.