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申请得到。

相关推荐
水境传感 李兆栋1 分钟前
无需走航!水平固定式 ADCP 实现河道连续测流
人工智能
yume_sibai1 分钟前
07-Rust 异步编程完全指南(async/await + Tokio + Future + 并发原语 + 异步流)
开发语言·后端·rust
Sylvia33.4 分钟前
板球实时数据接入实战:从Frames模型到多赛制适配
java·python·websocket·网络协议·架构
PILIPALAPENG5 分钟前
把 DeepSeek Agent(dsh)部署上云记录
人工智能
zy_destiny5 分钟前
豆包赋能抖音内容创作与运营实战指南
人工智能
linx2957 分钟前
单元七 · 零基础路线图-第 1–3 周·变量、类型与字符串
c语言·开发语言·数据结构·c++·算法
X54先生(人文科技)8 分钟前
《元创力》纪实录 · 卷宗 3.5-C《协议的形状——ELR体系第一份商业合同的形成全记录》
人工智能·深度学习·架构·ai写作·开源协议
GitCode官方9 分钟前
小鸿 AI 语音案例正式上线海思案例中心!首个适配 OpenHarmony 7.0 Release 全栈开源 AI 硬件
人工智能·开源·atomgit
昇腾知识体系11 分钟前
昇腾 Atlas 800I A5 服务器:机型定位与部署入口
服务器·人工智能·华为·架构·知识图谱
2601_9539880712 分钟前
Ricon组态 - 让数据可视化如此简单
运维·后端·物联网·数学建模·前端框架·c4前端