mirror of
https://github.com/DS4SD/docling.git
synced 2025-12-09 13:18:24 +00:00
feat: add coverage_threshold to skip OCR for small images (#161)
* feat: add coverage_threshold to skip OCR for small images Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * filter individual boxes Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * rename option Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> --------- Signed-off-by: Michele Dolfi <dol@zurich.ibm.com>
This commit is contained in:
@@ -22,6 +22,9 @@ class TableStructureOptions(BaseModel):
|
||||
|
||||
class OcrOptions(BaseModel):
|
||||
kind: str
|
||||
bitmap_area_threshold: float = (
|
||||
0.05 # percentage of the area for a bitmap to processed with OCR
|
||||
)
|
||||
|
||||
|
||||
class EasyOcrOptions(OcrOptions):
|
||||
|
||||
@@ -69,7 +69,7 @@ class BaseOcrModel:
|
||||
coverage, ocr_rects = find_ocr_rects(page.size, bitmap_rects)
|
||||
|
||||
# return full-page rectangle if sufficiently covered with bitmaps
|
||||
if coverage > BITMAP_COVERAGE_TRESHOLD:
|
||||
if coverage > max(BITMAP_COVERAGE_TRESHOLD, self.options.bitmap_area_threshold):
|
||||
return [
|
||||
BoundingBox(
|
||||
l=0,
|
||||
@@ -81,6 +81,14 @@ class BaseOcrModel:
|
||||
]
|
||||
# return individual rectangles if the bitmap coverage is smaller
|
||||
else: # coverage <= BITMAP_COVERAGE_TRESHOLD:
|
||||
|
||||
# skip OCR if the bitmap area on the page is smaller than the options threshold
|
||||
ocr_rects = [
|
||||
rect
|
||||
for rect in ocr_rects
|
||||
if rect.area() / (page.size.width * page.size.height)
|
||||
> self.options.bitmap_area_threshold
|
||||
]
|
||||
return ocr_rects
|
||||
|
||||
# Filters OCR cells by dropping any OCR cell that intersects with an existing programmatic cell.
|
||||
|
||||
Reference in New Issue
Block a user