简单的文字OCR webservice

环境依赖参考
https://blog.csdn.net/weixin_41735238/article/details/106734060

服务端service.py

import os
import urllib
import uuid

import requests
from spyne.application import Application
from spyne.decorator import rpc
from spyne import ServiceBase, String
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication
from wsgiref.simple_server import make_server
from paddleocr import PaddleOCR, draw_ocr
file_path = 'd:/img/'

def downimg(image_url):
    try:
        if not os.path.exists(file_path):
            os.makedirs(file_path)
        filename = '{}{}{}'.format(file_path, uuid.uuid1(),'.jpg')
        res = requests.get(image_url)
        with open(filename, 'wb') as f:
           f.write(res.content)
        return filename
    except Exception as e:
        print(e)
        return ''

def toOCR(img_path):
    try:
        ocr = PaddleOCR(use_angle_cls=True,use_gpu=False)
        print(img_path)
        result = ocr.ocr(img_path, cls=True)
        return str(result)
    except Exception as ex:
         print(ex)
         return 0

class Test(ServiceBase):
    @rpc(String,  _returns=String)
    def get_data(self, url):
        img_path=downimg(url)
        post_data=toOCR(img_path)
        return post_data


app = Application([Test], 'http://schemas.xmlsoap.org/soap/envelope',in_protocol=Soap11(validator='lxml'), out_protocol=Soap11())
wsgi_app = WsgiApplication(app)

if __name__ == '__main__':
    server = make_server('0.0.0.0', 8088, wsgi_app )
    server.serve_forever()

请求端 customer.py

# coding:utf-8
import suds
from suds.client import Client

url = "http://127.0.0.1:8088/sbcsxt/services/GetMethods?wsdl"
client = suds.client.Client(url)
result = client.service.get_data('https://pic.ntimg.cn/file/20210629/25266409_142727125104_2.jpg')
print(result)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值