python请求文字识别ocr api

python请求文字识别ocr api

支持免费在线体验,API文档清晰,提供多重语言案例

以下是用python请求文字识别ocr api的代码:

python 复制代码
# API文档网址:https://market.shiliuai.com/doc/advanced-general-ocr
# -*- coding: utf-8 -*-

import requests
import base64
import json
        
# 请求接口
URL = "https://ocr-api.shiliuai.com/api/general_ocr/v1"
        
# 图片转base64
def get_base64(file_path):
    with open(file_path, 'rb') as f:
        data = f.read()
    b64 = base64.b64encode(data).decode('utf8')
    return b64
        
        
def demo(appcode, file_path):
    # 请求头
    headers = {
        'Authorization': 'APPCODE %s' % appcode,
        'Content-Type': 'application/json'
    }
        
    # 请求体
    b64 = get_base64(file_path)
    data = {"image_base64": b64}
        
    # 请求
    response = requests.post(url=URL, headers=headers, json=data)
    content = json.loads(response.content)
    print(content)
        
if __name__ == "__main__":
    appcode = "你的APPCODE"
    file_path = "本地图片路径"
    demo(appcode, file_path) 
          

其中appcode可以到market.shiliuai.com申请得到。

相关推荐
DeniuHe1 分钟前
sklearn 中所有交叉验证数据集划分方式完整总结
人工智能·python·sklearn
DeniuHe5 分钟前
sklearn中不同交叉验证方法的场景适配
人工智能·python·sklearn
小新同学^O^6 分钟前
简单学习 --> 指令微调
人工智能·学习·llm·指令微调
知识浅谈11 分钟前
Transformer 中的 Q、K、V 到底是什么?怎么理解 Query、Key、Value?
人工智能·深度学习·transformer
名不经传的养虾人11 分钟前
从0到1:企业级AI项目迭代日记 Vol.36|临时方案下线,网关区分负载,用量穿透链路——这一周全是“归位”
人工智能·ai编程·ai工作流·企业ai·多agent协作
小程故事多_8013 分钟前
拆解Hermes Agent技术架构,会自我迭代的开源智能体如何突破AI传统局限
人工智能·架构·开源
黎阳之光14 分钟前
数智透明·安全兜底|黎阳之光透明矿山,AI+数字孪生守护矿山生命线
人工智能·物联网·算法·安全·数字孪生
小新11015 分钟前
qt creator 将qInfo的输出日志写入日志文档,方便查看
开发语言·qt
Bigger15 分钟前
mini-cc 的 MCP 协议:给 AI 装个 USB-C 接口
人工智能·ai编程·claude
AI_yangxi18 分钟前
短视频矩阵系统哪个稳定
大数据·人工智能·矩阵