123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import base64
- import os
- import re
- from crnn.crnn import crnnOcr
- from ocrapi import ocr
- def get_image():
- image_list = []
- for i in os.listdir('./result/image'):
- if re.match('(\d+)-(\d+)-(\d+)-(\d+)',i):
- with open(os.path.join('./result/image',i), 'rb') as f:
- base64_data = base64.b64encode(f.read())
- s = base64_data.decode()
- y_min, y_max, x_min, x_max = re.match('(\d+)-(\d+)-(\d+)-(\d+)', i).groups()
- image_list.append({'left':x_min,'top':y_min,'b64':s})
- return image_list
- def get_text():
- image_list = []
- for i in os.listdir('./result/text_img'):
- if re.match('(\d+)-(\d+)-(\d+)-(\d+)',i):
- with open(os.path.join('./result/text_img',i), 'rb') as f:
- s = crnnOcr(os.path.join('./result/text_img',i))
- # print(s)
- # s = ocr(os.path.join('./result/text_img',i))
- y_min, y_max, x_min, x_max = re.match('(\d+)-(\d+)-(\d+)-(\d+)', i).groups()
- image_list.append({'left':x_min,'top':y_min,
- 'w':int(x_max)-int(x_min),
- 'h':int(y_max)-int(y_min),
- 'size':int((int(y_max)-int(y_min))*0.6),
- 's':s})
- # print(i)
- # print({'left':x_min,'top':y_min,
- # 'w':int(x_max)-int(x_min),
- # 'h':int(y_max)-int(y_min),
- # 'size':int((int(y_max)-int(y_min))*0.6),
- # 's':s})
- return image_list
- if __name__ == '__main__':
- get_text()
|