Skip to content

Commit

Permalink
二维码识别HTTP接口:支持传入预处理参数"options" (#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroi-sora committed May 21, 2024
1 parent c78fc7c commit 3a10cf4
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions UmiOCR-data/py_src/server/qrcode_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
from ..mission.mission_qrcode import MissionQRCode


# 从base64识别二维码图片。传入base64字符串,返回字典 {"code", "data"}
def base2text(base64):
res = MissionQRCode.addMissionWait({}, [{"base64": base64}])
# 从base64识别二维码图片。传入data指令字典 {"base64", "options"}
# 返回字典 {"code", "data"}
def base2text(data):
base64 = data["base64"]
opt = data.get("options", {})
res = MissionQRCode.addMissionWait(opt, [{"base64": base64}])
return res[0]["result"]


# 从文本生成base64。传入data指令字典 {"text","xxx"}
# 从文本生成base64。传入data指令字典 {"text", "xxx"}
# 返回 {"code", "data"}
def text2base(data):
text = data["text"]
Expand Down Expand Up @@ -46,7 +49,7 @@ def _qrcode():
return json.dumps({"code": 801, "data": f"请求为空。"})

if "base64" in data:
return json.dumps(base2text(data["base64"]))
return json.dumps(base2text(data))
elif "text" in data:
return json.dumps(text2base(data))
return json.dumps({"code": 802, "data": '指令中不存在 "base64" 或 "text"'})
Expand Down

0 comments on commit 3a10cf4

Please sign in to comment.