你是否曾因社保卡,一头变得两个大。现在不用再愁啦,一行代码解决它。【pobd】 你的办公好帮手。

一、1行代码,体验魔法

pobd.ocr2excel.social_security_card(img_path=input_file,output_excel_path=output_file,api_key=api_key,secret_key=secret_key)

只需要上面这行代码,就能实现识别社保卡信息 + 生成excel 表格。不知道怎么申请百度API接口的 api_keysecret_key 的伙伴们,可以留言找我哦!

它是怎么做到的呢,接下来让我们揭开它神秘面纱吧。

二、抽丝剥茧,探寻根源

*1、首先我们选用的是 百度OCR接口**
`

    base64_image = self.image_to_base64(img_path)
    request_url = f"https://aip.baidubce.com/rest/2.0/ocr/v1/social_security_card?access_token={self.access_token}"
    headers = {'Content-Type': 'application/x-www-form-urlencoded'}
    data = {
        "image": base64_image
    }
    response = requests.post(request_url, headers=headers, data=data)
    return response.json()`
    
    

    

response 就是我们想要得到的信息了。不过现在得到的信息还比较混杂,需要进一步处理。

*2、使用pandas 组织数据**

df = pd.DataFrame(result_df)

df 就是使用pandas 把数据转换为 DataFrame。这样得到的信息不仅清晰,而且还有一个用处,那就是...

*3、存为 excel 表格**

s_output_excel), index=False, engine='openpyxl')

有了 DataFrame ,我们就能很轻易的写入 excel 表格了。

三、效果展示

我们还使用了进度条,可以实时了解工作进度。

community_476e8db.png

最后,就是我们的excel 表格展示啦。

community_5e2bc74.png

相关阅读

程序员晚枫专注AI编程培训,小白看完他和图灵社区合作的教程《30讲 · AI编程训练营》就能上手做AI项目。

🎓 AI 编程实战课程

想系统学习 AI 编程?程序员晚枫的 AI 编程实战课 帮你从零上手!