首页 > 其他分享 >py之使用umi_ocr实现本地ocr识别功能

py之使用umi_ocr实现本地ocr识别功能

时间:2025-02-04 16:57:49浏览次数:11  
标签:base64 url data self py json file ocr umi


import requests
import json
import base64


class OCRClientTool:
    def __init__(self, url):
        self.url = url

    def get_ocr_result(self, file_path):
        # 读取文件内容并编码为base64字符串
        with open(file_path, "rb") as image_file:
            encoded_string = base64.b64encode(image_file.read()).decode('utf-8')

        # 准备请求数据
        data = {
            "base64": encoded_string,
            "options": {
                "data.format": "text",
            }
        }


        # 发送POST请求
        try:
            response = requests.post(self.url, json=data)
            response.raise_for_status()  # 检查请求是否成功
            res_dict = json.loads(response.text)
            return res_dict['data'

标签:base64,url,data,self,py,json,file,ocr,umi
From: https://blog.csdn.net/qq_45662588/article/details/145428630

相关文章