gt2det.py 714 B

123456789101112131415161718
  1. import json
  2. import jsonlines
  3. def gen_det_label(input_label, out_label):
  4. with open(out_label, 'w', encoding='UTF-8') as out_file:
  5. with jsonlines.open(input_label, 'r') as rfd:
  6. for data in rfd:
  7. img_path = data['filename']
  8. label = []
  9. for cell in data['html']['cells']:
  10. a = ''
  11. for text in cell['tokens']:
  12. a += text
  13. result = {"transcription": str(a), "points": cell['bbox'][0]}
  14. label.append(result)
  15. # print(label)
  16. out_file.write(img_path + '\t' + json.dumps(label, ensure_ascii=False) + '\n')