OCR_Processo.py 1.2 KB

12345678910111213141516171819202122232425262728
  1. from .... import requests,cv2,time,random,os,tempfile,logger,re,uuid
  2. class OCRProcesso:
  3. def __init__(self):
  4. ...
  5. # def ocr(self,imgs):
  6. # # 创建临时目录
  7. # temp_dir = tempfile.mkdtemp()
  8. # temp_image_path = os.path.join(temp_dir, f'temp_image_{time.time()}_{random.randint(0, 1000)}.png')
  9. # logger.info(f'文件地址 {temp_image_path}')
  10. # cv2.imwrite(temp_image_path, imgs)
  11. # r = requests.post(
  12. # 'http://183.195.216.54:9587/ocr', files={'image': (temp_image_path, open(temp_image_path, 'rb'), 'image/png')},
  13. # )
  14. # ocr_out = r.json()['results']
  15. # ocr_out = ''.join( [item['text'] for item in ocr_out])
  16. # if ocr_out == 'ELSEVTER':
  17. # ocr_out = ''
  18. # logger.debug(ocr_out)
  19. # return ocr_out
  20. def ocr(self,imgs):
  21. # 创建临时目录
  22. temp_dir = tempfile.mkdtemp()
  23. temp_image_path = os.path.join(temp_dir, f'{uuid.uuid4()}.png')
  24. cv2.imwrite(temp_image_path, imgs)
  25. r = requests.post(
  26. 'http://183.195.216.54:9577' ,data={'file': str(temp_image_path)}
  27. )
  28. return ''.join(r.json())