diff --git a/owocr/ocr.py b/owocr/ocr.py index d3e1352..71f5c3c 100644 --- a/owocr/ocr.py +++ b/owocr/ocr.py @@ -207,6 +207,7 @@ class MangaOcr: readable_name = 'Manga OCR' key = 'm' available = False + coordinate_support = False def __init__(self, config={'pretrained_model_name_or_path':'kha-white/manga-ocr-base','force_cpu': False}): if 'manga_ocr' not in sys.modules: @@ -237,6 +238,7 @@ class GoogleVision: readable_name = 'Google Vision' key = 'g' available = False + coordinate_support = False def __init__(self): if 'google.cloud' not in sys.modules: @@ -281,6 +283,7 @@ class GoogleLens: readable_name = 'Google Lens' key = 'l' available = False + coordinate_support = True def __init__(self): if 'betterproto' not in sys.modules: @@ -425,6 +428,7 @@ class GoogleLensWeb: readable_name = 'Google Lens (web)' key = 'k' available = False + coordinate_support = False def __init__(self): if 'pyjson5' not in sys.modules: @@ -520,6 +524,7 @@ class Bing: readable_name = 'Bing' key = 'b' available = False + coordinate_support = True def __init__(self): self.requests_session = requests.Session() @@ -697,6 +702,7 @@ class AppleVision: readable_name = 'Apple Vision' key = 'a' available = False + coordinate_support = False def __init__(self): if sys.platform != 'darwin': @@ -746,6 +752,7 @@ class AppleLiveText: readable_name = 'Apple Live Text' key = 'd' available = False + coordinate_support = False def __init__(self): if sys.platform != 'darwin': @@ -826,6 +833,7 @@ class WinRTOCR: readable_name = 'WinRT OCR' key = 'w' available = False + coordinate_support = False def __init__(self, config={}): if sys.platform == 'win32': @@ -879,6 +887,7 @@ class OneOCR: readable_name = 'OneOCR' key = 'z' available = False + coordinate_support = True def __init__(self, config={}): if sys.platform == 'win32': @@ -1001,6 +1010,7 @@ class AzureImageAnalysis: readable_name = 'Azure Image Analysis' key = 'v' available = False + coordinate_support = False def __init__(self, config={}): if 'azure.ai.vision.imageanalysis' not in sys.modules: @@ -1054,6 +1064,7 @@ class EasyOCR: readable_name = 'EasyOCR' key = 'e' available = False + coordinate_support = False def __init__(self, config={'gpu': True}): if 'easyocr' not in sys.modules: @@ -1089,6 +1100,7 @@ class RapidOCR: readable_name = 'RapidOCR' key = 'r' available = False + coordinate_support = False def __init__(self): if 'rapidocr_onnxruntime' not in sys.modules: @@ -1137,6 +1149,7 @@ class OCRSpace: readable_name = 'OCRSpace' key = 'o' available = False + coordinate_support = False def __init__(self, config={}): try: diff --git a/owocr/run.py b/owocr/run.py index ee87768..0b65031 100644 --- a/owocr/run.py +++ b/owocr/run.py @@ -841,9 +841,9 @@ def process_and_write_results(img_or_path, last_result, filtering, notify): if output_format == 'json': result_dict = asdict(result_data) - output_string = json.dumps(result_dict, indent=4, ensure_ascii=False) + output_string = json.dumps(result_dict, ensure_ascii=False) log_message = post_process(unprocessed_text) - else: # 'text' format for a modern engine + else: # 'text' format if filtering: text_to_process, orig_text = filtering(unprocessed_text, last_result) output_string = post_process(text_to_process) @@ -1031,9 +1031,10 @@ def run(): user_input_thread.start() # if json is selected check if engine is compatible - if output_format == 'json' and engine_instances[engine_index].name not in ['bing', 'glens', 'oneocr']: + if output_format == 'json' and not engine_instances[engine_index].coordinate_support: + supported_engines = (engine.name for engine in engine_instances if engine.coordinate_support) logger.error(f"The selected engine '{engine_instances[engine_index].name}' does not support coordinate output.") - logger.error(f"Please choose one of: {', '.join(COORDINATE_SUPPORTED_ENGINES)}") + logger.error(f"Please choose one of: {', '.join(supported_engines)}") sys.exit(1) logger.opt(ansi=True).info(f"Reading from {' and '.join(read_from_readable)}, writing to {write_to_readable} using <{engine_color}>{engine_instances[engine_index].readable_name}{' (paused)' if paused else ''}")