Power Automate快速使用ocr接口

使用Power Automate 需要账户登录经常会有验证码设置,每次都是手动输入比较复杂!网上找到了开源的ocr 效率速度等都不错,而且搭建相当简单快速

建议使用Docker安装如果使用linux或者win的服务器安装将会比较麻烦

学习视频:

【全网独家】借免费开源AI训练后OCR功能秒杀网页验证码
https://www.bilibili.com/video/BV1Wq4y1a78k?spm_id_from=333.999.0.0

准备工作

  • 宝塔面板
  • Docker管理器 3.7
  • postman
  • Power Automate

Docker安装

直接将下列代码放入putty运行即可

git clone https://github.com/sml2h3/ocr_api_server.git
# docker怎么安装?百度吧

cd ocr_api_server

# 修改entrypoint.sh中的参数,具体参数往上翻,默认9898端口,同时开启ocr模块以及目标检测模块

# 编译镜像
docker build -t ocr_server:v1 .

# 运行镜像
docker run -p 9898:9898 -d ocr_server:v1

测试是否启动成功,可以通过直接GET访问http://{host}:{port}/ping来测试,如果返回pong则启动成功

这里我们需要在你的云服务器内允许相关的端口9898

接口信息

# 2、OCR/目标检测请求接口格式:

# http://{host}:{port}/{opt}/{img_type}/{ret_type}
# opt:操作类型 ocr=OCR det=目标检测 slide=滑块(match和compare两种算法,默认为compare)
# img_type: 数据类型 file=文件上传方式 b64=base64(imgbyte)方式 默认为file方式
# ret_type: 返回类型 json=返回json(识别出错会在msg里返回错误信息) text=返回文本格式(识别出错时回直接返回空文本)

# 例子:

# OCR请求
# resp = requests.post("http://{host}:{port}/ocr/file", files={'image': image_bytes})
# resp = requests.post("http://{host}:{port}/ocr/b64/text", data=base64.b64encode(file).decode())

# 目标检测请求
# resp = requests.post("http://{host}:{port}/det/file", files={'image': image_bytes})
# resp = requests.post("http://{host}:{port}/ocr/b64/json", data=base64.b64encode(file).decode())

# 滑块识别请求
# resp = requests.post("http://{host}:{port}/slide/match/file", files={'target_img': target_bytes, 'bg_img': bg_bytes})
# jsonstr = json.dumps({'target_img': target_b64str, 'bg_img': bg_b64str})
# resp = requests.post("http://{host}:{port}/slide/compare/b64", files=base64.b64encode(jsonstr.encode()).decode())

Postman调试

如下图进行调试

当最后结果输出ocr结果则接口测试成功

Power Automate设置

我们在Power Automate 使用本地base64

使用调用web服务=>勾选高级=>接收不信任的证书

Web.InvokeWebService.InvokeWebService Url: $'''http://81.70.157.183:9898/ocr/b64/text''' Method: Web.Method.Post Accept: $'''application/json''' ContentType: $'''application/json''' RequestBody: Base64Text ConnectionTimeout: 30 FollowRedirection: True ClearCookies: True FailOnErrorStatus: False EncodeRequestBody: False UserAgent: $'''Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.21) Gecko/20100312 Firefox/3.6''' Encoding: Web.Encoding.AutoDetect AcceptUntrustedCertificates: True ResponseHeaders=> WebServiceResponseHeaders Response=> WebServiceResponse StatusCode=> StatusCode

# [ControlRepository][PowerAutomateDesktop]

{
  "ControlRepositorySymbols": [],
  "ImageRepositorySymbol": {
    "Name": "imgrepo",
    "ImportMetadata": {},
    "Repository": "{\r\n  \"Folders\": [],\r\n  \"Images\": [],\r\n  \"Version\": 1\r\n}"
  }
}

 

 

 

相关推荐

Power Automate了解变量

在开发流程时,通常会在多个操作中重用信息并根据特定条件对其进行更新。例如,您可能需要存储这些变量并稍后在流程中 ...