from pathlib import Path import sys,json,socket sys.dont_write_bytecode=True sys.path.insert(0,'C:/wechat_rpa') socket.create_connection=lambda *a,**k: (_ for _ in ()).throw(AssertionError('No network during OCR fixture validation')) import cv2,numpy as np from session_name import NameReader from reply_session_policy import excluded_session_reason path=Path('C:/Users/isard/AppData/Local/Temp/codex-clipboard-ffacbcf9-9a16-4e4d-b581-0bf8debbad53.png') image=cv2.imdecode(np.frombuffer(path.read_bytes(),dtype=np.uint8),cv2.IMREAD_COLOR) items=NameReader().read_layout(image) matches=[{'text':item['text'],'confidence':round(item['score'],4),'reason':excluded_session_reason(name=item['text'])} for item in items if excluded_session_reason(name=item['text'])] assert matches, 'Supplied system title not recognized: '+str(items) result={'suppliedScreenshotMatched':True,'shape':list(image.shape),'matches':matches,'realMessagesSent':0} (Path(__file__).parent/'screenshot-ocr.json').write_text(json.dumps(result,ensure_ascii=False,indent=2),encoding='utf-8') print(json.dumps(result,ensure_ascii=False))