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 sys
|
||||||
import platform
|
import platform
|
||||||
import logging
|
import logging
|
||||||
|
import warnings
|
||||||
from math import sqrt
|
from math import sqrt
|
||||||
|
|
||||||
import jaconv
|
import jaconv
|
||||||
@@ -112,6 +113,7 @@ class MangaOcr:
|
|||||||
logger.warning('manga-ocr not available, Manga OCR will not work!')
|
logger.warning('manga-ocr not available, Manga OCR will not work!')
|
||||||
else:
|
else:
|
||||||
logger.disable('manga_ocr')
|
logger.disable('manga_ocr')
|
||||||
|
warnings.filterwarnings("ignore", message=".*MPS: no support.*")
|
||||||
from manga_ocr import ocr
|
from manga_ocr import ocr
|
||||||
ocr.post_process = empty_post_process
|
ocr.post_process = empty_post_process
|
||||||
logger.info(f'Loading Manga OCR model')
|
logger.info(f'Loading Manga OCR model')
|
||||||
@@ -390,6 +392,13 @@ class AzureImageAnalysis:
|
|||||||
return x
|
return x
|
||||||
|
|
||||||
def _preprocess(self, img):
|
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)
|
return pil_image_to_bytes(img)
|
||||||
|
|
||||||
class EasyOCR:
|
class EasyOCR:
|
||||||
|
|||||||
@@ -308,8 +308,6 @@ def process_and_write_results(engine_instance, img_or_path, write_to, enable_fil
|
|||||||
notification.title = 'Text recognized:'
|
notification.title = 'Text recognized:'
|
||||||
notification.message = text
|
notification.message = text
|
||||||
notification.send(block=False)
|
notification.send(block=False)
|
||||||
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':
|
if write_to == 'websocket':
|
||||||
websocket_server_thread.send_text(text)
|
websocket_server_thread.send_text(text)
|
||||||
@@ -322,6 +320,8 @@ def process_and_write_results(engine_instance, img_or_path, write_to, enable_fil
|
|||||||
|
|
||||||
with write_to.open('a', encoding='utf-8') as f:
|
with write_to.open('a', encoding='utf-8') as f:
|
||||||
f.write(text + '\n')
|
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}')
|
||||||
|
|
||||||
return orig_text
|
return orig_text
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user