Fix small images with Azure and error messages being copied out
This commit is contained in:
@@ -6,6 +6,7 @@ import time
|
||||
import sys
|
||||
import platform
|
||||
import logging
|
||||
import warnings
|
||||
from math import sqrt
|
||||
|
||||
import jaconv
|
||||
@@ -112,6 +113,7 @@ class MangaOcr:
|
||||
logger.warning('manga-ocr not available, Manga OCR will not work!')
|
||||
else:
|
||||
logger.disable('manga_ocr')
|
||||
warnings.filterwarnings("ignore", message=".*MPS: no support.*")
|
||||
from manga_ocr import ocr
|
||||
ocr.post_process = empty_post_process
|
||||
logger.info(f'Loading Manga OCR model')
|
||||
@@ -390,6 +392,13 @@ class AzureImageAnalysis:
|
||||
return x
|
||||
|
||||
def _preprocess(self, img):
|
||||
if any(x < 50 for x in img.size):
|
||||
w,h = img.size
|
||||
resize_factor = max(50/w, 50/h)
|
||||
new_w = int(w * resize_factor)
|
||||
new_h = int(h * resize_factor)
|
||||
img = img.resize((new_w, new_h), Image.LANCZOS)
|
||||
|
||||
return pil_image_to_bytes(img)
|
||||
|
||||
class EasyOCR:
|
||||
|
||||
24
owocr/run.py
24
owocr/run.py
@@ -308,21 +308,21 @@ def process_and_write_results(engine_instance, img_or_path, write_to, enable_fil
|
||||
notification.title = 'Text recognized:'
|
||||
notification.message = text
|
||||
notification.send(block=False)
|
||||
|
||||
if write_to == 'websocket':
|
||||
websocket_server_thread.send_text(text)
|
||||
elif write_to == 'clipboard':
|
||||
pyperclipfix.copy(text)
|
||||
else:
|
||||
write_to = Path(write_to)
|
||||
if write_to.suffix.lower() != '.txt':
|
||||
raise ValueError('write_to must be either "websocket", "clipboard" or a path to a text file')
|
||||
|
||||
with write_to.open('a', encoding='utf-8') as f:
|
||||
f.write(text + '\n')
|
||||
else:
|
||||
logger.opt(ansi=True).info(f'<{engine_color}>{engine_instance.readable_name}</{engine_color}> reported an error after {t1 - t0:0.03f}s: {text}')
|
||||
|
||||
if write_to == 'websocket':
|
||||
websocket_server_thread.send_text(text)
|
||||
elif write_to == 'clipboard':
|
||||
pyperclipfix.copy(text)
|
||||
else:
|
||||
write_to = Path(write_to)
|
||||
if write_to.suffix.lower() != '.txt':
|
||||
raise ValueError('write_to must be either "websocket", "clipboard" or a path to a text file')
|
||||
|
||||
with write_to.open('a', encoding='utf-8') as f:
|
||||
f.write(text + '\n')
|
||||
|
||||
return orig_text
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user