ocr_dataset.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. '''
  2. Author: hejinlong
  3. LastEditTime: 2021-03-08 09:15:27
  4. Description: hegd@mail.ustc.edu.cn
  5. '''
  6. # -*- coding: utf-8 -*-
  7. import numpy as np
  8. def simple_load_np_dataset(root_path = '/data2/liudan/ocr/data/ocr_txt/'):
  9. img_list_rec_file = root_path + 'val_img_path_rec.txt'
  10. boxes_rec_file = root_path + 'val_boxes_rec.txt'
  11. text_tag_rec_file = root_path + 'val_text_tag_rec.txt'
  12. all_img_path = []
  13. with open(img_list_rec_file,"r") as f:
  14. file_content = f.readlines()
  15. for i in file_content:
  16. all_img_path.append(i.strip())
  17. with open(boxes_rec_file,'r') as f:
  18. file_content = f.read().strip()
  19. num_list = file_content.split('\t')
  20. boxes_flatten = []
  21. for i in num_list:
  22. boxes_flatten.append(int(i))
  23. boxes_flatten = np.array(boxes_flatten)
  24. boxes = boxes_flatten.reshape((len(all_img_path),-1, 9))
  25. with open(text_tag_rec_file,'r') as f:
  26. all_text_tags = []
  27. file_content = f.readlines()
  28. for i in file_content:
  29. all_text_tags.append(i.split('\t**hegd**\t')[:-1])
  30. return all_img_path,boxes,all_text_tags