代码拉取完成,页面将自动刷新
同步操作将从 sml2h3/ocr_api_server 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/python3.6
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021 #
# @Time : 2022/1/6 23:28
# @Author : sml2h3
# @Email : sml2h3@gmail.com
# @File : test_api.py
# @Software: PyCharm
import base64
import json
import requests
print(' ')
# ******************OCR识别部分开始******************
host = "http://127.0.0.1:9898"
# 目标检测就把ocr改成det,其他相同
# 方式一
file = open(r'test.jpg', 'rb').read()
# file = open(r'test_calc.png', 'rb').read()
api_url = f"{host}/ocr/file"
resp = requests.post(api_url, files={'image': file})
print(f"{api_url=}, {resp.text=}")
api_url = f"{host}/ocr/file/json"
resp = requests.post(api_url, files={'image': file})
print(f"{api_url=}, {resp.text=}")
api_url = f"{host}/ocr/b64"
resp = requests.post(api_url, data=base64.b64encode(file).decode())
print(f"{api_url=}, {resp.text=}")
api_url = f"{host}/ocr/b64/json"
resp = requests.post(api_url, data=base64.b64encode(file).decode())
print(f"{api_url=}, {resp.text=}")
api_url = f"{host}/det/file"
resp = requests.post(api_url, files={'image': file})
print(f"{api_url=}, {resp.text=}")
api_url = f"{host}/det/file/json"
resp = requests.post(api_url, files={'image': file})
print(f"{api_url=}, {resp.text=}")
# 滑块识别
target_file = open(r'match_target.png', 'rb').read()
bg_file = open(r'match_bg.png', 'rb').read()
api_url = f"{host}/slide/match/file"
resp = requests.post(api_url, files={'target_img': target_file, 'bg_img': bg_file})
print(f"{api_url=}, {resp.text=}")
api_url = f"{host}/slide/match/file/json"
resp = requests.post(api_url, files={'target_img': target_file, 'bg_img': bg_file})
print(f"{api_url=}, {resp.text=}")
api_url = f"{host}/slide/match/b64"
target_b64str = base64.b64encode(target_file).decode()
bg_b64str = base64.b64encode(bg_file).decode()
jsonstr = json.dumps({'target_img': target_b64str, 'bg_img': bg_b64str})
resp = requests.post(api_url, data=base64.b64encode(jsonstr.encode()).decode())
print(f"{api_url=}, {resp.text=}")
api_url = f"{host}/slide/match/b64/json"
resp = requests.post(api_url, data=base64.b64encode(jsonstr.encode()).decode())
print(f"{api_url=}, {resp.text=}")
target_file = open(r'compare_target.jpg', 'rb').read()
bg_file = open(r'compare_bg.jpg', 'rb').read()
api_url = f"{host}/slide/compare/file"
resp = requests.post(api_url, files={'target_img': target_file, 'bg_img': bg_file})
print(f"{api_url=}, {resp.text=}")
api_url = f"{host}/slide/compare/file/json"
resp = requests.post(api_url, files={'target_img': target_file, 'bg_img': bg_file})
print(f"{api_url=}, {resp.text=}")
api_url = f"{host}/slide/compare/b64"
target_b64str = base64.b64encode(target_file).decode()
bg_b64str = base64.b64encode(bg_file).decode()
jsonstr = json.dumps({'target_img': target_b64str, 'bg_img': bg_b64str})
resp = requests.post(api_url, data=base64.b64encode(jsonstr.encode()).decode())
print(f"{api_url=}, {resp.text=}")
api_url = f"{host}/slide/compare/b64/json"
resp = requests.post(api_url, data=base64.b64encode(jsonstr.encode()).decode())
print(f"{api_url=}, {resp.text=}")
# 方式二
# 获取验证码图片
# headers = {
# "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
# "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4195.1 Safari/537.36"
# }
# resp = requests.get('https://data.gdcic.net/Dop/CheckCode.aspx?codemark=408.15173910730016', headers=headers, verify=False)
# captcha_img = resp.content
#
# 识别
# resp = requests.post(api_url, files={'image': captcha_img})
# print('验证码结果', resp.text)
#
# # 保存验证码图片以供验证
# with open('captcha.jpg', 'wb') as f:
# f.write(captcha_img)
# ******************OCR识别部分开始******************
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。