python识别图像中的文字

 

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


import easyocr

# 创建reader对象
import json
reader = easyocr.Reader(['en'])
result_list = reader.readtext('review2.png')
def use_result_list_to_recentangle(result_list):
    pos_list = []
    text_list = []
    for sample in result_list:
        if int(sample[0][1][0])>560:
            pos_list.append(sample[0])
            text_list.append(sample[1])
    return pos_list,text_list

def get_important_information(pos_list,text_list):
    tmp_sample = {}
    content = ''
    all_samples = []
    flag = 'review_background'
    for index in range(len(text_list)):
        if 'Reviewed in the' in text_list[index]:
            place = text_list[index]
            title = text_list[index-1]
            tmp_sample['title'] = title
            tmp_sample['place'] = place
            
        if 'Color' in text_list[index]:
            color = text_list[index]
            tmp_sample['color'] = color
        if flag == 'content':
            content += text_list[index]
        if 'Purchase' in text_list[index]:
            Verify_purchase = text_list[index]
            tmp_sample['Verify_purchase'] = Verify_purchase
            flag = 'content'

        if 'Helpful' == text_list[index]:
            flag = 'review_background'
            tmp_sample['content'] = content
            all_samples.append(tmp_sample)
            content = ''
            tmp_sample = {}
    return all_samples

            

pos_list,text_list = use_result_list_to_recentangle(result_list)
all_samples = get_important_information(pos_list,text_list)
json_path = '/cloud/cloud_disk/users/huh/nlp/vision-reptile/vision_reptile/data/result.json'
out_file = open(json_path, "w")
json.dump(all_samples, out_file, indent=6)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值