Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def ocr_space_file(filename, overlay=True, api_key='myAPI', language='eng'):
- payload = {'isOverlayRequired': overlay,
- 'apikey': api_key,
- 'language': language,
- }
- with open(filename, 'rb') as f:
- r = requests.post('https://api.ocr.space/parse/image',
- files={filename: f},
- data=payload,
- )
- Info = r.content.decode()
- obj = json.loads(Info)
- f = open('Data.txt', 'w')
- for i in obj['ParsedResults']:
- for j in range(0,len(i["TextOverlay"]['Lines'])):
- allInfo = i["TextOverlay"]['Lines'][j]['Words']
- for k in allInfo:
- text = k['WordText']
- coords = [k['Left'],k['Top'],k['Width'],k['Height']]
- f1 = ','.join(map(str, coords))
- f.write(text+ " "+ f1 + 'n' )
- f.close()
- return r.content.decode()
- test_file = ocr_space_file(filename='1my.png', language='eng')
- imagePaths = [f for f in glob.glob('cropped_images/*.png')]
- save_path = 'Labeled_images/'
- def ocr_all_screenshots():
- for pic in imagePaths:
- #src_fname, ext = os.path.splitext(pic) # split filename and extension
- # construct output filename, basename to remove input directory
- #save_fname = os.path.join(save_path, os.path.basename(src_fname) + '_labeled.png')
- os.chdir(save_path)
- ocr_space_file(pic)
- ocr_all_screenshots()
- def ocr_space_file(filename, overlay=True, api_key='мой API', language='eng'):
- ...обработка json
- for i in obj['ParsedResults']:
- f = open('Data' +str(i) +'.txt', 'w')
- ...
- f1 = ','.join(map(str, coords))
- f.write(f1 + 'n' )
- f.close()
- return r.content.decode()
Add Comment
Please, Sign In to add comment