|
@@ -1,19 +1,28 @@
|
|
-from .... import requests,cv2,time,random,os,tempfile,logger,re
|
|
|
|
|
|
+from .... import requests,cv2,time,random,os,tempfile,logger,re,uuid
|
|
class OCRProcesso:
|
|
class OCRProcesso:
|
|
def __init__(self):
|
|
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
|
|
def ocr(self,imgs):
|
|
def ocr(self,imgs):
|
|
# 创建临时目录
|
|
# 创建临时目录
|
|
temp_dir = tempfile.mkdtemp()
|
|
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}')
|
|
|
|
|
|
+ temp_image_path = os.path.join(temp_dir, f'{uuid.uuid4()}.png')
|
|
cv2.imwrite(temp_image_path, imgs)
|
|
cv2.imwrite(temp_image_path, imgs)
|
|
r = requests.post(
|
|
r = requests.post(
|
|
- 'http://183.195.216.54:9587/ocr', files={'image': (temp_image_path, open(temp_image_path, 'rb'), 'image/png')},
|
|
|
|
|
|
+ 'http://183.195.216.54:9577' ,data={'file': str(temp_image_path)}
|
|
)
|
|
)
|
|
- 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
|
|
|
|
|
|
+ return ''.join(r.json())
|