from .... import requests,cv2,time,random,os,tempfile,logger,re
class OCRProcesso:
    def __init__(self):
        ...
    def ocr(self,imgs):
        # 创建临时目录
        temp_dir = tempfile.mkdtemp()
        temp_image_path = os.path.join(temp_dir, f'temp_image_{time.time()}_{random.randint(0, 1000)}.png')
        logger.info(f'文件地址 {temp_image_path}')
        cv2.imwrite(temp_image_path, imgs)
        r = requests.post(
            'http://183.195.216.54:9587/ocr', files={'image': (temp_image_path, open(temp_image_path, 'rb'), 'image/png')},
        )
        ocr_out = r.json()['results']
        ocr_out = ''.join( [item['text'] for item in ocr_out])
        if ocr_out == 'ELSEVTER':
            ocr_out = ''
        logger.debug(ocr_out)
        return ocr_out