File size: 722 Bytes
0347dd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import subprocess

from IdentifyModel.cardModel import parse_id_card
from Plan.AiLLM import extract_entities


def pytesseractJs_recognition(validation_type, image, temp_path, file_name, language):
    try:
        # 使用 subprocess 執行 JavaScript 代碼,傳遞語言參數
        subprocess.run(['node', 'pytesseractJsOCR.js', image, language, temp_path + file_name],
                       capture_output=True,
                       text=True)
        with open(temp_path + file_name, 'r') as file:
            out_ocr_text = file.read()
            entities = extract_entities(out_ocr_text)
        return parse_id_card(out_ocr_text, validation_type, entities)
    except Exception as e:
        return str(e)