当前位置:   article > 正文

python识别图像中的文字_python识别图片上的文本

python识别图片上的文本

 

 我们想识别图像中对我们有用的评论,所以需要卡一个阈值来仅仅获得对我们有用的信息

  1. import easyocr
  2. # 创建reader对象
  3. import json
  4. reader = easyocr.Reader(['en'])
  5. result_list = reader.readtext('review2.png')
  6. def use_result_list_to_recentangle(result_list):
  7. pos_list = []
  8. text_list = []
  9. for sample in result_list:
  10. if int(sample[0][1][0])>560:
  11. pos_list.append(sample[0])
  12. text_list.append(sample[1])
  13. return pos_list,text_list
  14. def get_important_information(pos_list,text_list):
  15. tmp_sample = {}
  16. content = ''
  17. all_samples = []
  18. flag = 'review_background'
  19. for index in range(len(text_list)):
  20. if 'Reviewed in the' in text_list[index]:
  21. place = text_list[index]
  22. title = text_list[index-1]
  23. tmp_sample['title'] = title
  24. tmp_sample['place'] = place
  25. if 'Color' in text_list[index]:
  26. color = text_list[index]
  27. tmp_sample['color'] = color
  28. if flag == 'content':
  29. content += text_list[index]
  30. if 'Purchase' in text_list[index]:
  31. Verify_purchase = text_list[index]
  32. tmp_sample['Verify_purchase'] = Verify_purchase
  33. flag = 'content'
  34. if 'Helpful' == text_list[index]:
  35. flag = 'review_background'
  36. tmp_sample['content'] = content
  37. all_samples.append(tmp_sample)
  38. content = ''
  39. tmp_sample = {}
  40. return all_samples
  41. pos_list,text_list = use_result_list_to_recentangle(result_list)
  42. all_samples = get_important_information(pos_list,text_list)
  43. json_path = '/cloud/cloud_disk/users/huh/nlp/vision-reptile/vision_reptile/data/result.json'
  44. out_file = open(json_path, "w")
  45. json.dump(all_samples, out_file, indent=6)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/295981
推荐阅读
相关标签
  

闽ICP备14008679号