Add verbosity option, fix regression with separation of lines/paragraphs in terminal text output with coordinate-enabled engines

This commit is contained in:
AuroraWright
2025-09-20 11:52:26 +02:00
parent bf9debd479
commit de760458a9
4 changed files with 23 additions and 13 deletions

View File

@@ -85,6 +85,7 @@ try:
except:
optimized_png_encode = False
@dataclass
class BoundingBox:
"""
@@ -133,7 +134,6 @@ class OcrResult:
def empty_post_process(text):
return text
def post_process(text):
text = ' '.join([''.join(i.split()) for i in text.splitlines()])
text = text.replace('', '...')
@@ -141,7 +141,6 @@ def post_process(text):
text = jaconv.h2z(text, ascii=True, digit=True)
return text
def input_to_pil_image(img):
is_path = False
if isinstance(img, Image.Image):
@@ -159,7 +158,6 @@ def input_to_pil_image(img):
raise ValueError(f'img must be a path, PIL.Image or bytes object, instead got: {img}')
return pil_image, is_path
def pil_image_to_bytes(img, img_format='png', png_compression=6, jpeg_quality=80, optimize=False):
if img_format == 'png' and optimized_png_encode and not optimize:
raw_data = img.convert('RGBA').tobytes()
@@ -172,11 +170,9 @@ def pil_image_to_bytes(img, img_format='png', png_compression=6, jpeg_quality=80
image_bytes = image_bytes.getvalue()
return image_bytes
def pil_image_to_numpy_array(img):
return np.array(img.convert('RGBA'))
def limit_image_size(img, max_size):
img_bytes = pil_image_to_bytes(img)
if len(img_bytes) <= max_size:
@@ -745,7 +741,6 @@ class AppleVision:
def _preprocess(self, img):
return pil_image_to_bytes(img, 'tiff')
class AppleLiveText:
name = 'alivetext'
readable_name = 'Apple Live Text'
@@ -883,7 +878,6 @@ class AppleLiveText:
ns_image = NSImage.alloc().initWithData_(ns_data)
return ns_image
class WinRTOCR:
name = 'winrtocr'
readable_name = 'WinRT OCR'