init: 项目初始化
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +25 -0
- timi_hok_game_translator/.gitattributes +1 -0
- timi_hok_game_translator/.gitignore +14 -0
- timi_hok_game_translator/GameTrans_EvalSet/AI评测集正式版4500条.xlsx +3 -0
- timi_hok_game_translator/LICENSE.txt +210 -0
- timi_hok_game_translator/LQA_WMP/.env.example +60 -0
- timi_hok_game_translator/LQA_WMP/.gitattributes +8 -0
- timi_hok_game_translator/LQA_WMP/.gitignore +38 -0
- timi_hok_game_translator/LQA_WMP/CONTRIBUTING.md +48 -0
- timi_hok_game_translator/LQA_WMP/LICENSE +210 -0
- timi_hok_game_translator/LQA_WMP/README.md +119 -0
- timi_hok_game_translator/LQA_WMP/docker-compose.yml +110 -0
- timi_hok_game_translator/LQA_WMP/docs/api/bug.md +250 -0
- timi_hok_game_translator/LQA_WMP/docs/api/data.md +93 -0
- timi_hok_game_translator/LQA_WMP/docs/api/image.md +201 -0
- timi_hok_game_translator/LQA_WMP/docs/api/job.md +299 -0
- timi_hok_game_translator/LQA_WMP/docs/api/overview.md +121 -0
- timi_hok_game_translator/LQA_WMP/docs/api/project.md +174 -0
- timi_hok_game_translator/LQA_WMP/docs/api/system.md +122 -0
- timi_hok_game_translator/LQA_WMP/docs/api/user.md +292 -0
- timi_hok_game_translator/LQA_WMP/docs/deploy-guide.md +298 -0
- timi_hok_game_translator/LQA_WMP/docs/integration/restorer.md +291 -0
- timi_hok_game_translator/LQA_WMP/docs/web-guide.md +492 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/.gitignore +21 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/Dockerfile +48 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/README.md +350 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/common/interface_ocr.py +107 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/common/log.py +27 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/common/ocr_provider/__init__.py +152 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/common/ocr_provider/base.py +105 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/common/ocr_provider/cloud.py +188 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/common/ocr_provider/cvtest.py +88 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/common/ocr_provider/local_engines.py +158 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/common/ocr_provider/paddle.py +121 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/common/tools.py +68 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/common/util_network.py +25 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/config/baseconfig.py +153 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/config/gunicorn_config.py +23 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/deploy/run_gunicorn.sh +5 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/handles/handle_lqa.py +120 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/portal.py +25 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/requirements.txt +29 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/task/image_processing.py +153 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/task/lqa.py +278 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/task/lqa_abnormal.py +1029 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/task/lqa_config.py +53 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/task/lqa_processing.py +638 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/task/lqa_supervised.py +258 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/tests/batch_test_lqa.py +107 -0
- timi_hok_game_translator/LQA_WMP/lqa_service/tests/check_ocr.py +66 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,28 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
timi_hok_game_translator/GameTrans_EvalSet/AI评测集正式版4500条.xlsx filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
timi_hok_game_translator/LQA_WMP/web/public/favicon.ico filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
timi_hok_game_translator/LQA_WMP/web/src/assets/layouts/logo-text-1.png filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
timi_hok_game_translator/LQA_WMP/web/src/assets/layouts/logo-text-2-back.png filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
timi_hok_game_translator/LQA_WMP/web/src/assets/layouts/logo-text-2.png filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
timi_hok_game_translator/LQA_WMP/web/src/assets/layouts/logo.png filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
timi_hok_game_translator/Unity_LQARestore_Plugin/docs/images/restore_auto_pipeline.png filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
timi_hok_game_translator/Unity_LQARestore_Plugin/docs/images/restore_filter_config.png filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
timi_hok_game_translator/Unity_LQARestore_Plugin/docs/images/restore_full_vs_restore.png filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
timi_hok_game_translator/Unity_LQARestore_Plugin/docs/images/restore_platform_connection.png filter=lfs diff=lfs merge=lfs -text
|
| 46 |
+
timi_hok_game_translator/Unity_LQARestore_Plugin/docs/images/restore_pull_data.png filter=lfs diff=lfs merge=lfs -text
|
| 47 |
+
timi_hok_game_translator/Unity_LQARestore_Plugin/docs/images/restore_scene.png filter=lfs diff=lfs merge=lfs -text
|
| 48 |
+
timi_hok_game_translator/Unity_LQARestore_Plugin/docs/images/restore_submit.png filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
timi_hok_game_translator/Unity_LQARestore_Plugin/docs/images/restore_text_show.png filter=lfs diff=lfs merge=lfs -text
|
| 50 |
+
timi_hok_game_translator/Unity_LQARestore_Plugin/docs/images/restore_translation_font_config.png filter=lfs diff=lfs merge=lfs -text
|
| 51 |
+
timi_hok_game_translator/Unity_LQARestore_Plugin/docs/images/restore_upload_data.png filter=lfs diff=lfs merge=lfs -text
|
| 52 |
+
timi_hok_game_translator/Unity_LQATool_Plugin/docs/images/usage_full_vs_notext.png filter=lfs diff=lfs merge=lfs -text
|
| 53 |
+
timi_hok_game_translator/Unity_LQATool_Plugin/docs/images/usage_getnode_on.png filter=lfs diff=lfs merge=lfs -text
|
| 54 |
+
timi_hok_game_translator/Unity_LQATool_Plugin/docs/images/usage_getnode_panel.png filter=lfs diff=lfs merge=lfs -text
|
| 55 |
+
timi_hok_game_translator/Unity_LQATool_Plugin/docs/images/usage_output_folder.png filter=lfs diff=lfs merge=lfs -text
|
| 56 |
+
timi_hok_game_translator/Unity_LQATool_Plugin/docs/images/usage_textid.png filter=lfs diff=lfs merge=lfs -text
|
| 57 |
+
timi_hok_game_translator/Unity_LQATool_Plugin/docs/images/usage_tool_buttons.png filter=lfs diff=lfs merge=lfs -text
|
| 58 |
+
timi_hok_game_translator/Unity_LQATool_Plugin/docs/images/usage_visdebug.png filter=lfs diff=lfs merge=lfs -text
|
| 59 |
+
timi_hok_game_translator/video/工具链演示视频.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
+
timi_hok_game_translator/video/LQA演示视频.mp4 filter=lfs diff=lfs merge=lfs -text
|
timi_hok_game_translator/.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
/video/LQA演示视频.mp4 filter=lfs diff=lfs merge=lfs -text
|
timi_hok_game_translator/.gitignore
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IDE
|
| 2 |
+
.idea/
|
| 3 |
+
|
| 4 |
+
# 临时补丁 / 本地工具文件
|
| 5 |
+
fix__修改开源协议.patch
|
| 6 |
+
|
| 7 |
+
# Python
|
| 8 |
+
__pycache__/
|
| 9 |
+
*.py[cod]
|
| 10 |
+
.venv/
|
| 11 |
+
venv/
|
| 12 |
+
env/
|
| 13 |
+
.pytest_cache/
|
| 14 |
+
.mypy_cache/
|
timi_hok_game_translator/GameTrans_EvalSet/AI评测集正式版4500条.xlsx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:67954214e490f2308f5bdaa2df0e189f20712c87589cd874cfcfc0d2d2ab6eab
|
| 3 |
+
size 527746
|
timi_hok_game_translator/LICENSE.txt
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Tencent is pleased to support the open source community by making TiMi HOK Game Translator available.
|
| 2 |
+
|
| 3 |
+
Copyright (C) 2026 Tencent. All rights reserved.
|
| 4 |
+
|
| 5 |
+
TiMi HOK Game Translator is licensed under the Apache-2.0.
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
Terms of the Apache-2.0:
|
| 9 |
+
--------------------------------------------------------------------
|
| 10 |
+
Apache License
|
| 11 |
+
Version 2.0, January 2004
|
| 12 |
+
http://www.apache.org/licenses/
|
| 13 |
+
|
| 14 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 15 |
+
|
| 16 |
+
1. Definitions.
|
| 17 |
+
|
| 18 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 19 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 20 |
+
|
| 21 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 22 |
+
the copyright owner that is granting the License.
|
| 23 |
+
|
| 24 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 25 |
+
other entities that control, are controlled by, or are under common
|
| 26 |
+
control with that entity. For the purposes of this definition,
|
| 27 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 28 |
+
direction or management of such entity, whether by contract or
|
| 29 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 30 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 31 |
+
|
| 32 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 33 |
+
exercising permissions granted by this License.
|
| 34 |
+
|
| 35 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 36 |
+
including but not limited to software source code, documentation
|
| 37 |
+
source, and configuration files.
|
| 38 |
+
|
| 39 |
+
"Object" form shall mean any form resulting from mechanical
|
| 40 |
+
transformation or translation of a Source form, including but
|
| 41 |
+
not limited to compiled object code, generated documentation,
|
| 42 |
+
and conversions to other media types.
|
| 43 |
+
|
| 44 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 45 |
+
Object form, made available under the License, as indicated by a
|
| 46 |
+
copyright notice that is included in or attached to the work
|
| 47 |
+
(an example is provided in the Appendix below).
|
| 48 |
+
|
| 49 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 50 |
+
form, that is based on (or derived from) the Work and for which the
|
| 51 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 52 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 53 |
+
of this License, Derivative Works shall not include works that remain
|
| 54 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 55 |
+
the Work and Derivative Works thereof.
|
| 56 |
+
|
| 57 |
+
"Contribution" shall mean any work of authorship, including
|
| 58 |
+
the original version of the Work and any modifications or additions
|
| 59 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 60 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 61 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 62 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 63 |
+
means any form of electronic, verbal, or written communication sent
|
| 64 |
+
to the Licensor or its representatives, including but not limited to
|
| 65 |
+
communication on electronic mailing lists, source code control systems,
|
| 66 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 67 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 68 |
+
excluding communication that is conspicuously marked or otherwise
|
| 69 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 70 |
+
|
| 71 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 72 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 73 |
+
subsequently incorporated within the Work.
|
| 74 |
+
|
| 75 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 76 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 77 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 78 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 79 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 80 |
+
Work and such Derivative Works in Source or Object form.
|
| 81 |
+
|
| 82 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 83 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 84 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 85 |
+
(except as stated in this section) patent license to make, have made,
|
| 86 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 87 |
+
where such license applies only to those patent claims licensable
|
| 88 |
+
by such Contributor that are necessarily infringed by their
|
| 89 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 90 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 91 |
+
institute patent litigation against any entity (including a
|
| 92 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 93 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 94 |
+
or contributory patent infringement, then any patent licenses
|
| 95 |
+
granted to You under this License for that Work shall terminate
|
| 96 |
+
as of the date such litigation is filed.
|
| 97 |
+
|
| 98 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 99 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 100 |
+
modifications, and in Source or Object form, provided that You
|
| 101 |
+
meet the following conditions:
|
| 102 |
+
|
| 103 |
+
(a) You must give any other recipients of the Work or
|
| 104 |
+
Derivative Works a copy of this License; and
|
| 105 |
+
|
| 106 |
+
(b) You must cause any modified files to carry prominent notices
|
| 107 |
+
stating that You changed the files; and
|
| 108 |
+
|
| 109 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 110 |
+
that You distribute, all copyright, patent, trademark, and
|
| 111 |
+
attribution notices from the Source form of the Work,
|
| 112 |
+
excluding those notices that do not pertain to any part of
|
| 113 |
+
the Derivative Works; and
|
| 114 |
+
|
| 115 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 116 |
+
distribution, then any Derivative Works that You distribute must
|
| 117 |
+
include a readable copy of the attribution notices contained
|
| 118 |
+
within such NOTICE file, excluding those notices that do not
|
| 119 |
+
pertain to any part of the Derivative Works, in at least one
|
| 120 |
+
of the following places: within a NOTICE text file distributed
|
| 121 |
+
as part of the Derivative Works; within the Source form or
|
| 122 |
+
documentation, if provided along with the Derivative Works; or,
|
| 123 |
+
within a display generated by the Derivative Works, if and
|
| 124 |
+
wherever such third-party notices normally appear. The contents
|
| 125 |
+
of the NOTICE file are for informational purposes only and
|
| 126 |
+
do not modify the License. You may add Your own attribution
|
| 127 |
+
notices within Derivative Works that You distribute, alongside
|
| 128 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 129 |
+
that such additional attribution notices cannot be construed
|
| 130 |
+
as modifying the License.
|
| 131 |
+
|
| 132 |
+
You may add Your own copyright statement to Your modifications and
|
| 133 |
+
may provide additional or different license terms and conditions
|
| 134 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 135 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 136 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 137 |
+
the conditions stated in this License.
|
| 138 |
+
|
| 139 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 140 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 141 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 142 |
+
this License, without any additional terms or conditions.
|
| 143 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 144 |
+
the terms of any separate license agreement you may have executed
|
| 145 |
+
with Licensor regarding such Contributions.
|
| 146 |
+
|
| 147 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 148 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 149 |
+
except as required for reasonable and customary use in describing the
|
| 150 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 151 |
+
|
| 152 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 153 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 154 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 155 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 156 |
+
implied, including, without limitation, any warranties or conditions
|
| 157 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 158 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 159 |
+
appropriateness of using or redistributing the Work and assume any
|
| 160 |
+
risks associated with Your exercise of permissions under this License.
|
| 161 |
+
|
| 162 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 163 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 164 |
+
unless required by applicable law (such as deliberate and grossly
|
| 165 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 166 |
+
liable to You for damages, including any direct, indirect, special,
|
| 167 |
+
incidental, or consequential damages of any character arising as a
|
| 168 |
+
result of this License or out of the use or inability to use the
|
| 169 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 170 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 171 |
+
other commercial damages or losses), even if such Contributor
|
| 172 |
+
has been advised of the possibility of such damages.
|
| 173 |
+
|
| 174 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 175 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 176 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 177 |
+
or other liability obligations and/or rights consistent with this
|
| 178 |
+
License. However, in accepting such obligations, You may act only
|
| 179 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 180 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 181 |
+
defend, and hold each Contributor harmless for any liability
|
| 182 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 183 |
+
of your accepting any such warranty or additional liability.
|
| 184 |
+
|
| 185 |
+
END OF TERMS AND CONDITIONS
|
| 186 |
+
|
| 187 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 188 |
+
|
| 189 |
+
To apply the Apache License to your work, attach the following
|
| 190 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 191 |
+
replaced with your own identifying information. (Don't include
|
| 192 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 193 |
+
comment syntax for the file format. We also recommend that a
|
| 194 |
+
file or class name and description of purpose be included on the
|
| 195 |
+
same "printed page" as the copyright notice for easier
|
| 196 |
+
identification within third-party archives.
|
| 197 |
+
|
| 198 |
+
Copyright [yyyy] [name of copyright owner]
|
| 199 |
+
|
| 200 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 201 |
+
you may not use this file except in compliance with the License.
|
| 202 |
+
You may obtain a copy of the License at
|
| 203 |
+
|
| 204 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 205 |
+
|
| 206 |
+
Unless required by applicable law or agreed to in writing, software
|
| 207 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 208 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 209 |
+
See the License for the specific language governing permissions and
|
| 210 |
+
limitations under the License.
|
timi_hok_game_translator/LQA_WMP/.env.example
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# docker compose 部署配置: cp .env.example .env 后修改
|
| 2 |
+
|
| 3 |
+
# 以下密码/密钥必须修改为随机值
|
| 4 |
+
# 生成方式: python -c "import secrets;print(secrets.token_urlsafe(32))"
|
| 5 |
+
MYSQL_ROOT_PASSWORD=change-me-root
|
| 6 |
+
MYSQL_PASSWORD=change-me-lqa
|
| 7 |
+
REDIS_PASSWORD=change-me-redis
|
| 8 |
+
SECRET_KEY=change-me-to-a-long-random-string
|
| 9 |
+
|
| 10 |
+
# 首次启动自动创建的超级管理员 (已存在超管时不会覆盖)
|
| 11 |
+
LQA_ADMIN_USERNAME=admin
|
| 12 |
+
LQA_ADMIN_PASSWORD=ChangeMe123456
|
| 13 |
+
|
| 14 |
+
# 对外端口与访问地址 (缺陷中的截图链接、Webhook 变量 {{lqa_server}} 使用)
|
| 15 |
+
LQA_HTTP_PORT=8080
|
| 16 |
+
PUBLIC_URL=http://localhost:8080
|
| 17 |
+
|
| 18 |
+
# 是否开放自助注册 (注册后需管理员分配项目)
|
| 19 |
+
ALLOW_REGISTER=true
|
| 20 |
+
# HTTPS 部署时开启
|
| 21 |
+
SESSION_COOKIE_SECURE=false
|
| 22 |
+
# 截图是否允许匿名访问 (使用禅道且需要在禅道中直接显示截图时开启)
|
| 23 |
+
MEDIA_PUBLIC=false
|
| 24 |
+
|
| 25 |
+
# ---------------------------------------------------------------
|
| 26 |
+
# AI 识别服务
|
| 27 |
+
# ---------------------------------------------------------------
|
| 28 |
+
|
| 29 |
+
# 留空则自动使用随本编排启动的 ai 服务 (http://ai:8086)
|
| 30 |
+
# 若已有独立部署的识别服务, 填写其地址即可, 此时可用
|
| 31 |
+
# docker compose up -d --scale ai=0 跳过本地 ai 容器
|
| 32 |
+
AI_BASE_URL=
|
| 33 |
+
|
| 34 |
+
# 镜像内置的 OCR 引擎 (构建期生效)
|
| 35 |
+
# rapidocr 默认, 离线可用, 约 15MB
|
| 36 |
+
# paddleocr 精度更高, 镜像约 +2GB
|
| 37 |
+
# easyocr 多语种
|
| 38 |
+
# none 不内置, 需配合下方 OCR_* 指向外部/云 OCR
|
| 39 |
+
OCR_ENGINE=rapidocr
|
| 40 |
+
|
| 41 |
+
# 运行期使用的 OCR provider, 取值见 lqa_service/README.md
|
| 42 |
+
# OCR 是可选项: 留空或设为 none 时服务仍可正常启动与检测,
|
| 43 |
+
# 仅自动跳过依赖 OCR 的检测项 (错译、文本超文本框)
|
| 44 |
+
OCR_PROVIDER=rapidocr
|
| 45 |
+
OCR_LANG=ch
|
| 46 |
+
|
| 47 |
+
# ai 服务进程数; 识别为 CPU 密集型, 按核数调整
|
| 48 |
+
AI_WORKERS=2
|
| 49 |
+
|
| 50 |
+
# ai 服务对宿主机暴露的地址, 默认只监听本机便于调试
|
| 51 |
+
# 完全不对外暴露可改为 127.0.0.1:0, 或删除 compose 中 ai 的 ports
|
| 52 |
+
AI_HTTP_PORT=127.0.0.1:8086
|
| 53 |
+
|
| 54 |
+
# 使用云 OCR 时按需填写 (OCR_PROVIDER=tencentcloud/baidu/azure 等)
|
| 55 |
+
OCR_URL=
|
| 56 |
+
OCR_HOST=
|
| 57 |
+
OCR_API_KEY=
|
| 58 |
+
OCR_SECRET_ID=
|
| 59 |
+
OCR_SECRET_KEY=
|
| 60 |
+
OCR_REGION=ap-guangzhou
|
timi_hok_game_translator/LQA_WMP/.gitattributes
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
* text=auto eol=lf
|
| 2 |
+
*.png binary
|
| 3 |
+
*.jpg binary
|
| 4 |
+
*.ico binary
|
| 5 |
+
*.gif binary
|
| 6 |
+
*.woff binary
|
| 7 |
+
*.woff2 binary
|
| 8 |
+
*.ttf binary
|
timi_hok_game_translator/LQA_WMP/.gitignore
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 环境变量与密钥 (.env.example / web 的 .env.development 等需入库, 不要加 .env.*)
|
| 2 |
+
.env
|
| 3 |
+
*.local
|
| 4 |
+
|
| 5 |
+
# Python
|
| 6 |
+
__pycache__/
|
| 7 |
+
*.py[cod]
|
| 8 |
+
*.egg-info/
|
| 9 |
+
.venv/
|
| 10 |
+
venv/
|
| 11 |
+
.pytest_cache/
|
| 12 |
+
.mypy_cache/
|
| 13 |
+
.ruff_cache/
|
| 14 |
+
|
| 15 |
+
# Node
|
| 16 |
+
node_modules/
|
| 17 |
+
dist/
|
| 18 |
+
dist-ssr/
|
| 19 |
+
.eslintcache
|
| 20 |
+
|
| 21 |
+
# 运行时产物 (锚定到具体路径, 避免误伤同名源码目录)
|
| 22 |
+
*.log
|
| 23 |
+
/server/data/
|
| 24 |
+
/server/media/
|
| 25 |
+
/server/logs/
|
| 26 |
+
|
| 27 |
+
# 编辑器
|
| 28 |
+
.idea/
|
| 29 |
+
.vscode/
|
| 30 |
+
*.swp
|
| 31 |
+
*.sw?
|
| 32 |
+
|
| 33 |
+
# AI 开发助手本地元数据
|
| 34 |
+
.workbuddy/
|
| 35 |
+
|
| 36 |
+
# 系统
|
| 37 |
+
.DS_Store
|
| 38 |
+
Thumbs.db
|
timi_hok_game_translator/LQA_WMP/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 贡献指南
|
| 2 |
+
|
| 3 |
+
感谢你对 LQA 项目的关注, 以下是参与贡献的基本流程和规范
|
| 4 |
+
|
| 5 |
+
## 提交 Issue
|
| 6 |
+
|
| 7 |
+
- 提交前请先搜索是否已有相关 Issue, 避免重复
|
| 8 |
+
- **Bug 报告**: 请说明复现步骤、预期行为、实际行为,以及环境信息 (操作系统、Python/Node 版本、部署方式)
|
| 9 |
+
- **功能建议**: 请描述使用场景和期望的行为, 无需提供完整的实现方案
|
| 10 |
+
|
| 11 |
+
## 提交 Pull Request
|
| 12 |
+
|
| 13 |
+
1. Fork 本仓库, 在自己的 Fork 上创建分支, 分支名建议体现改动内容, 如 `fix/bugzilla-reopen` 或 `feat/dingtalk-notify`
|
| 14 |
+
2. 保持每个 PR 聚焦于单一目的, 便于 Review
|
| 15 |
+
3. 提交前请确认:
|
| 16 |
+
- 后端: `python manage.py migrate` 无误, 如有新模型请附带 migration 文件; 相关逻辑有基本测试或冒烟验证
|
| 17 |
+
- 前端: `pnpm lint` 通过, `pnpm build` 无报错
|
| 18 |
+
4. PR 描述中说明改动内容、测试方式, 以及是否有破坏性变更
|
| 19 |
+
|
| 20 |
+
## 本地开发环境
|
| 21 |
+
|
| 22 |
+
见 [README.md](README.md) 的快速概览, 或各子目录的详细文档:
|
| 23 |
+
|
| 24 |
+
- 后端: [server/README.md](server/README.md)
|
| 25 |
+
- 前端: [web/README.md](web/README.md)
|
| 26 |
+
|
| 27 |
+
## 代码规范
|
| 28 |
+
|
| 29 |
+
**后端 (Python)**
|
| 30 |
+
|
| 31 |
+
- 遵循项目现有风格, 参考 `server/.pylintrc`
|
| 32 |
+
- 数据校验使用 Pydantic schema, 接口返回统一走 `libs/base.py` 中的基类
|
| 33 |
+
- 新增缺陷系统适配器请继承 `libs/bugtracker/base.py` 中的 `BugTracker` 抽象基类, 在 `libs/bugtracker/__init__.py` 的 `TRACKER_TYPES` 中注册, 并在 `scripts/test_bugtracker.py` 中补充测试
|
| 34 |
+
|
| 35 |
+
**前端 (TypeScript / Vue)**
|
| 36 |
+
|
| 37 |
+
- 组件放在对应业务目录下, CRUD 配置与视图分文件
|
| 38 |
+
- API 请求统一走 `src/api/` 目录下的封装, 不直接调用 axios
|
| 39 |
+
- `pnpm lint` 包含 ESLint + Prettier, 提交前请确保通过
|
| 40 |
+
|
| 41 |
+
## 分支与版本
|
| 42 |
+
|
| 43 |
+
- `main` 为主分支, 保持可发布状态
|
| 44 |
+
- 重大功能或破坏性变更请在 Issue 中先讨论再动手
|
| 45 |
+
|
| 46 |
+
## 许可证
|
| 47 |
+
|
| 48 |
+
提交代码即表示你同意将贡献以 [Apache-2.0 License](LICENSE) 授权给本项目
|
timi_hok_game_translator/LQA_WMP/LICENSE
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Tencent is pleased to support the open source community by making LQA WMP available.
|
| 2 |
+
|
| 3 |
+
Copyright (C) 2024 LQA Contributors. All rights reserved.
|
| 4 |
+
|
| 5 |
+
LQA WMP is licensed under the Apache-2.0.
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
Terms of the Apache-2.0:
|
| 9 |
+
--------------------------------------------------------------------
|
| 10 |
+
Apache License
|
| 11 |
+
Version 2.0, January 2004
|
| 12 |
+
http://www.apache.org/licenses/
|
| 13 |
+
|
| 14 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 15 |
+
|
| 16 |
+
1. Definitions.
|
| 17 |
+
|
| 18 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 19 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 20 |
+
|
| 21 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 22 |
+
the copyright owner that is granting the License.
|
| 23 |
+
|
| 24 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 25 |
+
other entities that control, are controlled by, or are under common
|
| 26 |
+
control with that entity. For the purposes of this definition,
|
| 27 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 28 |
+
direction or management of such entity, whether by contract or
|
| 29 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 30 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 31 |
+
|
| 32 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 33 |
+
exercising permissions granted by this License.
|
| 34 |
+
|
| 35 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 36 |
+
including but not limited to software source code, documentation
|
| 37 |
+
source, and configuration files.
|
| 38 |
+
|
| 39 |
+
"Object" form shall mean any form resulting from mechanical
|
| 40 |
+
transformation or translation of a Source form, including but
|
| 41 |
+
not limited to compiled object code, generated documentation,
|
| 42 |
+
and conversions to other media types.
|
| 43 |
+
|
| 44 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 45 |
+
Object form, made available under the License, as indicated by a
|
| 46 |
+
copyright notice that is included in or attached to the work
|
| 47 |
+
(an example is provided in the Appendix below).
|
| 48 |
+
|
| 49 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 50 |
+
form, that is based on (or derived from) the Work and for which the
|
| 51 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 52 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 53 |
+
of this License, Derivative Works shall not include works that remain
|
| 54 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 55 |
+
the Work and Derivative Works thereof.
|
| 56 |
+
|
| 57 |
+
"Contribution" shall mean any work of authorship, including
|
| 58 |
+
the original version of the Work and any modifications or additions
|
| 59 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 60 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 61 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 62 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 63 |
+
means any form of electronic, verbal, or written communication sent
|
| 64 |
+
to the Licensor or its representatives, including but not limited to
|
| 65 |
+
communication on electronic mailing lists, source code control systems,
|
| 66 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 67 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 68 |
+
excluding communication that is conspicuously marked or otherwise
|
| 69 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 70 |
+
|
| 71 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 72 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 73 |
+
subsequently incorporated within the Work.
|
| 74 |
+
|
| 75 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 76 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 77 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 78 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 79 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 80 |
+
Work and such Derivative Works in Source or Object form.
|
| 81 |
+
|
| 82 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 83 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 84 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 85 |
+
(except as stated in this section) patent license to make, have made,
|
| 86 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 87 |
+
where such license applies only to those patent claims licensable
|
| 88 |
+
by such Contributor that are necessarily infringed by their
|
| 89 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 90 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 91 |
+
institute patent litigation against any entity (including a
|
| 92 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 93 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 94 |
+
or contributory patent infringement, then any patent licenses
|
| 95 |
+
granted to You under this License for that Work shall terminate
|
| 96 |
+
as of the date such litigation is filed.
|
| 97 |
+
|
| 98 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 99 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 100 |
+
modifications, and in Source or Object form, provided that You
|
| 101 |
+
meet the following conditions:
|
| 102 |
+
|
| 103 |
+
(a) You must give any other recipients of the Work or
|
| 104 |
+
Derivative Works a copy of this License; and
|
| 105 |
+
|
| 106 |
+
(b) You must cause any modified files to carry prominent notices
|
| 107 |
+
stating that You changed the files; and
|
| 108 |
+
|
| 109 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 110 |
+
that You distribute, all copyright, patent, trademark, and
|
| 111 |
+
attribution notices from the Source form of the Work,
|
| 112 |
+
excluding those notices that do not pertain to any part of
|
| 113 |
+
the Derivative Works; and
|
| 114 |
+
|
| 115 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 116 |
+
distribution, then any Derivative Works that You distribute must
|
| 117 |
+
include a readable copy of the attribution notices contained
|
| 118 |
+
within such NOTICE file, excluding those notices that do not
|
| 119 |
+
pertain to any part of the Derivative Works, in at least one
|
| 120 |
+
of the following places: within a NOTICE text file distributed
|
| 121 |
+
as part of the Derivative Works; within the Source form or
|
| 122 |
+
documentation, if provided along with the Derivative Works; or,
|
| 123 |
+
within a display generated by the Derivative Works, if and
|
| 124 |
+
wherever such third-party notices normally appear. The contents
|
| 125 |
+
of the NOTICE file are for informational purposes only and
|
| 126 |
+
do not modify the License. You may add Your own attribution
|
| 127 |
+
notices within Derivative Works that You distribute, alongside
|
| 128 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 129 |
+
that such additional attribution notices cannot be construed
|
| 130 |
+
as modifying the License.
|
| 131 |
+
|
| 132 |
+
You may add Your own copyright statement to Your modifications and
|
| 133 |
+
may provide additional or different license terms and conditions
|
| 134 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 135 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 136 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 137 |
+
the conditions stated in this License.
|
| 138 |
+
|
| 139 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 140 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 141 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 142 |
+
this License, without any additional terms or conditions.
|
| 143 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 144 |
+
the terms of any separate license agreement you may have executed
|
| 145 |
+
with Licensor regarding such Contributions.
|
| 146 |
+
|
| 147 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 148 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 149 |
+
except as required for reasonable and customary use in describing the
|
| 150 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 151 |
+
|
| 152 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 153 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 154 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 155 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 156 |
+
implied, including, without limitation, any warranties or conditions
|
| 157 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 158 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 159 |
+
appropriateness of using or redistributing the Work and assume any
|
| 160 |
+
risks associated with Your exercise of permissions under this License.
|
| 161 |
+
|
| 162 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 163 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 164 |
+
unless required by applicable law (such as deliberate and grossly
|
| 165 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 166 |
+
liable to You for damages, including any direct, indirect, special,
|
| 167 |
+
incidental, or consequential damages of any character arising as a
|
| 168 |
+
result of this License or out of the use or inability to use the
|
| 169 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 170 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 171 |
+
other commercial damages or losses), even if such Contributor
|
| 172 |
+
has been advised of the possibility of such damages.
|
| 173 |
+
|
| 174 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 175 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 176 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 177 |
+
or other liability obligations and/or rights consistent with this
|
| 178 |
+
License. However, in accepting such obligations, You may act only
|
| 179 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 180 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 181 |
+
defend, and hold each Contributor harmless for any liability
|
| 182 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 183 |
+
of your accepting any such warranty or additional liability.
|
| 184 |
+
|
| 185 |
+
END OF TERMS AND CONDITIONS
|
| 186 |
+
|
| 187 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 188 |
+
|
| 189 |
+
To apply the Apache License to your work, attach the following
|
| 190 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 191 |
+
replaced with your own identifying information. (Don't include
|
| 192 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 193 |
+
comment syntax for the file format. We also recommend that a
|
| 194 |
+
file or class name and description of purpose be included on the
|
| 195 |
+
same "printed page" as the copyright notice for easier
|
| 196 |
+
identification within third-party archives.
|
| 197 |
+
|
| 198 |
+
Copyright [yyyy] [name of copyright owner]
|
| 199 |
+
|
| 200 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 201 |
+
you may not use this file except in compliance with the License.
|
| 202 |
+
You may obtain a copy of the License at
|
| 203 |
+
|
| 204 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 205 |
+
|
| 206 |
+
Unless required by applicable law or agreed to in writing, software
|
| 207 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 208 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 209 |
+
See the License for the specific language governing permissions and
|
| 210 |
+
limitations under the License.
|
timi_hok_game_translator/LQA_WMP/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# LQA — 本地化质量检查平台
|
| 2 |
+
|
| 3 |
+

|
| 4 |
+
|
| 5 |
+
LQA (Localization Quality Assurance) 是一个面向游戏 / 应用多语言版本的本地化质量检查平台, 还原端 (如 UE/Unity 编辑器插件) 按任务批量生成各语言截图并上传, 平台调用 AI 识别服务检测 **漏译、错译、超框** 等问题, 测试人员审核结果后一键提交到缺陷系统, 并支持修复后的 **回归验证**
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
## 功能
|
| 10 |
+
|
| 11 |
+
- **账号体系** — 账号密码登录、自助注册 (注册后由管理员分配项目)、管理员创建用户 / 重置密码 / 禁用账号、API access_token
|
| 12 |
+
- **项目与角色** — 多项目隔离, 项目管理员 / 测试人员 / 开发人员三种角色, 超级管理员管理全局
|
| 13 |
+
- **还原任务** — 创建任务、选择语言与测试数据; 开始 / 重试时由浏览器直接调用项目配置的 Webhook (Jenkins / GitLab CI / 自建服务) 触发还原端
|
| 14 |
+
- **AI 识别** — 截图上传后异步调用 AI 识别服务, 支持全量识别与差异识别
|
| 15 |
+
- **缺陷管理** — 每个项目可选择 平台内记录 / Bugzilla 5.x / 禅道(开源版 REST API v1), 支持单个 / 批量 / 自动提单与回归验证
|
| 16 |
+
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
## 技术栈
|
| 20 |
+
|
| 21 |
+
| 层次 | 技术 |
|
| 22 |
+
|---|---|
|
| 23 |
+
| 后端语言与框架 | Python 3.12 + Django 5.1 |
|
| 24 |
+
| 异步任务 | Celery 5 + Redis |
|
| 25 |
+
| 数据库 | MySQL 8 |
|
| 26 |
+
| 缓存 / 会话 | Redis 7 |
|
| 27 |
+
| 后端服务器 | Gunicorn |
|
| 28 |
+
| 前端框架 | Vue 3 + Vite 5 + TypeScript |
|
| 29 |
+
| UI 组件库 | Element Plus + fast-crud |
|
| 30 |
+
| 前端状态管理 | Pinia |
|
| 31 |
+
| 前端基础模板 | [v3-admin-vite](https://github.com/un-pany/v3-admin-vite) |
|
| 32 |
+
| 容器化部署 | Docker Compose |
|
| 33 |
+
|
| 34 |
+
---
|
| 35 |
+
|
| 36 |
+
## 目录结构
|
| 37 |
+
|
| 38 |
+
```
|
| 39 |
+
LQA-WMP/
|
| 40 |
+
├── server/ 后端 (Python / Django)
|
| 41 |
+
│ ├── apps/
|
| 42 |
+
│ │ ├── user/ 账号、登录/注册、项目角色、access_token
|
| 43 |
+
│ │ ├── project/ 项目、项目配置 (缺陷类型/语言/Webhook/缺陷系统)
|
| 44 |
+
│ │ ├── job/ 还原任务、Webhook 触发、回归
|
| 45 |
+
│ │ ├── image/ 截图上传与 AI 识别
|
| 46 |
+
│ │ ├── bug/ 缺陷提单与同步
|
| 47 |
+
│ │ ├── data/ 测试数据
|
| 48 |
+
│ │ ├── system/ 枚举
|
| 49 |
+
│ │ └── lqa/ 健康检查、上传、管理命令
|
| 50 |
+
│ ├── libs/
|
| 51 |
+
│ │ └── bugtracker/ 缺陷系统适配器: none(平台内记录) / bugzilla / zentao
|
| 52 |
+
│ ├── scripts/ 冒烟测试、缺陷系统适配器测试
|
| 53 |
+
│ ├── requirements.txt
|
| 54 |
+
│ └── README.md 后端开发文档
|
| 55 |
+
├── web/ 前端 (Vue 3)
|
| 56 |
+
│ └── README.md 前端开发文档
|
| 57 |
+
├── lqa_service/ AI 识别服务 (Flask)
|
| 58 |
+
│ ├── common/ocr_provider/ 可插拔 OCR 适配层 (9 种实现)
|
| 59 |
+
│ ├── task/ 检测算法: 漏译/超框/漏key/重叠/错译
|
| 60 |
+
│ └── README.md 识别服务文档
|
| 61 |
+
├── docker-compose.yml 一键部署
|
| 62 |
+
└── .env.example 环境变量模板
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
---
|
| 66 |
+
|
| 67 |
+
## 文档
|
| 68 |
+
|
| 69 |
+
### API 协议
|
| 70 |
+
|
| 71 |
+
| 文档 | 说明 |
|
| 72 |
+
|---|---|
|
| 73 |
+
| [通用约定](docs/api/overview.md) | 认证方式、响应格式、错误码 |
|
| 74 |
+
| [用户接口](docs/api/user.md) | 登录、注册、账号管理、access_token |
|
| 75 |
+
| [项目接口](docs/api/project.md) | 项目管理、项目配置、模块 |
|
| 76 |
+
| [任务接口](docs/api/job.md) | 还原任务创建、启停、进度 |
|
| 77 |
+
| [截图接口](docs/api/image.md) | 截图上传、AI 识别、审核 |
|
| 78 |
+
| [缺陷接口](docs/api/bug.md) | 提单、批量提单、缺陷系统信息 |
|
| 79 |
+
| [测试数据接口](docs/api/data.md) | 测试数据管理 |
|
| 80 |
+
| [系统工具接口](docs/api/system.md) | 健康检查、枚举、文件上传 |
|
| 81 |
+
|
| 82 |
+
### 使用指南
|
| 83 |
+
|
| 84 |
+
| 文档 | 说明 |
|
| 85 |
+
|---|---|
|
| 86 |
+
| [Web 平台使用文档](docs/web-guide.md) | 面向测试 / 项目管理员 / 开发的 Web 平台操作手册 |
|
| 87 |
+
| [平台部署指南](docs/deploy-guide.md) | 全新电脑 / 服务器从零把平台跑起来的操作手册(Docker 一键部署 + 本地源码部署) |
|
| 88 |
+
|
| 89 |
+
### 集成指南
|
| 90 |
+
|
| 91 |
+
| 文档 | 说明 |
|
| 92 |
+
|---|---|
|
| 93 |
+
| [还原端集成指南](docs/integration/restorer.md) | 还原端(Unity 插件等)与平台对接的完整流程 |
|
| 94 |
+
|
| 95 |
+
### 快速索引: 还原端需要的接口
|
| 96 |
+
|
| 97 |
+
还原端只需关注以下三个接口, 认证使用 `LQA-Authorization: <access_token>` 请求头:
|
| 98 |
+
|
| 99 |
+
| 接口 | 说明 |
|
| 100 |
+
|---|---|
|
| 101 |
+
| `GET /api/job/datas` | 拉取任务测试数据 |
|
| 102 |
+
| `POST /api/image/entity` | 上传截图 (multipart/form-data) |
|
| 103 |
+
| `POST /api/job/device` | 上报设备信息与执行进度 |
|
| 104 |
+
|
| 105 |
+
详见 [还原端集成指南](docs/integration/restorer.md)。
|
| 106 |
+
|
| 107 |
+
---
|
| 108 |
+
|
| 109 |
+
## 贡献
|
| 110 |
+
|
| 111 |
+
欢迎提交 Issue 和 Pull Request,详见 [CONTRIBUTING.md](CONTRIBUTING.md)。
|
| 112 |
+
|
| 113 |
+
---
|
| 114 |
+
|
| 115 |
+
## 许可证
|
| 116 |
+
|
| 117 |
+
本项目后端代码以 **Apache-2.0** 开源,详见 [LICENSE](LICENSE)。
|
| 118 |
+
|
| 119 |
+
---
|
timi_hok_game_translator/LQA_WMP/docker-compose.yml
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 一键部署: cp .env.example .env 修改密码后执行 docker compose up -d --build
|
| 2 |
+
# 访问 http://<服务器>:${LQA_HTTP_PORT:-8080}, 使用 LQA_ADMIN_USERNAME / LQA_ADMIN_PASSWORD 登录
|
| 3 |
+
services:
|
| 4 |
+
mysql:
|
| 5 |
+
image: mysql:8.0
|
| 6 |
+
restart: unless-stopped
|
| 7 |
+
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
|
| 8 |
+
environment:
|
| 9 |
+
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:?请在 .env 中设置 MYSQL_ROOT_PASSWORD}
|
| 10 |
+
MYSQL_DATABASE: lqa
|
| 11 |
+
MYSQL_USER: lqa
|
| 12 |
+
MYSQL_PASSWORD: ${MYSQL_PASSWORD:?请在 .env 中设置 MYSQL_PASSWORD}
|
| 13 |
+
volumes:
|
| 14 |
+
- mysql_data:/var/lib/mysql
|
| 15 |
+
healthcheck:
|
| 16 |
+
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-uroot", "-p${MYSQL_ROOT_PASSWORD}"]
|
| 17 |
+
interval: 5s
|
| 18 |
+
timeout: 5s
|
| 19 |
+
retries: 30
|
| 20 |
+
|
| 21 |
+
redis:
|
| 22 |
+
image: redis:7-alpine
|
| 23 |
+
restart: unless-stopped
|
| 24 |
+
command: redis-server --requirepass ${REDIS_PASSWORD:?请在 .env 中设置 REDIS_PASSWORD}
|
| 25 |
+
volumes:
|
| 26 |
+
- redis_data:/data
|
| 27 |
+
healthcheck:
|
| 28 |
+
test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD}", "ping"]
|
| 29 |
+
interval: 5s
|
| 30 |
+
timeout: 5s
|
| 31 |
+
retries: 30
|
| 32 |
+
|
| 33 |
+
server: &server
|
| 34 |
+
build: ./server
|
| 35 |
+
image: lqa-server:latest
|
| 36 |
+
restart: unless-stopped
|
| 37 |
+
environment: &server_env
|
| 38 |
+
DEBUG: "false"
|
| 39 |
+
SECRET_KEY: ${SECRET_KEY:?请在 .env 中设置 SECRET_KEY}
|
| 40 |
+
ALLOWED_HOSTS: "*"
|
| 41 |
+
MYSQL_URL: mysql://lqa:${MYSQL_PASSWORD}@mysql:3306/lqa
|
| 42 |
+
REDIS_URL: rediscache://:${REDIS_PASSWORD}@redis:6379/1
|
| 43 |
+
CELERY_BROKER_URL: redis://:${REDIS_PASSWORD}@redis:6379/2
|
| 44 |
+
CELERY_BACKEND_URL: redis://:${REDIS_PASSWORD}@redis:6379/2
|
| 45 |
+
ALLOW_REGISTER: ${ALLOW_REGISTER:-true}
|
| 46 |
+
SESSION_COOKIE_SECURE: ${SESSION_COOKIE_SECURE:-false}
|
| 47 |
+
PUBLIC_URL: ${PUBLIC_URL:-}
|
| 48 |
+
MEDIA_PUBLIC: ${MEDIA_PUBLIC:-false}
|
| 49 |
+
# 默认指向随本编排启动的 ai 服务; 如需用外部识别服务, 在 .env 中覆盖
|
| 50 |
+
AI_BASE_URL: ${AI_BASE_URL:-http://ai:8086}
|
| 51 |
+
LQA_ADMIN_USERNAME: ${LQA_ADMIN_USERNAME:-admin}
|
| 52 |
+
LQA_ADMIN_PASSWORD: ${LQA_ADMIN_PASSWORD:-}
|
| 53 |
+
volumes:
|
| 54 |
+
- lqa_data:/data
|
| 55 |
+
depends_on:
|
| 56 |
+
mysql:
|
| 57 |
+
condition: service_healthy
|
| 58 |
+
redis:
|
| 59 |
+
condition: service_healthy
|
| 60 |
+
command: ["web"]
|
| 61 |
+
|
| 62 |
+
worker:
|
| 63 |
+
<<: *server
|
| 64 |
+
command: ["worker"]
|
| 65 |
+
# AI 识别由 Celery worker 发起 (apps/image/service.py), 需等 ai 就绪
|
| 66 |
+
depends_on:
|
| 67 |
+
server:
|
| 68 |
+
condition: service_started
|
| 69 |
+
ai:
|
| 70 |
+
condition: service_healthy
|
| 71 |
+
|
| 72 |
+
ai:
|
| 73 |
+
build:
|
| 74 |
+
context: ./lqa_service
|
| 75 |
+
args:
|
| 76 |
+
# 内置的 OCR 引擎: rapidocr (默认, 轻量) / paddleocr (精度更高, 镜像约+2GB)
|
| 77 |
+
# easyocr (多语种) / none (不内置, 需指向外部 OCR 服务)
|
| 78 |
+
OCR_ENGINE: ${OCR_ENGINE:-rapidocr}
|
| 79 |
+
image: lqa-ai:latest
|
| 80 |
+
restart: unless-stopped
|
| 81 |
+
environment:
|
| 82 |
+
DEBUG_MODE: ${AI_DEBUG_MODE:-False}
|
| 83 |
+
# OCR 为可选能力; 设为 none 则不做 OCR, 仅跳过错译与文本超框检测
|
| 84 |
+
OCR_PROVIDER: ${OCR_PROVIDER:-rapidocr}
|
| 85 |
+
OCR_LANG: ${OCR_LANG:-ch}
|
| 86 |
+
GUNICORN_WORKERS: ${AI_WORKERS:-2}
|
| 87 |
+
# 使用外部/云 OCR 时按需设置, 详见 lqa_service/README.md
|
| 88 |
+
OCR_URL: ${OCR_URL:-}
|
| 89 |
+
OCR_HOST: ${OCR_HOST:-}
|
| 90 |
+
OCR_API_KEY: ${OCR_API_KEY:-}
|
| 91 |
+
OCR_SECRET_ID: ${OCR_SECRET_ID:-}
|
| 92 |
+
OCR_SECRET_KEY: ${OCR_SECRET_KEY:-}
|
| 93 |
+
OCR_REGION: ${OCR_REGION:-ap-guangzhou}
|
| 94 |
+
# 默认仅在内部网络暴露; 需从宿主机直接调试时在 .env 设置 AI_HTTP_PORT
|
| 95 |
+
ports:
|
| 96 |
+
- "${AI_HTTP_PORT:-127.0.0.1:8086}:8086"
|
| 97 |
+
|
| 98 |
+
web:
|
| 99 |
+
build: ./web
|
| 100 |
+
image: lqa-web:latest
|
| 101 |
+
restart: unless-stopped
|
| 102 |
+
ports:
|
| 103 |
+
- "${LQA_HTTP_PORT:-8080}:80"
|
| 104 |
+
depends_on:
|
| 105 |
+
- server
|
| 106 |
+
|
| 107 |
+
volumes:
|
| 108 |
+
mysql_data:
|
| 109 |
+
redis_data:
|
| 110 |
+
lqa_data:
|
timi_hok_game_translator/LQA_WMP/docs/api/bug.md
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 缺陷接口
|
| 2 |
+
|
| 3 |
+
## 获取缺陷系统信息及提单选项
|
| 4 |
+
|
| 5 |
+
```
|
| 6 |
+
GET /api/bug/tracker_meta?project_id=<id>
|
| 7 |
+
```
|
| 8 |
+
|
| 9 |
+
返回当前项目配置的缺陷系统类型, 以及提单时需要的下拉选项 (版本列表等), 需要项目成员权限
|
| 10 |
+
|
| 11 |
+
**响应 data:**
|
| 12 |
+
|
| 13 |
+
```json
|
| 14 |
+
{
|
| 15 |
+
"type": "bugzilla",
|
| 16 |
+
"label": "Bugzilla",
|
| 17 |
+
"remote": true,
|
| 18 |
+
"enabled": true,
|
| 19 |
+
"version_report_list": ["1.0", "1.1"],
|
| 20 |
+
"version_fix_list": ["1.2"],
|
| 21 |
+
"release_id_list": [],
|
| 22 |
+
"error": ""
|
| 23 |
+
}
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
`type` 取值: `none`(平台内记录)、`bugzilla`、`zentao`
|
| 27 |
+
|
| 28 |
+
---
|
| 29 |
+
|
| 30 |
+
## 获取缺陷系统自定义字段
|
| 31 |
+
|
| 32 |
+
```
|
| 33 |
+
GET /api/bug/tracker_fields?project_id=<id>
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
返回缺陷系统中可作为 "自定义提单字段" 的字段及其选项 (Bugzilla/禅道专用), 需要项目成员权限
|
| 37 |
+
|
| 38 |
+
**响应 data:**
|
| 39 |
+
|
| 40 |
+
```json
|
| 41 |
+
{
|
| 42 |
+
"type": "bugzilla",
|
| 43 |
+
"fields": [
|
| 44 |
+
{
|
| 45 |
+
"name": "cf_game_version",
|
| 46 |
+
"label": "游戏版本",
|
| 47 |
+
"options": ["1.0", "1.1"]
|
| 48 |
+
}
|
| 49 |
+
]
|
| 50 |
+
}
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
---
|
| 54 |
+
|
| 55 |
+
## 测试缺陷系统连接
|
| 56 |
+
|
| 57 |
+
```
|
| 58 |
+
POST /api/bug/tracker_test
|
| 59 |
+
Content-Type: application/json
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
需要项目管理员权限, 用于保存配置前验证连接, `api_key` 传 `******` 时使用已保存的密钥
|
| 63 |
+
|
| 64 |
+
**请求体 (Bugzilla 示例):**
|
| 65 |
+
|
| 66 |
+
```json
|
| 67 |
+
{
|
| 68 |
+
"project_id": 2,
|
| 69 |
+
"tracker_type": "bugzilla",
|
| 70 |
+
"url": "https://bugzilla.example.com",
|
| 71 |
+
"api_key": "abc123",
|
| 72 |
+
"product": "MyGame",
|
| 73 |
+
"component": "本地化"
|
| 74 |
+
}
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
---
|
| 78 |
+
|
| 79 |
+
## 获取单条提单预览
|
| 80 |
+
|
| 81 |
+
```
|
| 82 |
+
GET /api/bug/build_info?project_id=<id>&image_id=<id>&bug_types=1,2
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
提单前预览将要填入缺陷系统的标题、描述等内容, 需要项目成员权限
|
| 86 |
+
|
| 87 |
+
**Query 参数:**
|
| 88 |
+
|
| 89 |
+
| 参数 | 类型 | 说明 |
|
| 90 |
+
|---|---|---|
|
| 91 |
+
| `project_id` | int | 项目 ID |
|
| 92 |
+
| `image_id` | int | 截图 ID |
|
| 93 |
+
| `bug_types` | string | 逗号分隔的缺陷类型 ID |
|
| 94 |
+
|
| 95 |
+
**响应 data:**
|
| 96 |
+
|
| 97 |
+
```json
|
| 98 |
+
{
|
| 99 |
+
"title": "[漏译][主界面] ui_main_zh.png",
|
| 100 |
+
"description": "...",
|
| 101 |
+
"bug_keys": [...],
|
| 102 |
+
"current_owner": "dev_user",
|
| 103 |
+
"title_pre": "",
|
| 104 |
+
"version_report": "1.0"
|
| 105 |
+
}
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
---
|
| 109 |
+
|
| 110 |
+
## 提交单个缺陷
|
| 111 |
+
|
| 112 |
+
```
|
| 113 |
+
POST /api/bug/entity
|
| 114 |
+
Content-Type: application/json
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
需要项目成员权限, 提单为异步操作, 返回 Celery 任务 ID
|
| 118 |
+
|
| 119 |
+
**请求体:**
|
| 120 |
+
|
| 121 |
+
```json
|
| 122 |
+
{
|
| 123 |
+
"project_id": 2,
|
| 124 |
+
"image_id": 200,
|
| 125 |
+
"bug_types": [1, 2],
|
| 126 |
+
"title": "[漏译] ui_main_zh.png",
|
| 127 |
+
"description": "详细描述...",
|
| 128 |
+
"current_owner": "dev_user",
|
| 129 |
+
"version_report": "1.0",
|
| 130 |
+
"version_fix": "1.2",
|
| 131 |
+
"priority": "P2",
|
| 132 |
+
"severity": "normal"
|
| 133 |
+
}
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
**响应 data:**
|
| 137 |
+
|
| 138 |
+
```json
|
| 139 |
+
{ "task": "celery-task-id-abc123" }
|
| 140 |
+
```
|
| 141 |
+
|
| 142 |
+
---
|
| 143 |
+
|
| 144 |
+
## 获取缺陷列表
|
| 145 |
+
|
| 146 |
+
```
|
| 147 |
+
GET /api/bug/list?job_id=<id>
|
| 148 |
+
```
|
| 149 |
+
|
| 150 |
+
`job_id` 和 `image_id` 二选一, 返回时会同步查询外部缺陷系统的最新状态 (`tracker_status`、`tracker_open`)
|
| 151 |
+
|
| 152 |
+
**Query 参数:**
|
| 153 |
+
|
| 154 |
+
| 参数 | 类型 | 说明 |
|
| 155 |
+
|---|---|---|
|
| 156 |
+
| `job_id` | int | 按任务查询 |
|
| 157 |
+
| `image_id` | int | 按截图查询 |
|
| 158 |
+
| `page` / `page_size` | int | 分页 |
|
| 159 |
+
| `title__contains` | string | 标题模糊搜索 |
|
| 160 |
+
| `info_type` | int | `1` 简略信息 (不同步缺陷系统) |
|
| 161 |
+
|
| 162 |
+
**响应 data:**
|
| 163 |
+
|
| 164 |
+
```json
|
| 165 |
+
{
|
| 166 |
+
"list": [
|
| 167 |
+
{
|
| 168 |
+
"id": 300,
|
| 169 |
+
"project_id": 2,
|
| 170 |
+
"job_id": 10,
|
| 171 |
+
"image_id": 200,
|
| 172 |
+
"title": "[漏译] ui_main_zh.png",
|
| 173 |
+
"priority": "P2",
|
| 174 |
+
"severity": "normal",
|
| 175 |
+
"reporter": "test_user",
|
| 176 |
+
"current_owner": "dev_user",
|
| 177 |
+
"version_report": "1.0",
|
| 178 |
+
"version_fix": "1.2",
|
| 179 |
+
"tracker": "bugzilla",
|
| 180 |
+
"external_id": "1234",
|
| 181 |
+
"external_url": "https://bugzilla.example.com/show_bug.cgi?id=1234",
|
| 182 |
+
"status": "open",
|
| 183 |
+
"bill_status": 1,
|
| 184 |
+
"tracker_status": "NEW",
|
| 185 |
+
"tracker_open": true,
|
| 186 |
+
"is_delete": 0,
|
| 187 |
+
"regress_status": 0,
|
| 188 |
+
"regress_job_ids": []
|
| 189 |
+
}
|
| 190 |
+
],
|
| 191 |
+
"total": 5,
|
| 192 |
+
"page": 1,
|
| 193 |
+
"page_size": 20
|
| 194 |
+
}
|
| 195 |
+
```
|
| 196 |
+
|
| 197 |
+
---
|
| 198 |
+
|
| 199 |
+
## 批量提交缺陷
|
| 200 |
+
|
| 201 |
+
```
|
| 202 |
+
POST /api/bug/list
|
| 203 |
+
Content-Type: application/json
|
| 204 |
+
```
|
| 205 |
+
|
| 206 |
+
需要项目成员权限, 批量异步提单
|
| 207 |
+
|
| 208 |
+
**请求体:**
|
| 209 |
+
|
| 210 |
+
```json
|
| 211 |
+
{
|
| 212 |
+
"project_id": 2,
|
| 213 |
+
"job_id": 10,
|
| 214 |
+
"image_ids": [200, 201, 202],
|
| 215 |
+
"bug_types": [1, 2],
|
| 216 |
+
"version_report": "1.0",
|
| 217 |
+
"version_fix": "1.2"
|
| 218 |
+
}
|
| 219 |
+
```
|
| 220 |
+
|
| 221 |
+
**响应 data:**
|
| 222 |
+
|
| 223 |
+
```json
|
| 224 |
+
{
|
| 225 |
+
"success": [200, 201],
|
| 226 |
+
"failed": [[202, "错误原因"]]
|
| 227 |
+
}
|
| 228 |
+
```
|
| 229 |
+
|
| 230 |
+
---
|
| 231 |
+
|
| 232 |
+
## 批量更新缺陷
|
| 233 |
+
|
| 234 |
+
```
|
| 235 |
+
PATCH /api/bug/list
|
| 236 |
+
Content-Type: application/json
|
| 237 |
+
```
|
| 238 |
+
|
| 239 |
+
目前主要用于批量更新回归状态
|
| 240 |
+
|
| 241 |
+
**请求体:**
|
| 242 |
+
|
| 243 |
+
```json
|
| 244 |
+
{
|
| 245 |
+
"bug_ids": [300, 301],
|
| 246 |
+
"regress_status": 1
|
| 247 |
+
}
|
| 248 |
+
```
|
| 249 |
+
|
| 250 |
+
---
|
timi_hok_game_translator/LQA_WMP/docs/api/data.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 测试数据接口
|
| 2 |
+
|
| 3 |
+
测试数据 (Data) 是还原任务的基础单元, 代表一个需要截图的界面/资源节点, 数据由平台管理员或通过导入工具维护
|
| 4 |
+
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## 获取测试数据详情
|
| 8 |
+
|
| 9 |
+
```
|
| 10 |
+
GET /api/data/entity?id=<id>
|
| 11 |
+
```
|
| 12 |
+
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
## 获取测试数据列表
|
| 16 |
+
|
| 17 |
+
```
|
| 18 |
+
GET /api/data/list
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
**Query 参数:**
|
| 22 |
+
|
| 23 |
+
| 参数 | 类型 | 说明 |
|
| 24 |
+
|---|---|---|
|
| 25 |
+
| `page` / `page_size` | int | 分页 |
|
| 26 |
+
| `project_id` | int | 按项目筛选 |
|
| 27 |
+
| `module_id` | int | 按模块筛选 |
|
| 28 |
+
| `cur_id` | int | 游标分页 |
|
| 29 |
+
|
| 30 |
+
---
|
| 31 |
+
|
| 32 |
+
## 创建/修改测试数据
|
| 33 |
+
|
| 34 |
+
```
|
| 35 |
+
POST /api/data/entity
|
| 36 |
+
PATCH /api/data/entity
|
| 37 |
+
Content-Type: application/json
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
**请求体 (主要字段):**
|
| 41 |
+
|
| 42 |
+
```json
|
| 43 |
+
{
|
| 44 |
+
"project_id": 2,
|
| 45 |
+
"module_id": 10,
|
| 46 |
+
"file_path": "Assets/UI/main.prefab",
|
| 47 |
+
"key": "ui_main_title",
|
| 48 |
+
"shot_img_path": "/media/..."
|
| 49 |
+
}
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
修改时需额外传 `"id": <data_id>`
|
| 53 |
+
|
| 54 |
+
---
|
| 55 |
+
|
| 56 |
+
## 获取资源版本列表
|
| 57 |
+
|
| 58 |
+
```
|
| 59 |
+
GET /api/data/resource_version/list?project_id=<id>
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
返回当前项目所有测试数据中出现过的资源版本号列表, 用于提单时的 "报告版本" 下拉选项
|
| 63 |
+
|
| 64 |
+
---
|
| 65 |
+
|
| 66 |
+
## 图片资源管理
|
| 67 |
+
|
| 68 |
+
```
|
| 69 |
+
GET /api/data/image_resource?project_id=<id>
|
| 70 |
+
POST /api/data/image_resource
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
管理每个测试数据关联的参考截图资源
|
| 74 |
+
|
| 75 |
+
**GET 参数:**
|
| 76 |
+
|
| 77 |
+
| 参数 | 类型 | 说明 |
|
| 78 |
+
|---|---|---|
|
| 79 |
+
| `project_id` | int | 项目 ID |
|
| 80 |
+
| `data_id` | int | 测试数据 ID |
|
| 81 |
+
|
| 82 |
+
---
|
| 83 |
+
|
| 84 |
+
## 图片资源合并
|
| 85 |
+
|
| 86 |
+
```
|
| 87 |
+
POST /api/data/image_resource/merge
|
| 88 |
+
Content-Type: application/json
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
将多个图片资源合并处理
|
| 92 |
+
|
| 93 |
+
---
|
timi_hok_game_translator/LQA_WMP/docs/api/image.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 截图接口
|
| 2 |
+
|
| 3 |
+
## 上传截图 (还原端调用)
|
| 4 |
+
|
| 5 |
+
```
|
| 6 |
+
POST /api/image/entity
|
| 7 |
+
Content-Type: multipart/form-data
|
| 8 |
+
LQA-Authorization: <access_token>
|
| 9 |
+
```
|
| 10 |
+
|
| 11 |
+
还原端上传每张截图, 上传后可选择同步触发 AI 识别
|
| 12 |
+
|
| 13 |
+
**Form 字段:**
|
| 14 |
+
|
| 15 |
+
| 字段 | 类型 | 必填 | 说明 |
|
| 16 |
+
|---|---|---|---|
|
| 17 |
+
| `file` | file | 是 | 截图文件 (PNG/JPG) |
|
| 18 |
+
| `project_id` | int | 是 | 项目 ID |
|
| 19 |
+
| `job_id` | int | 是 | 任务 ID |
|
| 20 |
+
| `data_id` | int | 是 | 测试数据 ID (来自 `/api/job/datas`) |
|
| 21 |
+
| `language` | int | 是 | 语言值 |
|
| 22 |
+
| `rect_locations` | string | 是 | 文本控件位置信息 JSON 字符串 |
|
| 23 |
+
| `ai_sign` | int | 否 | `1` 上传后立即触发 AI 识别, 默认 `0` |
|
| 24 |
+
| `discern` | int | 否 | 识别模式: `0` 全量, `1` 差异 |
|
| 25 |
+
| `create_bug` | int | 否 | `1` 识别后自动提单 |
|
| 26 |
+
| `regression` | int | 否 | `1` 表示回归任务 |
|
| 27 |
+
| `bug_ids` | string | 否 | 回归时传入需回归的缺陷 ID, 逗号分隔 |
|
| 28 |
+
|
| 29 |
+
**响应 data:**
|
| 30 |
+
|
| 31 |
+
```json
|
| 32 |
+
{
|
| 33 |
+
"image": {
|
| 34 |
+
"id": 200,
|
| 35 |
+
"project_id": 2,
|
| 36 |
+
"job_id": 10,
|
| 37 |
+
"data_id": 501,
|
| 38 |
+
"language": 2,
|
| 39 |
+
"file_name": "ui_main_zh.png",
|
| 40 |
+
"file_path": "/media/...",
|
| 41 |
+
"iteration": 1,
|
| 42 |
+
"is_latest": 1,
|
| 43 |
+
"ai_sign": 0
|
| 44 |
+
},
|
| 45 |
+
"task_id": "abc123..."
|
| 46 |
+
}
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
`task_id` 为 Celery 任务 ID, `ai_sign=1` 时返回; 可用于追踪异步识别进度
|
| 50 |
+
|
| 51 |
+
---
|
| 52 |
+
|
| 53 |
+
## 获取截图详情
|
| 54 |
+
|
| 55 |
+
```
|
| 56 |
+
GET /api/image/entity?image_id=<id>
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
**响应 data:**
|
| 60 |
+
|
| 61 |
+
```json
|
| 62 |
+
{
|
| 63 |
+
"image": {
|
| 64 |
+
"id": 200,
|
| 65 |
+
"file_path": "/media/...",
|
| 66 |
+
"ai_mark_img_path": "/media/...",
|
| 67 |
+
"ai_rect_img_path": "/media/...",
|
| 68 |
+
"ai_check_detail": {...},
|
| 69 |
+
"ai_bug_types": "[1,2]",
|
| 70 |
+
"will_review": 1,
|
| 71 |
+
"reviewed": 0,
|
| 72 |
+
"bug_num": 2,
|
| 73 |
+
...
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
---
|
| 79 |
+
|
| 80 |
+
## 获取截图列表
|
| 81 |
+
|
| 82 |
+
```
|
| 83 |
+
GET /api/image/list
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
**Query 参数:**
|
| 87 |
+
|
| 88 |
+
| 参数 | 类型 | 说明 |
|
| 89 |
+
|---|---|---|
|
| 90 |
+
| `page` / `page_size` | int | 分页 |
|
| 91 |
+
| `job_id` | int | 按任务筛选 |
|
| 92 |
+
| `data_id` | int | 按测试数据筛选 (需同时传 `job_id`) |
|
| 93 |
+
| `language` | int | 按语言筛选 |
|
| 94 |
+
| `languages` | string | 逗号分隔, 多语言筛选 |
|
| 95 |
+
| `is_latest` | int | `1` 只返回最新截图 |
|
| 96 |
+
| `will_review` | int | 是否需要审核 |
|
| 97 |
+
| `reviewed` | int | 审核状态 |
|
| 98 |
+
| `err_type` | int | 错误类型 |
|
| 99 |
+
| `ai_bug_types` | string | 逗号分隔, 按 AI 识别出的缺陷类型筛选 |
|
| 100 |
+
| `module_ids` | string | 逗号分隔的模块 ID |
|
| 101 |
+
| `info_type` | int | `0` 简略信息 (不含大字段) |
|
| 102 |
+
| `pk__gte` / `pk__lte` | int | ID 范围查询 |
|
| 103 |
+
|
| 104 |
+
**PATCH 批量更新:**
|
| 105 |
+
|
| 106 |
+
```
|
| 107 |
+
PATCH /api/image/list
|
| 108 |
+
Content-Type: application/json
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
```json
|
| 112 |
+
{
|
| 113 |
+
"ids": [200, 201, 202],
|
| 114 |
+
"reviewed": 1,
|
| 115 |
+
"will_review": 0
|
| 116 |
+
}
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
---
|
| 120 |
+
|
| 121 |
+
## 删除截图
|
| 122 |
+
|
| 123 |
+
```
|
| 124 |
+
DELETE /api/image/entity
|
| 125 |
+
Content-Type: application/json
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
```json
|
| 129 |
+
{
|
| 130 |
+
"project_id": 2,
|
| 131 |
+
"image_ids": [200, 201]
|
| 132 |
+
}
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
或单个: `"image_id": 200`
|
| 136 |
+
|
| 137 |
+
---
|
| 138 |
+
|
| 139 |
+
## 触发 AI 识别
|
| 140 |
+
|
| 141 |
+
```
|
| 142 |
+
POST /api/image/ai_sign
|
| 143 |
+
Content-Type: application/json
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
手动触发 AI 识别, 可针对单张或整个任务批量触发
|
| 147 |
+
|
| 148 |
+
**请求体:**
|
| 149 |
+
|
| 150 |
+
```json
|
| 151 |
+
{
|
| 152 |
+
"image_id": 200,
|
| 153 |
+
"job_id": null,
|
| 154 |
+
"discern": 0,
|
| 155 |
+
"languages": [2, 3]
|
| 156 |
+
}
|
| 157 |
+
```
|
| 158 |
+
|
| 159 |
+
`image_id` 和 `job_id` 二选一: 传 `image_id` 为同步识别单张; 传 `job_id` 为异步批量识别整个任务
|
| 160 |
+
|
| 161 |
+
`discern`: `0` 全量识别, `1` 差异识别
|
| 162 |
+
|
| 163 |
+
---
|
| 164 |
+
|
| 165 |
+
## 数据审核记录
|
| 166 |
+
|
| 167 |
+
```
|
| 168 |
+
GET /api/image/data_review?data_id=<id>&project_id=<id>
|
| 169 |
+
PATCH /api/image/data_review
|
| 170 |
+
Content-Type: application/json
|
| 171 |
+
```
|
| 172 |
+
|
| 173 |
+
**GET 响应 data:**
|
| 174 |
+
|
| 175 |
+
```json
|
| 176 |
+
{
|
| 177 |
+
"data_review": {
|
| 178 |
+
"id": 50,
|
| 179 |
+
"data_id": 501,
|
| 180 |
+
"project_id": 2,
|
| 181 |
+
"rect_location": [...],
|
| 182 |
+
"check_rect_location": "{}",
|
| 183 |
+
"dirty_rect_location": "{}",
|
| 184 |
+
"size": "1920,1080",
|
| 185 |
+
"reviewer": "system",
|
| 186 |
+
"image_id": 200
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
```
|
| 190 |
+
|
| 191 |
+
**PATCH 请求体 (人工审核修正文本框):**
|
| 192 |
+
|
| 193 |
+
```json
|
| 194 |
+
{
|
| 195 |
+
"id": 50,
|
| 196 |
+
"check_rect_location": "{}",
|
| 197 |
+
"dirty_rect_location": "{}"
|
| 198 |
+
}
|
| 199 |
+
```
|
| 200 |
+
|
| 201 |
+
---
|
timi_hok_game_translator/LQA_WMP/docs/api/job.md
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 任务接口
|
| 2 |
+
|
| 3 |
+
## 获取任务列表
|
| 4 |
+
|
| 5 |
+
```
|
| 6 |
+
GET /api/job/list
|
| 7 |
+
```
|
| 8 |
+
|
| 9 |
+
**Query 参数:**
|
| 10 |
+
|
| 11 |
+
| 参数 | 类型 | 说明 |
|
| 12 |
+
|---|---|---|
|
| 13 |
+
| `page` / `page_size` | int | 分页 |
|
| 14 |
+
| `cur_id` | int | 游标分页 |
|
| 15 |
+
| `project_id` | int | 按项目筛选 |
|
| 16 |
+
| `id` | int | 按任务 ID 精确查询 (同时返回子任务列表) |
|
| 17 |
+
| `name__icontains` | string | 任务名模糊搜索 |
|
| 18 |
+
| `status` | int | 任务状态筛选 |
|
| 19 |
+
| `creator_id` | int | 按创建人筛选 |
|
| 20 |
+
| `language` | int | 按语言筛选 |
|
| 21 |
+
| `created_begin_at` | string | 创建时间起始 |
|
| 22 |
+
| `created_end_at` | string | 创建时间结束 |
|
| 23 |
+
| `is_parent` | int | `0` 只返回普通任务, `1` 只返回回归任务 |
|
| 24 |
+
| `info_type` | int | `0` 简略信息 (不含扩展字段), 其他含扩展字段 |
|
| 25 |
+
|
| 26 |
+
**响应 data:**
|
| 27 |
+
|
| 28 |
+
```json
|
| 29 |
+
{
|
| 30 |
+
"list": [
|
| 31 |
+
{
|
| 32 |
+
"id": 10,
|
| 33 |
+
"project_id": 2,
|
| 34 |
+
"name": "2024-01 全量还原",
|
| 35 |
+
"languages": [2, 3],
|
| 36 |
+
"status": 2,
|
| 37 |
+
"reason": "",
|
| 38 |
+
"created_at": "...",
|
| 39 |
+
"updated_at": "...",
|
| 40 |
+
"parent_id": 0,
|
| 41 |
+
"regress_num": 1,
|
| 42 |
+
"bug_num": 5
|
| 43 |
+
}
|
| 44 |
+
],
|
| 45 |
+
"total": 20,
|
| 46 |
+
"page": 1,
|
| 47 |
+
"page_size": 20
|
| 48 |
+
}
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
**任务状态 (status) 枚举:**
|
| 52 |
+
|
| 53 |
+
| 值 | 说明 |
|
| 54 |
+
|---|---|
|
| 55 |
+
| `1` | 未执行 |
|
| 56 |
+
| `2` | 执行中 |
|
| 57 |
+
| `3` | 已完成 |
|
| 58 |
+
| `4` | 异常终止 |
|
| 59 |
+
|
| 60 |
+
---
|
| 61 |
+
|
| 62 |
+
## 获取任务详情
|
| 63 |
+
|
| 64 |
+
```
|
| 65 |
+
GET /api/job/entity?job_id=<id>[&progress=1][&fields=f1,f2][&mappings=1]
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
| 参数 | 说明 |
|
| 69 |
+
|---|---|
|
| 70 |
+
| `job_id` | 任务 ID |
|
| 71 |
+
| `progress` | `1` 时额外返回识别进度 (`progress_rate`、`all_count`、`ai_signed_count`) |
|
| 72 |
+
| `fields` | 逗号分隔,只返回指定字段 |
|
| 73 |
+
| `mappings` | `1` 时额外返回语言/缺陷类型/状态的枚举映射 |
|
| 74 |
+
|
| 75 |
+
**响应 data:**
|
| 76 |
+
|
| 77 |
+
```json
|
| 78 |
+
{
|
| 79 |
+
"job": {
|
| 80 |
+
"id": 10,
|
| 81 |
+
"project_id": 2,
|
| 82 |
+
"name": "2024-01 全量还原",
|
| 83 |
+
"languages": [2, 3],
|
| 84 |
+
"status": 2,
|
| 85 |
+
"progress_rate": "15/20",
|
| 86 |
+
...
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
---
|
| 92 |
+
|
| 93 |
+
## 创建任务
|
| 94 |
+
|
| 95 |
+
```
|
| 96 |
+
POST /api/job/entity
|
| 97 |
+
Content-Type: application/json
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
需要项目成员权限
|
| 101 |
+
|
| 102 |
+
**请求体 (主要字段):**
|
| 103 |
+
|
| 104 |
+
```json
|
| 105 |
+
{
|
| 106 |
+
"project_id": 2,
|
| 107 |
+
"name": "2024-01 全量还原",
|
| 108 |
+
"languages": [2, 3],
|
| 109 |
+
"plan_start_at": "2024-01-10T09:00:00",
|
| 110 |
+
"plan_end_at": "2024-01-12T18:00:00"
|
| 111 |
+
}
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
**响应 data:**
|
| 115 |
+
|
| 116 |
+
```json
|
| 117 |
+
{ "job": { "id": 10, ... } }
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
---
|
| 121 |
+
|
| 122 |
+
## 修改任务
|
| 123 |
+
|
| 124 |
+
```
|
| 125 |
+
PATCH /api/job/entity
|
| 126 |
+
Content-Type: application/json
|
| 127 |
+
```
|
| 128 |
+
|
| 129 |
+
需要项目成员权限, 请求体同创建, 额外传 `"id": <job_id>`
|
| 130 |
+
|
| 131 |
+
---
|
| 132 |
+
|
| 133 |
+
## 任务操作 (启动 / 重试 / 回调 / 停止)
|
| 134 |
+
|
| 135 |
+
```
|
| 136 |
+
POST /api/job/action
|
| 137 |
+
Content-Type: application/json
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
**请求体:**
|
| 141 |
+
|
| 142 |
+
```json
|
| 143 |
+
{
|
| 144 |
+
"job_id": 10,
|
| 145 |
+
"action": "start",
|
| 146 |
+
"build_id": "",
|
| 147 |
+
"regression": 0
|
| 148 |
+
}
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
**`action` 取值:**
|
| 152 |
+
|
| 153 |
+
| action | 说明 | 返回内容 |
|
| 154 |
+
|---|---|---|
|
| 155 |
+
| `start` | 启动任务: 返回渲染好的 Webhook 请求, 由浏览器发起调用 | `trigger` 对象 |
|
| 156 |
+
| `retry` | 重试: 补提未识别的截图, 并返回 Webhook 请求 | `trigger` 对象 |
|
| 157 |
+
| `started` | 浏览器调用 Webhook 成功后回调, 将任务置为执行中 | 无 |
|
| 158 |
+
| `stop` | 结束任务 | 无 |
|
| 159 |
+
|
| 160 |
+
`started` 时需额外传 `build_id` (Webhook 响应中的构建 ID) 和 `regression` (`0` 普通, `1` 回归, `2` 重试)
|
| 161 |
+
|
| 162 |
+
**`start`/`retry` 响应 data:**
|
| 163 |
+
|
| 164 |
+
```json
|
| 165 |
+
{
|
| 166 |
+
"job_id": 10,
|
| 167 |
+
"regression": 0,
|
| 168 |
+
"trigger": {
|
| 169 |
+
"url": "https://jenkins.example.com/job/...",
|
| 170 |
+
"method": "POST",
|
| 171 |
+
"headers": { "Authorization": "..." },
|
| 172 |
+
"body": "..."
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
```
|
| 176 |
+
|
| 177 |
+
---
|
| 178 |
+
|
| 179 |
+
## 创建回归任务
|
| 180 |
+
|
| 181 |
+
```
|
| 182 |
+
POST /api/job/bug_regress
|
| 183 |
+
Content-Type: application/json
|
| 184 |
+
```
|
| 185 |
+
|
| 186 |
+
基于已有缺陷创建回归任务, 创建后调用 `/api/job/action` 的 `start` action 触发执行
|
| 187 |
+
|
| 188 |
+
**请求体:**
|
| 189 |
+
|
| 190 |
+
```json
|
| 191 |
+
{
|
| 192 |
+
"project_id": 2,
|
| 193 |
+
"parent_id": 10,
|
| 194 |
+
"bug_ids": [101, 102, 103],
|
| 195 |
+
"languages": [2, 3]
|
| 196 |
+
}
|
| 197 |
+
```
|
| 198 |
+
|
| 199 |
+
---
|
| 200 |
+
|
| 201 |
+
## 获取任务进度
|
| 202 |
+
|
| 203 |
+
```
|
| 204 |
+
GET /api/job/progress?job_id=<id>
|
| 205 |
+
```
|
| 206 |
+
|
| 207 |
+
返回各语言的截图上传进度
|
| 208 |
+
|
| 209 |
+
**响应 data:**
|
| 210 |
+
|
| 211 |
+
```json
|
| 212 |
+
{
|
| 213 |
+
"all_data_count": 100,
|
| 214 |
+
"all_imaged_count": 45,
|
| 215 |
+
"languges": [
|
| 216 |
+
{
|
| 217 |
+
"language": 2,
|
| 218 |
+
"imaged_count": 25,
|
| 219 |
+
"imaged_count_per": "25%"
|
| 220 |
+
}
|
| 221 |
+
]
|
| 222 |
+
}
|
| 223 |
+
```
|
| 224 |
+
|
| 225 |
+
---
|
| 226 |
+
|
| 227 |
+
## 获取任务测试数据 (还原端调用)
|
| 228 |
+
|
| 229 |
+
```
|
| 230 |
+
GET /api/job/datas
|
| 231 |
+
LQA-Authorization: <access_token>
|
| 232 |
+
```
|
| 233 |
+
|
| 234 |
+
还原端拉取本次任务需要还原的数据列表
|
| 235 |
+
|
| 236 |
+
**Query 参数:**
|
| 237 |
+
|
| 238 |
+
| 参数 | 类型 | 说明 |
|
| 239 |
+
|---|---|---|
|
| 240 |
+
| `job_id` | int | 必填 |
|
| 241 |
+
| `language` | int | 语言值, 必填 |
|
| 242 |
+
| `regression` | int | `0` 普通, `1` 回归 |
|
| 243 |
+
| `count` | int | 本次拉取条数, 默认全部 |
|
| 244 |
+
| `minID` | int | 增量拉取: 只返回 `id > minID` 的数据 |
|
| 245 |
+
| `module_ids` | string | 逗号分隔的模块 ID, 按模块筛选 |
|
| 246 |
+
| `iteration` | int | 迭代轮次 |
|
| 247 |
+
| `use_cache` | int | `1` 使用缓存 |
|
| 248 |
+
|
| 249 |
+
**响应 data:**
|
| 250 |
+
|
| 251 |
+
```json
|
| 252 |
+
{
|
| 253 |
+
"datas": [
|
| 254 |
+
{
|
| 255 |
+
"id": 501,
|
| 256 |
+
"file_path": "/media/...",
|
| 257 |
+
"module_id": 10
|
| 258 |
+
}
|
| 259 |
+
],
|
| 260 |
+
"bug_ids": []
|
| 261 |
+
}
|
| 262 |
+
```
|
| 263 |
+
|
| 264 |
+
回归任务时 `bug_ids` 中包含需要回归验证的缺陷 ID 列表
|
| 265 |
+
|
| 266 |
+
---
|
| 267 |
+
|
| 268 |
+
## 上报设备与进度 (还原端调用)
|
| 269 |
+
|
| 270 |
+
```
|
| 271 |
+
POST /api/job/device
|
| 272 |
+
Content-Type: application/json
|
| 273 |
+
LQA-Authorization: <access_token>
|
| 274 |
+
```
|
| 275 |
+
|
| 276 |
+
还原端上报执行设备信息和当前进度
|
| 277 |
+
|
| 278 |
+
**请求体:**
|
| 279 |
+
|
| 280 |
+
```json
|
| 281 |
+
{
|
| 282 |
+
"job_id": 10,
|
| 283 |
+
"execute_pc": "PC-001",
|
| 284 |
+
"language": 2,
|
| 285 |
+
"status": 2,
|
| 286 |
+
"progress": 50,
|
| 287 |
+
"total": 100
|
| 288 |
+
}
|
| 289 |
+
```
|
| 290 |
+
|
| 291 |
+
**GET 查询设备列表:**
|
| 292 |
+
|
| 293 |
+
```
|
| 294 |
+
GET /api/job/device?job_id=<id>
|
| 295 |
+
```
|
| 296 |
+
|
| 297 |
+
返回该任务下所有设备的执行状态列表
|
| 298 |
+
|
| 299 |
+
---
|
timi_hok_game_translator/LQA_WMP/docs/api/overview.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# API 通用约定
|
| 2 |
+
|
| 3 |
+
## Base URL
|
| 4 |
+
|
| 5 |
+
所有接口均以 `/api/` 为前缀, Docker Compose 部署时, Nginx 将 `/api-pro/` 反向代理到后端, 前端通过 `/api-pro/` 访问; 后端本身监听 `/api/`
|
| 6 |
+
|
| 7 |
+
本文档中的路径均为 **后端实际路径** (`/api/...`)
|
| 8 |
+
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
## 认证
|
| 12 |
+
|
| 13 |
+
平台支持两种认证方式, 通过请求头区分:
|
| 14 |
+
|
| 15 |
+
### 浏览器 (Session Cookie)
|
| 16 |
+
|
| 17 |
+
登录后服务端颁发 Session Cookie, 后续请求自动携带, 同时需要携带请求头:
|
| 18 |
+
|
| 19 |
+
```
|
| 20 |
+
LQA-Authorization: web
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
### API 调用方 (access_token)
|
| 24 |
+
|
| 25 |
+
适用于还原端、脚本等非浏览器场景
|
| 26 |
+
|
| 27 |
+
```
|
| 28 |
+
LQA-Authorization: <access_token>
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
**获取 access_token 的两种方式:**
|
| 32 |
+
|
| 33 |
+
1. 管理命令 (推荐, 由平台管理员执行):
|
| 34 |
+
```bash
|
| 35 |
+
python manage.py update_access_token -u <user_id> [-e <有效期秒数,默认30天>]
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
2. 接口方式:
|
| 39 |
+
- `GET /api/ticket` 获取一次性 ticket (需已登录)
|
| 40 |
+
- 携带请求头 `LQA-Ticket: <ticket>` 调用 `POST /api/user/access_token`
|
| 41 |
+
- 返回新的 access_token (旧 token 同时失效)
|
| 42 |
+
|
| 43 |
+
**免登录接口** (无需认证):
|
| 44 |
+
- `GET /api/health`
|
| 45 |
+
- `GET /api/user/auth_config`
|
| 46 |
+
- `POST /api/user/login`
|
| 47 |
+
- `POST /api/user/register` (需 `ALLOW_REGISTER=true`)
|
| 48 |
+
|
| 49 |
+
---
|
| 50 |
+
|
| 51 |
+
## 响应格式
|
| 52 |
+
|
| 53 |
+
所有接口返回 JSON, 结构如下:
|
| 54 |
+
|
| 55 |
+
```json
|
| 56 |
+
{
|
| 57 |
+
"code": 0,
|
| 58 |
+
"msg": "",
|
| 59 |
+
"data": {}
|
| 60 |
+
}
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
| 字段 | 类型 | 说明 |
|
| 64 |
+
|---|---|---|
|
| 65 |
+
| `code` | int | `0` 表示成功, 非 0 表示错误 |
|
| 66 |
+
| `msg` | string | 成功时通常为空或提示文字, 失败时为错误描述 |
|
| 67 |
+
| `data` | object | 业务数据, 成功时才有意义 |
|
| 68 |
+
|
| 69 |
+
---
|
| 70 |
+
|
| 71 |
+
## 错误码
|
| 72 |
+
|
| 73 |
+
| code | 常量 | 含义 |
|
| 74 |
+
|---|---|---|
|
| 75 |
+
| `0` | — | 成功 |
|
| 76 |
+
| `1001` | `ERROR` | 通用业务错误 |
|
| 77 |
+
| `1002` | `ERROR_PARAM` | 参数错误 |
|
| 78 |
+
| `1003` | `ERROR_AUTH` | 认证失败 (未登录或 token 失效) |
|
| 79 |
+
| `1004` | `ERROR_PERMISSION` | 无权限 |
|
| 80 |
+
| `1005` | `NOT_EXIST` | 资源不存在 |
|
| 81 |
+
|
| 82 |
+
认证失败 (`1003`) 时前端应跳转到登录页; 还原端应检查 access_token 是否过期
|
| 83 |
+
|
| 84 |
+
---
|
| 85 |
+
|
| 86 |
+
## 分页参数
|
| 87 |
+
|
| 88 |
+
列表接口通用分页参数 (Query String):
|
| 89 |
+
|
| 90 |
+
| 参数 | 类型 | 默认值 | 说明 |
|
| 91 |
+
|---|---|---|---|
|
| 92 |
+
| `page` | int | `1` | 页码 (从 1 开始) |
|
| 93 |
+
| `page_size` | int | `20` | 每页条数 |
|
| 94 |
+
| `cur_id` | int | — | 游标分页: 返回 `id < cur_id` 的记录 |
|
| 95 |
+
|
| 96 |
+
分页响应体:
|
| 97 |
+
|
| 98 |
+
```json
|
| 99 |
+
{
|
| 100 |
+
"code": 0,
|
| 101 |
+
"data": {
|
| 102 |
+
"list": [...],
|
| 103 |
+
"total": 100,
|
| 104 |
+
"page": 1,
|
| 105 |
+
"page_size": 20
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
---
|
| 111 |
+
|
| 112 |
+
## 角色说明
|
| 113 |
+
|
| 114 |
+
| 角色值 | 名称 | 说明 |
|
| 115 |
+
|---|---|---|
|
| 116 |
+
| `1` | 项目管理员 | 可管理项目配置、成员、缺陷系统 |
|
| 117 |
+
| `2` | 测试人员 | 可创建任务、审核截图、提单 |
|
| 118 |
+
| `3` | 开发人员 | 可查看任务、截图、缺陷 |
|
| 119 |
+
| — | 超级管理员 | `is_admin=1`, 管理全局用户和项目, 不受项目角色限制 |
|
| 120 |
+
|
| 121 |
+
---
|
timi_hok_game_translator/LQA_WMP/docs/api/project.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 项目接口
|
| 2 |
+
|
| 3 |
+
## 获取项目信息
|
| 4 |
+
|
| 5 |
+
```
|
| 6 |
+
GET /api/project/entity?project_id=<id>
|
| 7 |
+
```
|
| 8 |
+
|
| 9 |
+
**响应 data:**
|
| 10 |
+
|
| 11 |
+
```json
|
| 12 |
+
{
|
| 13 |
+
"project": {
|
| 14 |
+
"id": 2,
|
| 15 |
+
"code": "game_cn",
|
| 16 |
+
"name": "某游戏中文版",
|
| 17 |
+
"label": "",
|
| 18 |
+
"team": "QA团队",
|
| 19 |
+
"game_type": 1,
|
| 20 |
+
"project_type": 2,
|
| 21 |
+
"project_phase": 1
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
## 创建/修改项目
|
| 29 |
+
|
| 30 |
+
```
|
| 31 |
+
POST /api/project/entity
|
| 32 |
+
PATCH /api/project/entity
|
| 33 |
+
Content-Type: application/json
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
需要超级管理员权限, 创建时会自动初始化项目的缺陷类型、语言等配置 (从系统模板复制)
|
| 37 |
+
|
| 38 |
+
**请求体:**
|
| 39 |
+
|
| 40 |
+
```json
|
| 41 |
+
{
|
| 42 |
+
"code": "game_cn",
|
| 43 |
+
"name": "某游戏中文版",
|
| 44 |
+
"label": "",
|
| 45 |
+
"team": "QA团队",
|
| 46 |
+
"game_type": 1,
|
| 47 |
+
"project_type": 2,
|
| 48 |
+
"project_phase": 1
|
| 49 |
+
}
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
修改时需额外传 `"project_id": <id>`
|
| 53 |
+
|
| 54 |
+
**`game_type` 枚举:**
|
| 55 |
+
|
| 56 |
+
| 值 | 说明 |
|
| 57 |
+
|---|---|
|
| 58 |
+
| `1` | 手游 |
|
| 59 |
+
| `2` | 端游 |
|
| 60 |
+
| `3` | 页游 |
|
| 61 |
+
| `4` | App |
|
| 62 |
+
| `5` | 小游戏 |
|
| 63 |
+
|
| 64 |
+
**`project_type` 枚举:** `1` 平台级, `2` 项目级
|
| 65 |
+
|
| 66 |
+
**`project_phase` 枚举:** `1` 上线运营, `2` 下线, `3` 研发期, `4` 保密
|
| 67 |
+
|
| 68 |
+
---
|
| 69 |
+
|
| 70 |
+
## 获取项目列表
|
| 71 |
+
|
| 72 |
+
```
|
| 73 |
+
GET /api/project/list
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
**Query 参数:**
|
| 77 |
+
|
| 78 |
+
| 参数 | 类型 | 说明 |
|
| 79 |
+
|---|---|---|
|
| 80 |
+
| `page` / `page_size` | int | 分页 |
|
| 81 |
+
| `project_id` | int | 按 ID 精确查询 |
|
| 82 |
+
| `name__icontains` | string | 名称模糊搜索 |
|
| 83 |
+
| `team__icontains` | string | 团队模糊搜索 |
|
| 84 |
+
| `game_type` | int | 游戏类型筛选 |
|
| 85 |
+
| `project_type` | int | 项目类型筛选 |
|
| 86 |
+
| `project_phase` | int | 项目阶段筛选 |
|
| 87 |
+
|
| 88 |
+
---
|
| 89 |
+
|
| 90 |
+
## 获取项目角色树
|
| 91 |
+
|
| 92 |
+
```
|
| 93 |
+
GET /api/project/roles?project_id=<id>
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
`project_id=0` 时返回所有项目的角色树, 用于用户管理表单的角色下拉选项
|
| 97 |
+
|
| 98 |
+
---
|
| 99 |
+
|
| 100 |
+
## 项目配置
|
| 101 |
+
|
| 102 |
+
```
|
| 103 |
+
GET /api/project/config?project_id=<id>&cate=<cate>
|
| 104 |
+
POST /api/project/config?cate=<cate>
|
| 105 |
+
PATCH /api/project/config?cate=<cate>
|
| 106 |
+
DELETE /api/project/config?cate=<cate>
|
| 107 |
+
Content-Type: application/json
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
POST/PATCH/DELETE 需要 **项目管理员** 权限
|
| 111 |
+
|
| 112 |
+
**`cate` 取值:**
|
| 113 |
+
|
| 114 |
+
| cate | 说明 |
|
| 115 |
+
|---|---|
|
| 116 |
+
| `BugType` | 缺陷类型配置 (多条) |
|
| 117 |
+
| `Language` | 区域语言配置 (多条) |
|
| 118 |
+
| `ImgRevert` | 图片还原配置 (单条): `GET` 时加 `&editor=1` 返回还原端格式 |
|
| 119 |
+
| `BugBillMethod` | 提单配置 (单条) |
|
| 120 |
+
| `BugBillUser` | 提单人员配置 |
|
| 121 |
+
| `BugTracker` | 缺陷系统配置 (单条), `api_key` 字段返回时以 `******` 掩码 |
|
| 122 |
+
| `CustomField` | 自定义提单字段 |
|
| 123 |
+
| `Other` | 其他配置 (单条) |
|
| 124 |
+
|
| 125 |
+
**GET 响应 data:**
|
| 126 |
+
|
| 127 |
+
```json
|
| 128 |
+
{ "list": [...] }
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
**PATCH 响应 data:**
|
| 132 |
+
|
| 133 |
+
```json
|
| 134 |
+
{ "config": { ... } }
|
| 135 |
+
```
|
| 136 |
+
|
| 137 |
+
---
|
| 138 |
+
|
| 139 |
+
## 模块管理
|
| 140 |
+
|
| 141 |
+
```
|
| 142 |
+
GET /api/project/module/list?project_id=<id>[&all=1]
|
| 143 |
+
POST /api/project/module
|
| 144 |
+
PATCH /api/project/module
|
| 145 |
+
DELETE /api/project/module
|
| 146 |
+
Content-Type: application/json
|
| 147 |
+
```
|
| 148 |
+
|
| 149 |
+
需要项目成员权限 (增删改需项目管理员)
|
| 150 |
+
|
| 151 |
+
**创建/修改请求体:**
|
| 152 |
+
|
| 153 |
+
```json
|
| 154 |
+
{
|
| 155 |
+
"project_id": 2,
|
| 156 |
+
"name": "ui_main",
|
| 157 |
+
"show_name": "主界面"
|
| 158 |
+
}
|
| 159 |
+
```
|
| 160 |
+
|
| 161 |
+
修改时需额外传 `"id": <module_id>`
|
| 162 |
+
|
| 163 |
+
**删除请求体:**
|
| 164 |
+
|
| 165 |
+
```json
|
| 166 |
+
{
|
| 167 |
+
"project_id": 2,
|
| 168 |
+
"module_id": 10
|
| 169 |
+
}
|
| 170 |
+
```
|
| 171 |
+
|
| 172 |
+
**GET 带 `all=1`** 时返回项目下所有模块 (不分页), 格式为 `{"modules": [...], "total": N}`
|
| 173 |
+
|
| 174 |
+
---
|
timi_hok_game_translator/LQA_WMP/docs/api/system.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 系统工具接口
|
| 2 |
+
|
| 3 |
+
## 健康检查
|
| 4 |
+
|
| 5 |
+
```
|
| 6 |
+
GET /api/health
|
| 7 |
+
```
|
| 8 |
+
|
| 9 |
+
免登录, 用于容器健康检查、监控探活
|
| 10 |
+
|
| 11 |
+
**响应 data:**
|
| 12 |
+
|
| 13 |
+
```json
|
| 14 |
+
{ "status": "ok" }
|
| 15 |
+
```
|
| 16 |
+
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
## 获取一次性 Ticket
|
| 20 |
+
|
| 21 |
+
```
|
| 22 |
+
GET /api/ticket
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
需要登录, 获取一个 5 分钟有效的一次性 ticket, 用于换取 `access_token` (详见[用户接口 - 获取 access_token](user.md#获取-access_token))
|
| 26 |
+
|
| 27 |
+
**响应 data:**
|
| 28 |
+
|
| 29 |
+
```json
|
| 30 |
+
{ "ticket": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" }
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
---
|
| 34 |
+
|
| 35 |
+
## 磁盘使用情况
|
| 36 |
+
|
| 37 |
+
```
|
| 38 |
+
GET /api/disk_usage
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
需要登录, 返回媒体文件目录的磁盘用量
|
| 42 |
+
|
| 43 |
+
**响应 data:**
|
| 44 |
+
|
| 45 |
+
```json
|
| 46 |
+
{
|
| 47 |
+
"total": 107374182400,
|
| 48 |
+
"used": 21474836480,
|
| 49 |
+
"free": 85899345920
|
| 50 |
+
}
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
单位: 字节
|
| 54 |
+
|
| 55 |
+
---
|
| 56 |
+
|
| 57 |
+
## 上传文件
|
| 58 |
+
|
| 59 |
+
```
|
| 60 |
+
POST /api/upload_file
|
| 61 |
+
Content-Type: multipart/form-data
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
通用文件上传, 用于上传项目配置相关的附件 (如还原配置文件)
|
| 65 |
+
|
| 66 |
+
**响应 data:**
|
| 67 |
+
|
| 68 |
+
```json
|
| 69 |
+
{
|
| 70 |
+
"file_name": "config.json",
|
| 71 |
+
"file_path": "/media/tmp/..."
|
| 72 |
+
}
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
---
|
| 76 |
+
|
| 77 |
+
## 获取枚举值
|
| 78 |
+
|
| 79 |
+
```
|
| 80 |
+
GET /api/system/enums/<cate>
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
获取系统内置枚举的标签与值, 用于前端下拉选项
|
| 84 |
+
|
| 85 |
+
**`cate` 取值示例:**
|
| 86 |
+
|
| 87 |
+
| cate | 说明 |
|
| 88 |
+
|---|---|
|
| 89 |
+
| `game_type` | 游戏类型 |
|
| 90 |
+
| `project_type` | 项目类型 |
|
| 91 |
+
| `project_phase` | 项目阶段 |
|
| 92 |
+
| `role` | 项目角色 |
|
| 93 |
+
| `user_status` | 用户状态 |
|
| 94 |
+
| `job_status` | 任务状态 |
|
| 95 |
+
|
| 96 |
+
**响应 data (示例):**
|
| 97 |
+
|
| 98 |
+
```json
|
| 99 |
+
{
|
| 100 |
+
"list": [
|
| 101 |
+
{ "value": 1, "label": "手游" },
|
| 102 |
+
{ "value": 2, "label": "端游" }
|
| 103 |
+
]
|
| 104 |
+
}
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
---
|
| 108 |
+
|
| 109 |
+
## 媒体文件访问
|
| 110 |
+
|
| 111 |
+
```
|
| 112 |
+
GET /media/<path>
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
截图等上传文件的访问路径
|
| 116 |
+
|
| 117 |
+
- `MEDIA_PUBLIC=false` (默认): 需要登录认证 (由登录中间件鉴权)
|
| 118 |
+
- `MEDIA_PUBLIC=true`: 允许匿名访问, 适用于禅道需要内嵌显示截图的场景
|
| 119 |
+
|
| 120 |
+
生产环境建议由 Nginx 直接提供 `APP_MEDIA_ROOT/media/` 目录, 避免经过 Django 处理
|
| 121 |
+
|
| 122 |
+
---
|
timi_hok_game_translator/LQA_WMP/docs/api/user.md
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 用户接口
|
| 2 |
+
|
| 3 |
+
## 获取登录页配置
|
| 4 |
+
|
| 5 |
+
```
|
| 6 |
+
GET /api/user/auth_config
|
| 7 |
+
```
|
| 8 |
+
|
| 9 |
+
免登录, 返回是否开放注册等前端需要的公开配置
|
| 10 |
+
|
| 11 |
+
**响应 data:**
|
| 12 |
+
|
| 13 |
+
```json
|
| 14 |
+
{
|
| 15 |
+
"allow_register": true,
|
| 16 |
+
"app_name": "LQA"
|
| 17 |
+
}
|
| 18 |
+
```
|
| 19 |
+
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
## 登录
|
| 23 |
+
|
| 24 |
+
```
|
| 25 |
+
POST /api/user/login
|
| 26 |
+
Content-Type: application/json
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
免登录, 连续失败次数过多会锁定一段时间
|
| 30 |
+
|
| 31 |
+
**请求体:**
|
| 32 |
+
|
| 33 |
+
```json
|
| 34 |
+
{
|
| 35 |
+
"username": "admin",
|
| 36 |
+
"password": "Admin123456"
|
| 37 |
+
}
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
**响应 data:**
|
| 41 |
+
|
| 42 |
+
```json
|
| 43 |
+
{
|
| 44 |
+
"user": {
|
| 45 |
+
"id": 1,
|
| 46 |
+
"name": "admin",
|
| 47 |
+
"name_zh": "管理员",
|
| 48 |
+
"is_admin": 1
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
登录成功后服务端设置 Session Cookie, 后续浏览器请求自动携带
|
| 54 |
+
|
| 55 |
+
---
|
| 56 |
+
|
| 57 |
+
## 退出登录
|
| 58 |
+
|
| 59 |
+
```
|
| 60 |
+
POST /api/user/logout
|
| 61 |
+
GET /api/user/logout
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
清除 Session
|
| 65 |
+
|
| 66 |
+
---
|
| 67 |
+
|
| 68 |
+
## 注册
|
| 69 |
+
|
| 70 |
+
```
|
| 71 |
+
POST /api/user/register
|
| 72 |
+
Content-Type: application/json
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
免登录, 仅在 `ALLOW_REGISTER=true` 时可用, 注册后需管理员分配项目角色
|
| 76 |
+
|
| 77 |
+
**请求体:**
|
| 78 |
+
|
| 79 |
+
```json
|
| 80 |
+
{
|
| 81 |
+
"username": "testuser",
|
| 82 |
+
"password": "Password123",
|
| 83 |
+
"name_zh": "测试用户",
|
| 84 |
+
"email": "test@example.com"
|
| 85 |
+
}
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
---
|
| 89 |
+
|
| 90 |
+
## 修改自己的密码
|
| 91 |
+
|
| 92 |
+
```
|
| 93 |
+
POST /api/user/password
|
| 94 |
+
Content-Type: application/json
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
**请求体:**
|
| 98 |
+
|
| 99 |
+
```json
|
| 100 |
+
{
|
| 101 |
+
"old_password": "OldPass123",
|
| 102 |
+
"new_password": "NewPass456"
|
| 103 |
+
}
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
---
|
| 107 |
+
|
| 108 |
+
## 修改自己的资料
|
| 109 |
+
|
| 110 |
+
```
|
| 111 |
+
PATCH /api/user/profile
|
| 112 |
+
Content-Type: application/json
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
**请求体 (字段均可选):**
|
| 116 |
+
|
| 117 |
+
```json
|
| 118 |
+
{
|
| 119 |
+
"name_zh": "新昵称",
|
| 120 |
+
"email": "new@example.com"
|
| 121 |
+
}
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
---
|
| 125 |
+
|
| 126 |
+
## 重置他人密码
|
| 127 |
+
|
| 128 |
+
```
|
| 129 |
+
POST /api/user/reset_password
|
| 130 |
+
Content-Type: application/json
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
需要超级管理员权限
|
| 134 |
+
|
| 135 |
+
**请求体:**
|
| 136 |
+
|
| 137 |
+
```json
|
| 138 |
+
{
|
| 139 |
+
"id": 5,
|
| 140 |
+
"new_password": "NewPass789"
|
| 141 |
+
}
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
---
|
| 145 |
+
|
| 146 |
+
## 获取用户列表
|
| 147 |
+
|
| 148 |
+
```
|
| 149 |
+
GET /api/user/list
|
| 150 |
+
```
|
| 151 |
+
|
| 152 |
+
**Query 参数:**
|
| 153 |
+
|
| 154 |
+
| 参数 | 类型 | 说明 |
|
| 155 |
+
|---|---|---|
|
| 156 |
+
| `page` / `page_size` | int | 分页 |
|
| 157 |
+
| `cur_id` | int | 游标分页 |
|
| 158 |
+
| `name__icontains` | string | 用户名模糊搜索 |
|
| 159 |
+
| `name_zh__icontains` | string | 显示名模糊搜索 |
|
| 160 |
+
| `department__icontains` | string | 部门模糊搜索 |
|
| 161 |
+
| `status` | int | 状态: `1` 正常, `0` 禁用 |
|
| 162 |
+
| `project_id` | int | 筛选属于某项目的成员 |
|
| 163 |
+
| `is_admin` | int | `1` 只返回项目管理员, `0` 只返回非管理员 |
|
| 164 |
+
| `info_type` | int | `0` 基础信息, `1` 简略信息, `2` 含项目角色 |
|
| 165 |
+
|
| 166 |
+
**响应 data:**
|
| 167 |
+
|
| 168 |
+
```json
|
| 169 |
+
{
|
| 170 |
+
"list": [
|
| 171 |
+
{
|
| 172 |
+
"id": 1,
|
| 173 |
+
"name": "admin",
|
| 174 |
+
"name_zh": "管理员",
|
| 175 |
+
"email": "",
|
| 176 |
+
"department": "",
|
| 177 |
+
"status": 1,
|
| 178 |
+
"is_admin": 1,
|
| 179 |
+
"projects": [...],
|
| 180 |
+
"roles": [...]
|
| 181 |
+
}
|
| 182 |
+
],
|
| 183 |
+
"total": 10,
|
| 184 |
+
"page": 1,
|
| 185 |
+
"page_size": 20
|
| 186 |
+
}
|
| 187 |
+
```
|
| 188 |
+
|
| 189 |
+
---
|
| 190 |
+
|
| 191 |
+
## 获取/创建/修改/删除用户
|
| 192 |
+
|
| 193 |
+
```
|
| 194 |
+
GET /api/user/entity?id=<uid>&info_type=<0|1>
|
| 195 |
+
POST /api/user/entity
|
| 196 |
+
PATCH /api/user/entity
|
| 197 |
+
DELETE /api/user/entity
|
| 198 |
+
```
|
| 199 |
+
|
| 200 |
+
**GET 参数:**
|
| 201 |
+
|
| 202 |
+
| 参数 | 说明 |
|
| 203 |
+
|---|---|
|
| 204 |
+
| `id` | 用户 ID, 不传则返回当前登录用户 |
|
| 205 |
+
| `info_type` | `0` 基础信息, `1` 含项目角色 (默认) |
|
| 206 |
+
|
| 207 |
+
本人查询时可在响应中看到自己的 `access_token`
|
| 208 |
+
|
| 209 |
+
**POST 请求体 (创建用户):**
|
| 210 |
+
|
| 211 |
+
```json
|
| 212 |
+
{
|
| 213 |
+
"name": "newuser",
|
| 214 |
+
"password": "Pass123456",
|
| 215 |
+
"name_zh": "新用户",
|
| 216 |
+
"email": "new@example.com",
|
| 217 |
+
"department": "QA",
|
| 218 |
+
"project_id": 2,
|
| 219 |
+
"roles": [[2, 2]]
|
| 220 |
+
}
|
| 221 |
+
```
|
| 222 |
+
|
| 223 |
+
超级管理员可创建任意用户; 项目管理员只能为本项目创建成员
|
| 224 |
+
|
| 225 |
+
**PATCH 请求体 (修改用户):**
|
| 226 |
+
|
| 227 |
+
```json
|
| 228 |
+
{
|
| 229 |
+
"id": 5,
|
| 230 |
+
"project_id": 2,
|
| 231 |
+
"name_zh": "新名字",
|
| 232 |
+
"status": 0,
|
| 233 |
+
"is_admin": 0,
|
| 234 |
+
"roles": [[2, 2]]
|
| 235 |
+
}
|
| 236 |
+
```
|
| 237 |
+
|
| 238 |
+
**DELETE 请求体 (软删除, 需超管):**
|
| 239 |
+
|
| 240 |
+
```json
|
| 241 |
+
{ "id": 5 }
|
| 242 |
+
```
|
| 243 |
+
|
| 244 |
+
---
|
| 245 |
+
|
| 246 |
+
## 获取当前用户权限信息
|
| 247 |
+
|
| 248 |
+
```
|
| 249 |
+
GET /api/user/permission
|
| 250 |
+
```
|
| 251 |
+
|
| 252 |
+
返回当前用户的基本信息及可访问的项目列表 (含角色), 前端用于初始化路由权限
|
| 253 |
+
|
| 254 |
+
**响应 data:**
|
| 255 |
+
|
| 256 |
+
```json
|
| 257 |
+
{
|
| 258 |
+
"user": {
|
| 259 |
+
"id": 1,
|
| 260 |
+
"is_admin": 1,
|
| 261 |
+
"name": "admin",
|
| 262 |
+
"name_zh": "管理员"
|
| 263 |
+
},
|
| 264 |
+
"projects": [
|
| 265 |
+
{
|
| 266 |
+
"id": 2,
|
| 267 |
+
"code": "game_cn",
|
| 268 |
+
"name": "某游戏中文版",
|
| 269 |
+
"roles": ["2_1", "2_2"]
|
| 270 |
+
}
|
| 271 |
+
]
|
| 272 |
+
}
|
| 273 |
+
```
|
| 274 |
+
|
| 275 |
+
---
|
| 276 |
+
|
| 277 |
+
## 获取 access_token
|
| 278 |
+
|
| 279 |
+
```
|
| 280 |
+
POST /api/user/access_token
|
| 281 |
+
LQA-Ticket: <ticket>
|
| 282 |
+
```
|
| 283 |
+
|
| 284 |
+
需先通过 `GET /api/ticket` 获取一次性 ticket, 再携带 `LQA-Ticket` 请求头调用本接口, 生成新 token 后旧 token 立即失效
|
| 285 |
+
|
| 286 |
+
**响应 data:**
|
| 287 |
+
|
| 288 |
+
```json
|
| 289 |
+
{ "access_token": "eyJ..." }
|
| 290 |
+
```
|
| 291 |
+
|
| 292 |
+
---
|
timi_hok_game_translator/LQA_WMP/docs/deploy-guide.md
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# LQA 平台部署指南
|
| 2 |
+
|
| 3 |
+
> 适用对象: 需要在一台 **全新电脑 / 全新服务器** 上从零把 LQA (本地化质量检查) 平台跑起来的人
|
| 4 |
+
>
|
| 5 |
+
> 适用版本: Docker Compose 一键部署 (推荐) 或 本地源码开发部署,
|
| 6 |
+
> 本文档基于仓库根目录的 `README.md`、`docker-compose.yml`、`.env.example` 及 `server/README.md`、`web/README.md` 整理
|
| 7 |
+
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
## 一、平台简介与组件
|
| 11 |
+
|
| 12 |
+
LQA 平台由以下服务组成, 部署时它们要么打包进容器, 要么在本地分别启动:
|
| 13 |
+
|
| 14 |
+
| 组件 | 作用 | 技术 |
|
| 15 |
+
|---|---|---|
|
| 16 |
+
| MySQL 8 | 主数据库 | 容器 / 本地 |
|
| 17 |
+
| Redis 7 | 缓存、Session、Celery 消息队列 | 容器 / 本地 |
|
| 18 |
+
| server | 后端 API (Django + Gunicorn) | Python 3.12 |
|
| 19 |
+
| worker | Celery 异步任务 (AI 识别、自动提单、回归) | Python 3.12 |
|
| 20 |
+
| ai | AI 识别服务 (Flask, 内置离线 OCR) | 容器 / 外部服务 |
|
| 21 |
+
| web | 前端静态资源 + 反向代理 (Nginx) | Vue 3 + Vite |
|
| 22 |
+
|
| 23 |
+
**对外访问端口**: 默认 `8080` (容器部署), 本地开发前端 `3333`、后端 `8000`
|
| 24 |
+
|
| 25 |
+
---
|
| 26 |
+
|
| 27 |
+
## 二、两种部署方式对比
|
| 28 |
+
|
| 29 |
+
| 方式 | 适合场景 | 难度 | 依赖 |
|
| 30 |
+
|---|---|---|---|
|
| 31 |
+
| **A. Docker Compose 一键部署 (推荐)** | 生产 / 演示 / 给不懂 Python 的人 | ⭐ 简单 | 只需装 Docker |
|
| 32 |
+
| **B. 本地源码开发部署** | 二次开发、调试 | ⭐⭐⭐ 需配环境 | Python 3.12、Node 20、MySQL、Redis |
|
| 33 |
+
|
| 34 |
+
下面分别说明
|
| 35 |
+
|
| 36 |
+
---
|
| 37 |
+
|
| 38 |
+
## 三、方式 A: Docker Compose 一键部署 (推荐)
|
| 39 |
+
|
| 40 |
+
### 3.1 前置准备: 安装 Docker
|
| 41 |
+
|
| 42 |
+
- **Windows**: 下载安装 [Docker Desktop](https://www.docker.com/products/docker-desktop/), 安装后需在设置里勾选 **"Use the WSL 2 based engine"**; 首次启动需开启 WSL2 (控制面板 → 程序 → 启用或关闭 Windows 功能 → 勾选 "虚拟机平台" 和 "适用于 Linux 的 Windows 子系统", 重启后执行 `wsl --install`)
|
| 43 |
+
- **macOS**: 下载 [Docker Desktop for Mac](https://www.docker.com/products/docker-desktop/)
|
| 44 |
+
- **Linux (Ubuntu 示例)**:
|
| 45 |
+
```bash
|
| 46 |
+
sudo apt update
|
| 47 |
+
sudo apt install -y docker.io docker-compose-plugin
|
| 48 |
+
sudo usermod -aG docker $USER # 退出重登后免 sudo 用 docker
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
验证:
|
| 52 |
+
```bash
|
| 53 |
+
docker --version # 需 20.10+ (Windows/Mac 桌面版自带)
|
| 54 |
+
docker compose version # 需 v2 (命令是 docker compose, 不是 docker-compose)
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
### 3.2 获取代码
|
| 58 |
+
|
| 59 |
+
```bash
|
| 60 |
+
git clone git@github.com:your-org/WMP.git
|
| 61 |
+
cd WMP
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
> 若使用 HTTPS: `git clone https://github.com/your-org/WMP.git`
|
| 65 |
+
|
| 66 |
+
### 3.3 配置环境变量
|
| 67 |
+
|
| 68 |
+
```bash
|
| 69 |
+
cp .env.example .env
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
**必须修改的 4 项 (否则容器会因 `${VAR:?}` 校验报错或存在安全风险)**:
|
| 73 |
+
|
| 74 |
+
```ini
|
| 75 |
+
MYSQL_ROOT_PASSWORD=请改成随机串
|
| 76 |
+
MYSQL_PASSWORD=请改成随机串
|
| 77 |
+
REDIS_PASSWORD=请改成随机串
|
| 78 |
+
SECRET_KEY=请改成随机串
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
生成随机串 (任选其一):
|
| 82 |
+
```bash
|
| 83 |
+
# 方式 1:用 Python
|
| 84 |
+
python -c "import secrets;print(secrets.token_urlsafe(48))"
|
| 85 |
+
# 方式 2:用 openssl
|
| 86 |
+
openssl rand -base64 48
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
**其余常用项 (按需修改)**:
|
| 90 |
+
|
| 91 |
+
| 变量 | 默认值 | 说明 |
|
| 92 |
+
|---|---|---|
|
| 93 |
+
| `LQA_ADMIN_USERNAME` | `admin` | 初始超级管理员账号, 已存在时不覆盖 |
|
| 94 |
+
| `LQA_ADMIN_PASSWORD` | 空 (必填) | 初始超管密码, **必须设置** |
|
| 95 |
+
| `LQA_HTTP_PORT` | `8080` | 平台对外 HTTP 端口 |
|
| 96 |
+
| `PUBLIC_URL` | `http://localhost:8080` | 缺陷截图链接与 Webhook `{{lqa_server}}` 变量使用; 部署到别的主机需改成实际域名/IP |
|
| 97 |
+
| `ALLOW_REGISTER` | `true` | 是否开放自助注册 |
|
| 98 |
+
| `SESSION_COOKIE_SECURE` | `false` | HTTPS 部署时需设为 `true`, 否则浏览器可能拒绝发送会话 Cookie |
|
| 99 |
+
| `AI_BASE_URL` | 空 (用内置 ai 容器) | 若已有独立识别服务, 填其地址, 并加 `--scale ai=0` 跳过本地 ai |
|
| 100 |
+
| `OCR_ENGINE` / `OCR_PROVIDER` | `rapidocr` | 离线 OCR, 开箱即用; `paddleocr` 精度更高但镜像 +2GB |
|
| 101 |
+
| `AI_WORKERS` | `2` | ai 服务进程数, 按并发识别量调整 |
|
| 102 |
+
| `AI_HTTP_PORT` | `127.0.0.1:8086` | 默认只本机可访问 ai, 仅供调试 |
|
| 103 |
+
|
| 104 |
+
> `OCR_ENGINE` / `OCR_PROVIDER` 完整可选项与说明见 [lqa_service/README.md](../lqa_service/README.md)
|
| 105 |
+
|
| 106 |
+
### 3.4 启动
|
| 107 |
+
|
| 108 |
+
```bash
|
| 109 |
+
docker compose up -d --build
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
首次会拉取/构建镜像 (ai 镜像内含 OCR, 首次构建较慢, 约几分钟到十几分钟)
|
| 113 |
+
|
| 114 |
+
查看状态:
|
| 115 |
+
```bash
|
| 116 |
+
docker compose ps # 看各容器是否 healthy
|
| 117 |
+
docker compose logs -f # 实时看日志; Ctrl+C 退出
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
### 3.5 验证与登录
|
| 121 |
+
|
| 122 |
+
浏览器打开 `http://<服务器IP>:8080` (本机即 `http://localhost:8080`), 用 `.env` 里的 `LQA_ADMIN_USERNAME` / `LQA_ADMIN_PASSWORD` 登录
|
| 123 |
+
|
| 124 |
+
> 若打不开: ① 确认防火墙放行 `8080`; ② `docker compose ps` 看 `web` / `server` 是否 `healthy`; ③ `docker compose logs web` 看 Nginx 是否起来
|
| 125 |
+
|
| 126 |
+
### 3.6 首次使用必做配置
|
| 127 |
+
|
| 128 |
+
1. **系统管理 → 项目管理**: 创建项目, 并给使用平台的账号分配项目与角色 (超管默认无项目, 需自己建)
|
| 129 |
+
2. **项目设置 → 基础配置 → 还原执行**: 配置 Webhook (Jenkins / GitLab CI / 自建服务), 变量如 `{{job_id}}`、`{{regression}}`、`{{lqa_server}}` 见页面提示
|
| 130 |
+
3. **项目设置 → 缺陷系统**: 选择 平台内记录 / Bugzilla / 禅道, 填连接信息后点 "测试连接"
|
| 131 |
+
|
| 132 |
+
### 3.7 常用运维
|
| 133 |
+
|
| 134 |
+
```bash
|
| 135 |
+
docker compose down # 停止 (不删数据)
|
| 136 |
+
docker compose down -v # 停止并删除数据卷 (慎用! 会清空库)
|
| 137 |
+
docker compose restart server # 只重启后端
|
| 138 |
+
docker compose up -d --build # 改了 .env 或代码后重建
|
| 139 |
+
```
|
| 140 |
+
|
| 141 |
+
---
|
| 142 |
+
|
| 143 |
+
## 四、方式 B: 本地源码开发部署
|
| 144 |
+
|
| 145 |
+
适合需要改代码、跑测试的场景, 需要 **本机** 具备: Python 3.12、Node.js 20+、pnpm 11、MySQL 8、Redis 7
|
| 146 |
+
|
| 147 |
+
### 4.1 安装基础依赖
|
| 148 |
+
|
| 149 |
+
- **Python 3.12**: [python.org](https://www.python.org/downloads/) 或 `pyenv`; Windows 勾选 "Add to PATH"
|
| 150 |
+
- **Node.js 20 + pnpm 11**:
|
| 151 |
+
```bash
|
| 152 |
+
# 先装 Node 20 (含 npm), 再装 pnpm
|
| 153 |
+
npm install -g pnpm@11
|
| 154 |
+
node -v && pnpm -v
|
| 155 |
+
```
|
| 156 |
+
- **MySQL 8**: Windows 可用 [MySQL Installer](https://dev.mysql.com/downloads/installer/); Linux `sudo apt install mysql-server`
|
| 157 |
+
创建库与用户:
|
| 158 |
+
```sql
|
| 159 |
+
CREATE DATABASE lqa CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
| 160 |
+
CREATE USER 'lqa'@'localhost' IDENTIFIED BY '你的密码';
|
| 161 |
+
GRANT ALL PRIVILEGES ON lqa.* TO 'lqa'@'localhost';
|
| 162 |
+
FLUSH PRIVILEGES;
|
| 163 |
+
```
|
| 164 |
+
- **Redis 7**: Windows 用 [Memurai](https://www.memurai.com/) 或 WSL 内装; Linux `sudo apt install redis-server`
|
| 165 |
+
启动并设置密码 (与下面 `.env` 中 `REDIS_PASSWORD` 一致):
|
| 166 |
+
```bash
|
| 167 |
+
redis-server --requirepass 你的Redis密码
|
| 168 |
+
```
|
| 169 |
+
|
| 170 |
+
### 4.2 后端
|
| 171 |
+
|
| 172 |
+
```bash
|
| 173 |
+
cd server
|
| 174 |
+
python -m venv .venv
|
| 175 |
+
.venv\Scripts\activate # Windows 激活; Linux/macOS: source .venv/bin/activate
|
| 176 |
+
pip install -r requirements.txt
|
| 177 |
+
|
| 178 |
+
cp .env.example .env # 修改 MYSQL_URL / REDIS_URL 等 (见 4.5)
|
| 179 |
+
python manage.py migrate # 建表
|
| 180 |
+
python manage.py init_data # 初始化系统模板 (缺陷类型、区域语言)
|
| 181 |
+
python manage.py init_admin --username admin --password 'Admin123456'
|
| 182 |
+
```
|
| 183 |
+
|
| 184 |
+
启动 (两个终端):
|
| 185 |
+
|
| 186 |
+
```bash
|
| 187 |
+
# 终端 1: API 服务
|
| 188 |
+
python manage.py runserver 0.0.0.0:8000
|
| 189 |
+
|
| 190 |
+
# 终端 2: Celery 异步任务 (Windows 必须加 -P solo)
|
| 191 |
+
celery -A celery_app worker -l info -P solo # Windows
|
| 192 |
+
# celery -A celery_app worker -l info # Linux/macOS
|
| 193 |
+
```
|
| 194 |
+
|
| 195 |
+
### 4.3 前端
|
| 196 |
+
|
| 197 |
+
```bash
|
| 198 |
+
cd web
|
| 199 |
+
pnpm install
|
| 200 |
+
pnpm dev # http://localhost:3333
|
| 201 |
+
```
|
| 202 |
+
|
| 203 |
+
开发时接口请求 `/api-pro/*` 由 Vite 代理到后端 `http://127.0.0.1:8000/`,
|
| 204 |
+
要指向别的后端地址, 在 `web/` 下新建 `.env.development.local` (已被 git 忽略):
|
| 205 |
+
|
| 206 |
+
```
|
| 207 |
+
VITE_PROXY_TARGET = 'http://192.168.1.10:8000/'
|
| 208 |
+
```
|
| 209 |
+
|
| 210 |
+
### 4.4 后端 .env 关键项 (本地开发)
|
| 211 |
+
|
| 212 |
+
`server/.env` 至少要有:
|
| 213 |
+
|
| 214 |
+
```ini
|
| 215 |
+
SECRET_KEY=随机串
|
| 216 |
+
MYSQL_URL=mysql://lqa:你的密码@127.0.0.1:3306/lqa
|
| 217 |
+
REDIS_URL=rediscache://:你的Redis密码@127.0.0.1:6379/1
|
| 218 |
+
CELERY_BROKER_URL=redis://:你的Redis密码@127.0.0.1:6379/2
|
| 219 |
+
CELERY_BACKEND_URL=redis://:你的Redis密码@127.0.0.1:6379/2
|
| 220 |
+
LQA_ADMIN_USERNAME=admin
|
| 221 |
+
LQA_ADMIN_PASSWORD=Admin123456
|
| 222 |
+
AI_BASE_URL=http://<外部AI服务地址>:8086 # 指向外部 AI 识别服务, 详见下方 "对接外部 AI 平台"
|
| 223 |
+
```
|
| 224 |
+
|
| 225 |
+
### 4.5 对接外部 AI 平台
|
| 226 |
+
|
| 227 |
+
平台本身不内置 AI 识别算法, 识别能力由 **外部 AI 识别服务** 提供, 二者通过 HTTP 对接:
|
| 228 |
+
|
| 229 |
+
- **容器部署**: 默认随编排启动内置的 `ai` 容器, 无需配置; 若你已有独立部署的识别服务, 在 `.env` 中设置 `AI_BASE_URL` 指向它, 并用 `docker compose up -d --scale ai=0` 跳过本地 `ai` 容器即可
|
| 230 |
+
- **本地源码部署**: 在 `server/.env` 中设置 `AI_BASE_URL` 指向外部识别服务地址, 重启后端生效
|
| 231 |
+
|
| 232 |
+
> 平台调用约定: 对 `POST {AI_BASE_URL}/image/lqa_check/` 发起请求, 并自动带上 `project-method: <AI识别项目名>_lqa` 请求头 ("AI识别项目名" 在 Web 端 "项目设置" 中配置), 具体的识别服务如何部署、支持哪些 OCR 引擎, 不属于本平台部署文档范畴
|
| 233 |
+
|
| 234 |
+
### 4.6 验证
|
| 235 |
+
|
| 236 |
+
1. 浏览器打开 `http://localhost:3333`, 用上面的超管账号登录
|
| 237 |
+
2. `GET http://127.0.0.1:8000/api/health` (免登录) 返回健康信息
|
| 238 |
+
|
| 239 |
+
---
|
| 240 |
+
|
| 241 |
+
## 五、为还原端生成 access_token (对接必做)
|
| 242 |
+
|
| 243 |
+
还原端 (Unity / UE 插件) 通过 `LQA-Authorization: <access_token>` 调用接口, 需要给对应账号生成 token:
|
| 244 |
+
|
| 245 |
+
```bash
|
| 246 |
+
cd server
|
| 247 |
+
.venv\Scripts\activate
|
| 248 |
+
python manage.py update_access_token -u <用户ID或用户名> [-e 2592000] # 默认 30 天有效
|
| 249 |
+
```
|
| 250 |
+
|
| 251 |
+
或在 Web 端登录后: `GET /api/ticket` 取一次性 ticket → 带 `LQA-Ticket` 调 `POST /api/user/access_token` 换 token
|
| 252 |
+
|
| 253 |
+
还原端只需 3 个接口:
|
| 254 |
+
|
| 255 |
+
| 接口 | 说明 |
|
| 256 |
+
|---|---|
|
| 257 |
+
| `GET /api/job/datas` | 拉取任务测试数据 |
|
| 258 |
+
| `POST /api/image/entity` | 上传截图 (multipart/form-data) |
|
| 259 |
+
| `POST /api/job/device` | 上报设备信息与执行进度 |
|
| 260 |
+
|
| 261 |
+
详见 [还原端集成指南](../docs/integration/restorer.md)。
|
| 262 |
+
|
| 263 |
+
---
|
| 264 |
+
|
| 265 |
+
## 六、常见问题 (FAQ)
|
| 266 |
+
|
| 267 |
+
**Q1: 容器起不来, 报 `${MYSQL_PASSWORD:?请在 .env 中设置 ...}`**
|
| 268 |
+
→ 没复制或没填 `.env` 里的必填项, 回去执行 `cp .env.example .env` 并把 4 个必填项填好
|
| 269 |
+
|
| 270 |
+
**Q2: `docker compose` 命令找不到**
|
| 271 |
+
→ 用的是旧版 `docker-compose`(带横线), 装 `docker-compose-plugin` 后用 `docker compose` (空格) 即可; 或单独装 `pip install docker-compose`
|
| 272 |
+
|
| 273 |
+
**Q3: Windows 上 Celery 启动报错 / 卡死**
|
| 274 |
+
→ Windows 必须加 `-P solo`: `celery -A celery_app worker -l info -P solo`
|
| 275 |
+
|
| 276 |
+
**Q4: 平台能打开但 "识别" 一直没结果**
|
| 277 |
+
→ worker 未启动, 或 `AI_BASE_URL` 指向的 AI 识别服务不可达, 容器部署看 `docker compose logs worker` 和 `docker compose logs ai`; 本地部署确认 `server/.env` 中的 `AI_BASE_URL` 能访问、并已重启后端
|
| 278 |
+
|
| 279 |
+
**Q5: Webhook 触发失败 (CORS)**
|
| 280 |
+
→ 还原执行由 **浏览器** 发起, 目标服务 (Jenkins 等) 需允许平台域名跨域; Jenkins 装 CORS 插件或加反向代理
|
| 281 |
+
|
| 282 |
+
**Q6: 改了 .env 不生效**
|
| 283 |
+
→ 容器部署需 `docker compose up -d --build` 重建; 本地部署需重启 runserver 与 worker
|
| 284 |
+
|
| 285 |
+
---
|
| 286 |
+
|
| 287 |
+
## 七、端口速查表
|
| 288 |
+
|
| 289 |
+
| 端口 | 服务 | 说明 |
|
| 290 |
+
|---|---|---|
|
| 291 |
+
| 8080 | web (Nginx) | 容器部署对外访问入口 |
|
| 292 |
+
| 8000 | server | 本地开发后端 |
|
| 293 |
+
| 3333 | web (Vite) | 本地开发前端 |
|
| 294 |
+
| 8086 | ai | AI 识别服务 (默认仅本机, 容器内部 `ai:8086`) |
|
| 295 |
+
| 3306 | mysql | 数据库 |
|
| 296 |
+
| 6379 | redis | 缓存/队列 |
|
| 297 |
+
|
| 298 |
+
---
|
timi_hok_game_translator/LQA_WMP/docs/integration/restorer.md
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 还原端集成指南
|
| 2 |
+
|
| 3 |
+
本文档面向还原端开发者 (Unity/UE 编辑器插件、自动化脚本等), 描述与 LQA 平台交互的完整流程
|
| 4 |
+
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## 概述
|
| 8 |
+
|
| 9 |
+
还原端的职责:
|
| 10 |
+
1. 被 Webhook 触发后启动
|
| 11 |
+
2. 从平台拉取本次任务的测试数据列表
|
| 12 |
+
3. 按数据逐一生成各语言截图, 上传到平台
|
| 13 |
+
4. 上报设备信息与进度
|
| 14 |
+
|
| 15 |
+
平台侧的职责:
|
| 16 |
+
- 在浏览器中调用还原端配置的 Webhook, 触发还原
|
| 17 |
+
- 接收截图、异步调用 AI 识别服务、生成缺陷报告
|
| 18 |
+
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
## 认证
|
| 22 |
+
|
| 23 |
+
还原端使用 **access_token** 认证, 每个请求携带请求头:
|
| 24 |
+
|
| 25 |
+
```
|
| 26 |
+
LQA-Authorization: <access_token>
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
**获取 access_token (由平台管理员操作):**
|
| 30 |
+
|
| 31 |
+
```bash
|
| 32 |
+
# 在后端服务器上执行
|
| 33 |
+
python manage.py update_access_token -u <user_id> -e 2592000
|
| 34 |
+
# -e 指定有效期 (秒), 默认 30 天
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
也可以通过接口方式获取, 详见 [API 通用约定 - 认证](../api/overview.md)
|
| 38 |
+
|
| 39 |
+
---
|
| 40 |
+
|
| 41 |
+
## 交互流程
|
| 42 |
+
|
| 43 |
+
```
|
| 44 |
+
平台(浏览器) 还原端
|
| 45 |
+
│ │
|
| 46 |
+
│── Webhook 触发 ──→ │ 携带 job_id、languages、lqa_server 等参数
|
| 47 |
+
│ │
|
| 48 |
+
│ │── GET /api/job/datas ──→ 平台
|
| 49 |
+
│ │←── 测试数据列表 ─────────
|
| 50 |
+
│ │
|
| 51 |
+
│ (循环处理每个数据) │
|
| 52 |
+
│ │── POST /api/image/entity ──→ 平台 (上传截图)
|
| 53 |
+
│ │←── image_id ─────────────
|
| 54 |
+
│ │
|
| 55 |
+
│ │── POST /api/job/device ──→ 平台 (上报进度)
|
| 56 |
+
│ │←── 确认 ────────────────
|
| 57 |
+
│ │
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
Webhook 参数由平台在 "项目设置 > 基础配置 > 还原执行" 中配置, 可用变量:
|
| 61 |
+
|
| 62 |
+
| 变量 | 说明 |
|
| 63 |
+
|---|---|
|
| 64 |
+
| `{{job_id}}` | 任务 ID |
|
| 65 |
+
| `{{languages}}` | 语言列表 (逗号分隔的平台标准编码, 如 `LAN_EN_US,LAN_JA_JP`) |
|
| 66 |
+
| `{{language_values}}` | 平台标准语言编码数组 (JSON), 如 `["LAN_EN_US","LAN_JA_JP"]` |
|
| 67 |
+
| `{{ue_languages}}` | UE 还原插件专用语言编码 (逗号分隔), 如 `LAN_EU_EN,LAN_JP_JP`; 拉起 UE 时命令行 `-Language=` 应使用此值 |
|
| 68 |
+
| `{{ue_language_values}}` | UE 还原插件专用语言编码数组(JSON) |
|
| 69 |
+
| `{{regression}}` | `0` 普通, `1` 回归 |
|
| 70 |
+
| `{{lqa_server}}` | 平台访问地址 (来自 `PUBLIC_URL` 配置) |
|
| 71 |
+
|
| 72 |
+
> **UE 还原插件语言编码说明**
|
| 73 |
+
> 平台内部统一使用 ISO 国家码 (如韩语 `LAN_KO_KR`、日语 `LAN_JA_JP`), 而 UE 还原插件 `ConfigManager.cpp` 的 `LanguageMap` 使用另一套命名 (如韩语 `LAN_KO_KO`、日语 `LAN_JP_JP`)
|
| 74 |
+
> 当还原端直接拼接 UE 启动命令时, 请优先使用 `{{ue_languages}}` / `{{ue_language_values}}` 变量, 平台已完成反向翻译; 否则 UE 命令行 `-Language=` 传入平台标准编码将无法被插件识别, 还原会降级到默认语言 (英语)
|
| 75 |
+
|
| 76 |
+
---
|
| 77 |
+
|
| 78 |
+
## 接口说明
|
| 79 |
+
|
| 80 |
+
### 1. 拉取测试数据
|
| 81 |
+
|
| 82 |
+
```
|
| 83 |
+
GET /api/job/datas?job_id=<id>&language=<lang>®ression=<0|1>
|
| 84 |
+
LQA-Authorization: <access_token>
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
建议分语言分批拉取
|
| 88 |
+
|
| 89 |
+
**完整请求示例:**
|
| 90 |
+
|
| 91 |
+
```
|
| 92 |
+
GET https://lqa.example.com/api/job/datas?job_id=10&language=2®ression=0&count=500
|
| 93 |
+
LQA-Authorization: eyJ...
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
**响应示例:**
|
| 97 |
+
|
| 98 |
+
```json
|
| 99 |
+
{
|
| 100 |
+
"code": 0,
|
| 101 |
+
"data": {
|
| 102 |
+
"datas": [
|
| 103 |
+
{ "id": 501, "file_path": "Assets/UI/main.prefab", "module_id": 10 },
|
| 104 |
+
{ "id": 502, "file_path": "Assets/UI/shop.prefab", "module_id": 11 }
|
| 105 |
+
],
|
| 106 |
+
"bug_ids": []
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
回归任务时 `bug_ids` 包含需要回归的缺陷 ID, 还原端在上传截图时需要传回这些 `bug_ids`
|
| 112 |
+
|
| 113 |
+
**增量拉取 (分批):**
|
| 114 |
+
|
| 115 |
+
```
|
| 116 |
+
GET /api/job/datas?job_id=10&language=2&count=100&minID=0
|
| 117 |
+
GET /api/job/datas?job_id=10&language=2&count=100&minID=502
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
---
|
| 121 |
+
|
| 122 |
+
### 2. 上传截图
|
| 123 |
+
|
| 124 |
+
```
|
| 125 |
+
POST /api/image/entity
|
| 126 |
+
Content-Type: multipart/form-data
|
| 127 |
+
LQA-Authorization: <access_token>
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
**Form 字段:**
|
| 131 |
+
|
| 132 |
+
| 字段 | 类型 | 必填 | 说明 |
|
| 133 |
+
|---|---|---|---|
|
| 134 |
+
| `file` | file | 是 | 截图文件 (PNG 推荐) |
|
| 135 |
+
| `project_id` | int | 是 | 项目 ID |
|
| 136 |
+
| `job_id` | int | 是 | 任务 ID |
|
| 137 |
+
| `data_id` | int | 是 | 测试数据 ID (来自上一步) |
|
| 138 |
+
| `language` | int | 是 | 语言值 |
|
| 139 |
+
| `rect_locations` | string | 是 | 文本控件位置 JSON (见下方格式) |
|
| 140 |
+
| `ai_sign` | int | 否 | `1` 上传后立即触发 AI 识别 |
|
| 141 |
+
| `discern` | int | 否 | `0` 全量 (默认), `1` 差异识别 |
|
| 142 |
+
| `create_bug` | int | 否 | `1` 识别后自动提单 |
|
| 143 |
+
| `regression` | int | 否 | `1` 表示回归任务 |
|
| 144 |
+
| `bug_ids` | string | 否 | 回归时: 需回归的缺陷 ID, 逗号分隔 |
|
| 145 |
+
|
| 146 |
+
**`rect_locations` 格式:**
|
| 147 |
+
|
| 148 |
+
`rect_locations` 是一个 JSON 字符串, 描述截图中各文本控件的位置 (用于 AI 识别定位文字区域):
|
| 149 |
+
|
| 150 |
+
```json
|
| 151 |
+
[
|
| 152 |
+
{
|
| 153 |
+
"x": 100,
|
| 154 |
+
"y": 200,
|
| 155 |
+
"width": 300,
|
| 156 |
+
"height": 50,
|
| 157 |
+
"key": "ui_title",
|
| 158 |
+
"text": "标题文本"
|
| 159 |
+
}
|
| 160 |
+
]
|
| 161 |
+
```
|
| 162 |
+
|
| 163 |
+
字段含义:
|
| 164 |
+
|
| 165 |
+
| 字段 | 说明 |
|
| 166 |
+
|---|---|
|
| 167 |
+
| `x`, `y` | 控件左上角坐标 (像素) |
|
| 168 |
+
| `width`, `height` | 控件宽高 (像素) |
|
| 169 |
+
| `key` | 控件唯一标识 |
|
| 170 |
+
| `text` | 控件当前显示文本 |
|
| 171 |
+
|
| 172 |
+
**响应示例:**
|
| 173 |
+
|
| 174 |
+
```json
|
| 175 |
+
{
|
| 176 |
+
"code": 0,
|
| 177 |
+
"data": {
|
| 178 |
+
"image": {
|
| 179 |
+
"id": 200,
|
| 180 |
+
"file_path": "/media/project/2/job/10/image/ui_main_zh.png"
|
| 181 |
+
},
|
| 182 |
+
"task_id": "abc123-..."
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
```
|
| 186 |
+
|
| 187 |
+
---
|
| 188 |
+
|
| 189 |
+
### 3. 上报设备与进度
|
| 190 |
+
|
| 191 |
+
```
|
| 192 |
+
POST /api/job/device
|
| 193 |
+
Content-Type: application/json
|
| 194 |
+
LQA-Authorization: <access_token>
|
| 195 |
+
```
|
| 196 |
+
|
| 197 |
+
建议每完成一批截图上传后上报一次进度
|
| 198 |
+
|
| 199 |
+
**请求体:**
|
| 200 |
+
|
| 201 |
+
```json
|
| 202 |
+
{
|
| 203 |
+
"job_id": 10,
|
| 204 |
+
"execute_pc": "PC-RENDER-001",
|
| 205 |
+
"language": 2,
|
| 206 |
+
"status": 2,
|
| 207 |
+
"progress": 45,
|
| 208 |
+
"total": 100
|
| 209 |
+
}
|
| 210 |
+
```
|
| 211 |
+
|
| 212 |
+
| 字段 | 说明 |
|
| 213 |
+
|---|---|
|
| 214 |
+
| `execute_pc` | 还原设备标识 (机器名或 IP) |
|
| 215 |
+
| `language` | 当前正在处理的语言 |
|
| 216 |
+
| `status` | `1` 等待, `2` 执行中, `3` 完成, `4` 失败 |
|
| 217 |
+
| `progress` | 已完成数量 |
|
| 218 |
+
| `total` | 总数量 |
|
| 219 |
+
|
| 220 |
+
---
|
| 221 |
+
|
| 222 |
+
## 错误处理
|
| 223 |
+
|
| 224 |
+
所有接口返回 `code != 0` 时为错误, `msg` 字段包含错误描述
|
| 225 |
+
|
| 226 |
+
| code | 建议处理方式 |
|
| 227 |
+
|---|---|
|
| 228 |
+
| `1003` | access_token 失效, 需重新获取 |
|
| 229 |
+
| `1002` | 请求参数错误, 检查字段 |
|
| 230 |
+
| `1005` | 资源不存在, `job_id` 或 `data_id` 可能已被删除 |
|
| 231 |
+
| `1001` | 通用错误, 记录日志, 可重试 |
|
| 232 |
+
|
| 233 |
+
建议对上传失败的截图进行重试 (最多 3 次), 重试时使用相同的 `data_id` 和 `language`, 平台会自动管理 `iteration` 版本
|
| 234 |
+
|
| 235 |
+
---
|
| 236 |
+
|
| 237 |
+
## 完整示例 (Python 伪代码)
|
| 238 |
+
|
| 239 |
+
```python
|
| 240 |
+
import requests
|
| 241 |
+
|
| 242 |
+
LQA_SERVER = "https://lqa.example.com"
|
| 243 |
+
ACCESS_TOKEN = "eyJ..."
|
| 244 |
+
HEADERS = {"LQA-Authorization": ACCESS_TOKEN}
|
| 245 |
+
|
| 246 |
+
def run_restore(job_id, project_id, languages):
|
| 247 |
+
for language in languages:
|
| 248 |
+
# 1. 拉取测试数据
|
| 249 |
+
resp = requests.get(
|
| 250 |
+
f"{LQA_SERVER}/api/job/datas",
|
| 251 |
+
params={"job_id": job_id, "language": language},
|
| 252 |
+
headers=HEADERS
|
| 253 |
+
)
|
| 254 |
+
datas = resp.json()["data"]["datas"]
|
| 255 |
+
|
| 256 |
+
for i, data in enumerate(datas):
|
| 257 |
+
# 2. 生成截图(业务逻辑)
|
| 258 |
+
screenshot, rect_locations = render_screenshot(data, language)
|
| 259 |
+
|
| 260 |
+
# 3. 上传截图
|
| 261 |
+
requests.post(
|
| 262 |
+
f"{LQA_SERVER}/api/image/entity",
|
| 263 |
+
data={
|
| 264 |
+
"project_id": project_id,
|
| 265 |
+
"job_id": job_id,
|
| 266 |
+
"data_id": data["id"],
|
| 267 |
+
"language": language,
|
| 268 |
+
"rect_locations": json.dumps(rect_locations),
|
| 269 |
+
"ai_sign": 1,
|
| 270 |
+
},
|
| 271 |
+
files={"file": ("screenshot.png", screenshot, "image/png")},
|
| 272 |
+
headers=HEADERS
|
| 273 |
+
)
|
| 274 |
+
|
| 275 |
+
# 4. 上报进度
|
| 276 |
+
if i % 10 == 0:
|
| 277 |
+
requests.post(
|
| 278 |
+
f"{LQA_SERVER}/api/job/device",
|
| 279 |
+
json={
|
| 280 |
+
"job_id": job_id,
|
| 281 |
+
"execute_pc": "MY-PC-001",
|
| 282 |
+
"language": language,
|
| 283 |
+
"status": 2,
|
| 284 |
+
"progress": i + 1,
|
| 285 |
+
"total": len(datas)
|
| 286 |
+
},
|
| 287 |
+
headers=HEADERS
|
| 288 |
+
)
|
| 289 |
+
```
|
| 290 |
+
|
| 291 |
+
---
|
timi_hok_game_translator/LQA_WMP/docs/web-guide.md
ADDED
|
@@ -0,0 +1,492 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# LQA Web 平台使用文档
|
| 2 |
+
|
| 3 |
+
本手册面向 **测试工程师 / 项目管理员 / 开发同学**, 介绍如何通过 LQA Web 平台 (以下简称 “平台”) 完成本地化质量检查的日常工作: 从登录、创建项目、配置还原端与缺陷系统, 到执行还原任务、审核 AI 识别结果、提交并回归验证缺陷
|
| 4 |
+
|
| 5 |
+
> 平台默认访问地址: `http://<服务器IP>:8080` (由 `.env` 中 `LQA_HTTP_PORT` 决定, 默认 `8080`),
|
| 6 |
+
> 部署与运维相关内容请参阅项目根 [README.md](../README.md)
|
| 7 |
+
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
## 1. 概览
|
| 11 |
+
|
| 12 |
+
### 1.1 功能地图
|
| 13 |
+
|
| 14 |
+
```mermaid
|
| 15 |
+
flowchart LR
|
| 16 |
+
A[登录 / 注册] --> B[系统管理]
|
| 17 |
+
A --> C[项目设置]
|
| 18 |
+
A --> D[任务管理]
|
| 19 |
+
A --> E[数据管理]
|
| 20 |
+
|
| 21 |
+
B --> B1[项目管理]
|
| 22 |
+
B --> B2[用户管理]
|
| 23 |
+
B --> B3[全局设置]
|
| 24 |
+
|
| 25 |
+
C --> C1[缺陷类型]
|
| 26 |
+
C --> C2[区域语言]
|
| 27 |
+
C --> C3[图片还原]
|
| 28 |
+
C --> C4[模块]
|
| 29 |
+
C --> C5[还原执行 Webhook]
|
| 30 |
+
C --> C6[缺陷系统]
|
| 31 |
+
C --> C7[提单模板]
|
| 32 |
+
|
| 33 |
+
D --> D1[创建/编辑任务]
|
| 34 |
+
D --> D2[开始/重试/结束]
|
| 35 |
+
D --> D3[执行进度]
|
| 36 |
+
D --> D4[结果审核]
|
| 37 |
+
D --> D5[缺陷单]
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
### 1.2 角色
|
| 41 |
+
|
| 42 |
+
| 角色 | 可见菜单 | 典型操作 |
|
| 43 |
+
|---|---|---|
|
| 44 |
+
| **超级管理员** | 系统管理 (项目/用户/全局设置) + 所有项目 | 创建项目、创建/禁用用户、全局配置 |
|
| 45 |
+
| **项目管理员** | 自己的项目下 全部菜单 | 配置 Webhook/缺陷系统、建任务、建缺陷类型 |
|
| 46 |
+
| **测试人员** | 任务管理、数据管理、结果审核、缺陷单 | 跑任务、审核结果、提单、回归 |
|
| 47 |
+
| **开发人员** | 任务管理 (只读)、缺陷单 | 查看任务、处理缺陷 |
|
| 48 |
+
|
| 49 |
+
> 角色由 **超级管理员** 在 “项目设置 → 用户管理” 中为用户在具体项目下分配, 一个用户可同时在多个项目中拥有不同角色
|
| 50 |
+
|
| 51 |
+
### 1.3 顶部与左侧导航
|
| 52 |
+
|
| 53 |
+
- **左侧菜单**: 按当前选中的项目动态生成, 顶部切换项目后, 整个左侧菜单会刷新为该项目下的功能
|
| 54 |
+
- **顶部项目选择器**: 切换项目视角; **系统管理** 视角独立, 用于全局配置
|
| 55 |
+
- **右上角头像**: 个人信息、修改密码、退出登录
|
| 56 |
+
|
| 57 |
+
---
|
| 58 |
+
|
| 59 |
+
## 2. 账号与登录
|
| 60 |
+
|
| 61 |
+
### 2.1 登录
|
| 62 |
+
|
| 63 |
+
1. 浏览器访问平台地址, 输入用户名与密码
|
| 64 |
+
2. 平台支持自助注册 (由 `.env` 中 `ALLOW_REGISTER` 控制, 默认开启), 注册后账号默认无任何项目权限, 需由超级管理员到 “系统管理 → 用户管理” 中分配项目角色
|
| 65 |
+
3. 忘记密码请联系超级管理员, 在用户管理页面点击 “重置密码”
|
| 66 |
+
|
| 67 |
+
### 2.2 自助注册
|
| 68 |
+
|
| 69 |
+
- 登录页右下角若出现 **注册账号** 入口即为开放注册状态
|
| 70 |
+
- 注册流程: 填写 **用户名 / 中文名 / 所属部门 / 密码 / 确认密码** → 提交, 无需邮件验证, 注册后请联系管理员分配项目
|
| 71 |
+
|
| 72 |
+
### 2.3 修改密码 / 退出登录
|
| 73 |
+
|
| 74 |
+
- 点击右上角头像 → **修改密码**: 需要输入原密码
|
| 75 |
+
- 退出登录: 点击头像 → **退出登录**
|
| 76 |
+
|
| 77 |
+
---
|
| 78 |
+
|
| 79 |
+
## 3. 系统管理 (超级管理员)
|
| 80 |
+
|
| 81 |
+
### 3.1 项目管理 (`系统管理 → 项目管理`)
|
| 82 |
+
|
| 83 |
+
用于创建和维护所有项目, 字段说明:
|
| 84 |
+
|
| 85 |
+
| 字段 | 必填 | 说明 |
|
| 86 |
+
|---|---|---|
|
| 87 |
+
| 所属团队 | 否 | 用于分组标识 |
|
| 88 |
+
| 名称 | 是 | 项目中文名 |
|
| 89 |
+
| 项目代号 (code) | 是 | 英文代号, `[A-Za-z0-9_-]{2,100}`, **创建后不可修改**; 用于提单模板目录 `templates/spec2/<代号小写>` |
|
| 90 |
+
| AI 识别项目名 (cvtest_project) | 是 | AI 识别服务中的项目标识, 调用时拼成 `<项目名>_lqa` 作为 `project-method`, 未填写时 **无法创建任务** |
|
| 91 |
+
| 项目类型 | 是 | 平台级 / 项目级 (默认项目级) |
|
| 92 |
+
| 游戏类型 | 是 | 多选:手游 / 端游 / 页游 / app / 小游戏 |
|
| 93 |
+
| 研发阶段 | 是 | 上线运营 / 下线 / 研发期 / 保密 |
|
| 94 |
+
| 测试经理 | 是 | 平台用户名; 创建项目后会自动赋予 “项目管理员” 角色, 多人以 `;` 分隔 |
|
| 95 |
+
|
| 96 |
+
> 创建完成后, 顶部项目选择器会出现新项目, 切换过去即可进入该项目的功能菜单
|
| 97 |
+
|
| 98 |
+
### 3.2 用户管理 (`系统管理 → 用户管理`)
|
| 99 |
+
|
| 100 |
+
- **全局视角**: 可按 `英文名 / 中文名 / 所属部门 / 所属项目 / 是否管理员` 搜索; 可新增用户、重置密码、禁用账号
|
| 101 |
+
- **按项目视角**: 进入某个项目的 `项目设置 → 用户管理`, 这里的新增/编辑作用于当前项目的角色分配
|
| 102 |
+
- 支持 **导出用户列表 CSV** (右上角 “导出” 按钮), 角色会翻译成 `项目名/角色名` 的可读文本
|
| 103 |
+
|
| 104 |
+
字段:
|
| 105 |
+
|
| 106 |
+
| 字段 | 说明 |
|
| 107 |
+
|---|---|
|
| 108 |
+
| 英文名 | 唯一标识, 创建后不可改 |
|
| 109 |
+
| 中文名 / 所属部门 | 用户自助注册时填写, 管理员可改 |
|
| 110 |
+
| 角色 | 多选, 格式 `项目/角色`, 使用级联选择器 |
|
| 111 |
+
|
| 112 |
+
### 3.3 全局设置 (`系统管理 → 设置`)
|
| 113 |
+
|
| 114 |
+
- 调整系统级别开关、全局提示等 (具体项按部署版本不同略有差异)
|
| 115 |
+
|
| 116 |
+
---
|
| 117 |
+
|
| 118 |
+
## 4. 项目设置 (项目管理员)
|
| 119 |
+
|
| 120 |
+
进入某个项目后, 左侧菜单会出现 **���目设置**, 分为以下 Tab:
|
| 121 |
+
|
| 122 |
+
> 不同角色可见的 Tab 不同, 普通测试人员只能看到 **模块** 和 **提单**
|
| 123 |
+
|
| 124 |
+
### 4.1 缺陷类型
|
| 125 |
+
|
| 126 |
+
维护项目的缺陷分类 (如: **漏译**、**超框**、**错译**、**漏 Key**、**重叠** 等)
|
| 127 |
+
|
| 128 |
+
- 新建缺陷类型时需填写: **名称、是否启用、排序、是否 AI 识别类型**
|
| 129 |
+
- AI 识别类型会在 **创建任务 → 识别缺陷类型** 多选中出现, 决定本次任务 AI 会检查哪些问题
|
| 130 |
+
|
| 131 |
+
### 4.2 区域语言
|
| 132 |
+
|
| 133 |
+
维护项目使用的区域语言编码, 例如:
|
| 134 |
+
|
| 135 |
+
| 显示名 | 编码 | PO 代码 |
|
| 136 |
+
|---|---|---|
|
| 137 |
+
| 英语 | `LAN_EU_EN` | `en` |
|
| 138 |
+
| 日语 | `LAN_JP_JP` | `ja` |
|
| 139 |
+
| 简体中文 | `LAN_CHS_CHS` | `zh` |
|
| 140 |
+
|
| 141 |
+
- 可增删, 但 **编码必须与还原端插件保持一致** (在 UE/Unity 插件配置或命令行传入)
|
| 142 |
+
- 排序决定了创建任务时语言选择器的默认顺序
|
| 143 |
+
|
| 144 |
+
### 4.3 图片还原
|
| 145 |
+
|
| 146 |
+
配置 **语言根目录** 和 **路径模板**, 用于还原端定位每种语言的截图位置
|
| 147 |
+
|
| 148 |
+
- 多条配置可共存: 每条配置可展开编辑 **语言编码 ↔ 文件路径** 的映射表
|
| 149 |
+
- 该配置写入变量 `{{language_path}}`, 可在 Webhook 请求体中直接使用
|
| 150 |
+
|
| 151 |
+
### 4.4 模块
|
| 152 |
+
|
| 153 |
+
维护业务模块树 (如: **登录 / 大厅 / 战斗 / 商店**)
|
| 154 |
+
|
| 155 |
+
- 模块用于筛选测试数据、组织任务与缺陷
|
| 156 |
+
- 支持多级, 字段: **上级模块、名称、显示名、备注、是否启用**
|
| 157 |
+
|
| 158 |
+
### 4.5 还原执行 (Webhook)
|
| 159 |
+
|
| 160 |
+
> 这是接入 Jenkins / GitLab CI / 自建还原服务 的核心配置
|
| 161 |
+
> **开始任务 / 重试任务** 时, 由 **浏览器** 直接请求该 Webhook, 再由 Webhook 后端拉起还原进程
|
| 162 |
+
|
| 163 |
+
#### 字段
|
| 164 |
+
|
| 165 |
+
| 字段 | 示例 | 说明 |
|
| 166 |
+
|---|---|---|
|
| 167 |
+
| Webhook 地址 | `https://jenkins.example.com/job/lqa/buildWithParameters?token=xxx&JOB_ID={{job_id}}` | `http(s)://` 开头 |
|
| 168 |
+
| 请求方法 | `POST` / `PUT` / `GET` | GET 不填请求体 |
|
| 169 |
+
| 请求头 (JSON) | `{"Authorization": "Bearer xxx"}` | JSON 对象, 可为空 |
|
| 170 |
+
| 请求体 (JSON) | `{"job_id": "{{job_id}}", "regression": "{{regression}}"}` | JSON 对象/数组, **留空时自动发送全部变量** |
|
| 171 |
+
| 编辑器路径 | `D:/UE/Engine/Binaries/Win64/UE4Editor.exe` | 还原端拉取配置时返回, 也可作为 `{{editor_path}}` |
|
| 172 |
+
| 编辑器版本 | `5.3.2` | `{{editor_version}}` |
|
| 173 |
+
|
| 174 |
+
#### 可用变量 (在地址、请求头、请求体中以 `{{变量名}}` 使用)
|
| 175 |
+
|
| 176 |
+
| 变量 | 说明 |
|
| 177 |
+
|---|---|
|
| 178 |
+
| `job_id` / `job_name` | 任务 ID / 名称 |
|
| 179 |
+
| `parent_job_id` | 父任务 ID (回归任务时有值, 否则为 0) |
|
| 180 |
+
| `project_id` / `project_code` / `project_name` | 项目信息 |
|
| 181 |
+
| `languages` | 还原语言编码, 逗号分隔, 如 `LAN_EU_EN,LAN_JP_JP` |
|
| 182 |
+
| `language_values` | 还原语言值数组, 如 `[2, 6]` |
|
| 183 |
+
| `regression` | **执行类型: 0 普通 / 1 回归 / 2 重试** |
|
| 184 |
+
| `discern` | 识别方式: 0 全量 / 1 差异 |
|
| 185 |
+
| `create_bug` | 识别后是否自动提单: 0/1 |
|
| 186 |
+
| `svn_url` / `svn_version` | 资源仓库与版本 |
|
| 187 |
+
| `language_path` | 图片还原配置中的语言根目录 |
|
| 188 |
+
| `editor_path` / `editor_version` | 本页填写的编辑器路径与版本 |
|
| 189 |
+
| `lqa_server` | 平台对外地址 (后端 `PUBLIC_URL`) |
|
| 190 |
+
|
| 191 |
+
> **提示**: 请求体中如果某个值 **恰好** 写成 `"{{变量名}}"` (整段加引号)), 框架会保留原始类型 (数字/数组), 否则按字符串替换
|
| 192 |
+
|
| 193 |
+
#### 跨域 (CORS)
|
| 194 |
+
|
| 195 |
+
Webhook 由浏览器直接请求, 目标服务必须允许平台域名跨域, 常见做法:
|
| 196 |
+
- Jenkins 安装 **CORS Filter Plugin** 并在系统设置里把平台域名加入白名单;
|
| 197 |
+
- 或在 Jenkins/Gitlab 前加一层 Nginx 反向代理, 由该代理返回 `Access-Control-Allow-Origin`
|
| 198 |
+
|
| 199 |
+
### 4.6 缺陷系统
|
| 200 |
+
|
| 201 |
+
决定项目的 Bug 存放位置, 支持三种模式:
|
| 202 |
+
|
| 203 |
+
| 类型 | 必填配置 | 说明 |
|
| 204 |
+
|---|---|---|
|
| 205 |
+
| **平台内记录 (none)** | 无 | 缺陷只保存在平台内, 回归时由平台关闭/重新打开 |
|
| 206 |
+
| **Bugzilla 5.x** | 系统地址、API Key、产品名称、组件 | API Key 在 Bugzilla “用户偏好 → API Keys” 中生成 |
|
| 207 |
+
| **禅道 (zentao)** | 系统地址、账号、密码、产品 ID | 系统地址 **不含** `/api.php`; 产品 ID 在产品页 URL 中可见 |
|
| 208 |
+
|
| 209 |
+
#### 高级配置 (JSON)
|
| 210 |
+
|
| 211 |
+
- **Bugzilla**:
|
| 212 |
+
```json
|
| 213 |
+
{
|
| 214 |
+
"assignee_field": "email", // 指派人取用户的 email (默认) 或 name
|
| 215 |
+
"reopen_status": "CONFIRMED", // 回归不通过时重新打开的状态
|
| 216 |
+
"default_version": "unspecified" // 未选择发现版本时使用的版本
|
| 217 |
+
}
|
| 218 |
+
```
|
| 219 |
+
- **禅道**:
|
| 220 |
+
```json
|
| 221 |
+
{
|
| 222 |
+
"project_id": 5, // 禅道项目/执行 ID, 用于拉取版本 (Build) 列表
|
| 223 |
+
"bug_type": "others" // 缺陷类型, 默认 others
|
| 224 |
+
}
|
| 225 |
+
```
|
| 226 |
+
|
| 227 |
+
#### 操作
|
| 228 |
+
|
| 229 |
+
- 填完后点击 **测试连接**, 会以当前表单内容调用真实接口试探, 错误信息会原样展示 (含编号列表)
|
| 230 |
+
- 点击 **保存** 持久化, 密钥字段 **只写不读**: 已保存的 API Key / 密码 显示为 `******`, 不修改则保持原值
|
| 231 |
+
|
| 232 |
+
### 4.7 提单模板
|
| 233 |
+
|
| 234 |
+
- 配置自动/手动提单时, 默认带��的 **标题模板**、**描述模板**、**附件模板**
|
| 235 |
+
- 支持变量 (`{{language}}` / `{{module}}` / `{{bug_type}}` 等)
|
| 236 |
+
- 项目代号对应的 `templates/spec2/<代号小写>` 目录存在时, 会优先使用该目录下的自定义模板
|
| 237 |
+
|
| 238 |
+
---
|
| 239 |
+
|
| 240 |
+
## 5. 任务管理
|
| 241 |
+
|
| 242 |
+
### 5.1 列表
|
| 243 |
+
|
| 244 |
+
左侧菜单 **任务管理**, 表格字段:
|
| 245 |
+
|
| 246 |
+
| 字段 | 说明 |
|
| 247 |
+
|---|---|
|
| 248 |
+
| ID / 名称 | 任务编号与中文名 |
|
| 249 |
+
| 模块 / 区域语言 | 本任务涉及的模块与语言 |
|
| 250 |
+
| 状态 | 未执行 / 执行中 / 成功 / 失败 (失败悬浮可见原因) |
|
| 251 |
+
| 缺陷数 | AI 识别产生的缺陷总数 |
|
| 252 |
+
| 回归 | 是否为回归子任务 |
|
| 253 |
+
| 回归任务数 | 本任务产生的回归子任务个数 |
|
| 254 |
+
| 创建人 / 创建时间 / 更新时间 | 元信息 |
|
| 255 |
+
|
| 256 |
+
搜索栏支持: **时间范围 (默认 3 个月)、ID、名称、模块、区域语言、状态、是否回归、创建人**
|
| 257 |
+
|
| 258 |
+
### 5.2 创建任务
|
| 259 |
+
|
| 260 |
+
点击右上角 **添加**, 弹出任务表单, 核心字段分组如下:
|
| 261 |
+
|
| 262 |
+
#### 5.2.1 基础信息
|
| 263 |
+
|
| 264 |
+
- **任务名称** (必填)
|
| 265 |
+
- **区域语言** (多选, 必填)
|
| 266 |
+
- **识别缺陷类型** (多选)
|
| 267 |
+
- **是否开启差异识别 (discern)**: 开启后 AI 只对比变化部分, 速度更快
|
| 268 |
+
- **是否开启 OCR** (ocr_detect)
|
| 269 |
+
- **计划时间 (plan_time)**: 仅记录
|
| 270 |
+
|
| 271 |
+
#### 5.2.2 测试数据
|
| 272 |
+
|
| 273 |
+
两种来源二选一:
|
| 274 |
+
- **选取数据** (`data_ds`): 按模块 + 过滤条件选择;
|
| 275 |
+
- **按版本生成** (`GeneratePictureByVersion`): 填写 **SVN 地址、SVN 版本号**, 还原端按版本拉取并生成
|
| 276 |
+
|
| 277 |
+
#### 5.2.3 项目资源 / 译文资源
|
| 278 |
+
|
| 279 |
+
- 嵌入组件: **项目资源** 和 **译文资源**, 用于指定本次还原使用的工程版本和译文版本
|
| 280 |
+
- 具体字段随还原端插件约定而不同
|
| 281 |
+
|
| 282 |
+
#### 5.2.4 自动提单
|
| 283 |
+
|
| 284 |
+
- **create_bug = 1** 时任务完成后自动把 AI 识别出的缺陷提到配置好的缺陷系统
|
| 285 |
+
- 关联字段: **发现版本、修复版本、发布计划、严重度 (severity)、优先级 (priority)、提单缺陷类型 (bill_bug_types)**
|
| 286 |
+
|
| 287 |
+
### 5.3 操作按钮 (行内)
|
| 288 |
+
|
| 289 |
+
| 按钮 | 显示条件 | 作用 |
|
| 290 |
+
|---|---|---|
|
| 291 |
+
| 查看 | 任意状态 | 以只读模式打开任务表单, 展示详细字段 |
|
| 292 |
+
| 编辑 | 状态=未执行 | 修改任务配置 |
|
| 293 |
+
| 追加 | 状态=执行中 | 为运行中的任务追加语言 / 数据 |
|
| 294 |
+
| 开始 ▶ | 状态=未执行 | 调用 **Webhook** 启动还原 |
|
| 295 |
+
| 结束 ■ | 状态=执行中 | 发送 stop 指令结束 |
|
| 296 |
+
| 重试 | 执行中/失败/成功 | 对未生成图片的数据再次触发还原; 弹窗二次确认 |
|
| 297 |
+
| 执行进度 | 任意 | 弹窗展示每台设备的进度、已完成/总数 |
|
| 298 |
+
| 审核 | 任意 | 跳转到 **结果审核** 页 |
|
| 299 |
+
| 缺陷 | 任意 | 跳转到 **缺陷单** 页 |
|
| 300 |
+
|
| 301 |
+
> **开始失败怎么办?** 多半是 Webhook 返回了非 2xx 或者浏览器被 CORS 拦截,
|
| 302 |
+
> 可在浏览器 DevTools → Network 面板看 `jenkins/...` 请求的响应内容
|
| 303 |
+
|
| 304 |
+
### 5.4 执行进度
|
| 305 |
+
|
| 306 |
+
弹窗展示:
|
| 307 |
+
- 每台设备 (还原端) 的在线状态、当前任务、已完成数 / 总数、剩余时间估算
|
| 308 |
+
- 若还原端周期性上报 (通过 `POST /api/job/device`), 此处会实时刷新
|
| 309 |
+
|
| 310 |
+
---
|
| 311 |
+
|
| 312 |
+
## 6. 结果审核
|
| 313 |
+
|
| 314 |
+
从任务行的 **审核** 按钮进入, URL 为 `/image-results?job_id=xxx`
|
| 315 |
+
|
| 316 |
+
### 6.1 功能
|
| 317 |
+
|
| 318 |
+
- 列出本任务所有截图 + AI 识别到的缺陷框
|
| 319 |
+
- 左右切图, 支持 **放大/缩小/平移**, 缺陷框按类型以不同颜色高亮
|
| 320 |
+
- 单张图片可:
|
| 321 |
+
- **确认缺陷**: 保留并进入待提单队列;
|
| 322 |
+
- **忽略**: 标记为误报, 不进入提单;
|
| 323 |
+
- **编辑框**: 修正 AI 画错的位置、改类型;
|
| 324 |
+
- **手动新增框**: 补 AI 没识别到的问题
|
| 325 |
+
|
| 326 |
+
### 6.2 快捷键
|
| 327 |
+
|
| 328 |
+
| 键 | 作用 |
|
| 329 |
+
|---|---|
|
| 330 |
+
| `← / →` | 上一张 / 下一张 |
|
| 331 |
+
| `Enter` | 确认当前框 |
|
| 332 |
+
| `Delete` | 删除当前框 |
|
| 333 |
+
| `Esc` | 退出编辑 |
|
| 334 |
+
|
| 335 |
+
### 6.3 批量操作
|
| 336 |
+
|
| 337 |
+
顶部支持按 **缺陷类型 / 置信度 / 状态** 筛选, 然后批量确认 / 忽略
|
| 338 |
+
|
| 339 |
+
---
|
| 340 |
+
|
| 341 |
+
## 7. 缺陷单管理
|
| 342 |
+
|
| 343 |
+
从任务行的 **缺陷** 按钮或任务列表外部菜单进入, URL 为 `/bugs?job_id=xxx`
|
| 344 |
+
|
| 345 |
+
### 7.1 列表字段
|
| 346 |
+
|
| 347 |
+
- **缺陷 ID** (平台内编号)、**外部编号** (Bugzilla/禅道中的 ID, 可点击直达)
|
| 348 |
+
- **语言**、**模块**、**缺陷类型**、**严重度**、**状态**
|
| 349 |
+
- **提单状态**: 未提 / 已提 / 提单失败 (鼠标悬浮可见错误信息)
|
| 350 |
+
- **回归结果**: 待回归 / 通过 / 不通过
|
| 351 |
+
|
| 352 |
+
### 7.2 操作
|
| 353 |
+
|
| 354 |
+
| 操作 | 说明 |
|
| 355 |
+
|---|---|
|
| 356 |
+
| **单条提单** | 把当前缺陷同步到外部缺陷系统 |
|
| 357 |
+
| **批量提单** | 勾选多条 → 批量提单; 按模块或语言合并策略由模板决定 |
|
| 358 |
+
| **自动提单** | 任务配置勾选 `create_bug=1` 时任务结束后由后台自动触发 |
|
| 359 |
+
| **回归验证** | 对已修复的缺陷重新跑一遍 AI, 通过则关闭 Bugzilla/禅道单, 不通过则重新打开 |
|
| 360 |
+
| **查看截图** | 点开缺陷查看原图 + 画框 |
|
| 361 |
+
|
| 362 |
+
### 7.3 自动回归
|
| 363 |
+
|
| 364 |
+
- 在任务管理里对某任务 **创建回归子任务** (`regression=1`), 平台会:
|
| 365 |
+
1. 以 `regression=1` 触发 Webhook, 还原端按父任务的数据重新生图;
|
| 366 |
+
2. 新生成的图再跑一遍 AI;
|
| 367 |
+
3. 比对结果: 如果原缺陷在新图中消失 → 标记 **通过**, 关闭外部单; 否则 **不通过**, 重新打开外部单
|
| 368 |
+
|
| 369 |
+
---
|
| 370 |
+
|
| 371 |
+
## 8. 数据管理
|
| 372 |
+
|
| 373 |
+
左侧菜单 **数据管理**, 用于维护项目的 **测试数据集**
|
| 374 |
+
|
| 375 |
+
### 8.1 列表
|
| 376 |
+
|
| 377 |
+
- 可按 **模块、版本、创建人、关键字** 搜索
|
| 378 |
+
- 字段: ID、名称、所属模块、版本、备注、创建人、创建/更新时间
|
| 379 |
+
|
| 380 |
+
### 8.2 操作
|
| 381 |
+
|
| 382 |
+
- **新增 / 导入**: 手工录入或 Excel 导入 (具体导入模板见页面提示)
|
| 383 |
+
- **批量编辑**: 勾选后点 “编辑” 按钮, 可统一改模块 / 版本等
|
| 384 |
+
- **批量删除**: 勾选后点 “删除”, 二次确认
|
| 385 |
+
- **预览 JSON**: 行内按钮打开 JSON 弹窗 (引擎可直接读取的格式)
|
| 386 |
+
- **图片画框**: 对 UI 类数据可直接在图上标注
|
| 387 |
+
|
| 388 |
+
---
|
| 389 |
+
|
| 390 |
+
## 9. 典型使用流程
|
| 391 |
+
|
| 392 |
+
### 9.1 从零接入一个项目
|
| 393 |
+
|
| 394 |
+
```mermaid
|
| 395 |
+
sequenceDiagram
|
| 396 |
+
participant SA as 超管
|
| 397 |
+
participant PM as 项目管理员
|
| 398 |
+
participant QA as 测试人员
|
| 399 |
+
participant R as 还原端 (UE/Unity 插件)
|
| 400 |
+
|
| 401 |
+
SA->>SA: 系统管理 → 项目管理 → 创建项目 (填 code 与 cvtest_project)
|
| 402 |
+
SA->>PM: 分配项目管理员角色
|
| 403 |
+
PM->>PM: 项目设置 → 缺陷类型 / 区域语言 / 模块
|
| 404 |
+
PM->>PM: 项目设置 → 图片还原 (语言根目录 + 路径)
|
| 405 |
+
PM->>PM: 项目设置 → 还原执行 (配 Webhook)
|
| 406 |
+
PM->>PM: 项目设置 → 缺陷系统 (选 none/bugzilla/zentao 并测试连接)
|
| 407 |
+
PM->>PM: 项目设置 → 提单 (配模板)
|
| 408 |
+
QA->>QA: 数据管理 → 导入测试数据
|
| 409 |
+
QA->>QA: 任务管理 → 添加任务 → 开始
|
| 410 |
+
R->>R: 被 Webhook 唤起,按任务拉取数据、还原、上传截图
|
| 411 |
+
QA->>QA: 结果审核 → 确认缺陷
|
| 412 |
+
QA->>QA: 缺陷单 → 批量提单
|
| 413 |
+
PM->>PM: 修复后创建回归任务 (regression=1)
|
| 414 |
+
```
|
| 415 |
+
|
| 416 |
+
### 9.2 一次常规版本回归
|
| 417 |
+
|
| 418 |
+
1. **准备**: 开发合入新译文/新资源, 交付新版本号
|
| 419 |
+
2. **跑任务**: 到 **任务管理 → 添加** 创建新任务, 选择新版本和需要校验的语言 + 模块; 或直接对上一轮任务点 **重试**
|
| 420 |
+
3. **审核**: 任务完成后点 **审核**, 批量确认/忽略
|
| 421 |
+
4. **提单**: 点 **缺陷**, 批量提单到 Bugzilla / 禅道
|
| 422 |
+
5. **跟进修复**: 开发在外部系统修复 Bug, 关闭或改状态为 FIXED
|
| 423 |
+
6. **回归**: 对父任务点 **创建回归任务**, 让平台重新还原 + 识别 + 自动开关外部单
|
| 424 |
+
|
| 425 |
+
---
|
| 426 |
+
|
| 427 |
+
## 10. 常见问题 (FAQ)
|
| 428 |
+
|
| 429 |
+
### Q1: 登录后左侧菜单只有 “系统管理”, 看不到 “任务管理” 等?
|
| 430 |
+
A: 你当前尚未加入任何项目, 请超管在 **项目管理 → 测试经理** 填上你, 或在 **用户管理** 中为你分配项目角色, 登出重登后菜单会刷新
|
| 431 |
+
|
| 432 |
+
### Q2: 点“开始”任务按钮, 弹出 “启动失败:Network Error / CORS”?
|
| 433 |
+
A: Webhook 由浏览器直接请求 Jenkins/CI, 必须允许平台域名跨域
|
| 434 |
+
- 让 CI 服务返回 `Access-Control-Allow-Origin: <平台域名>` 响应头;
|
| 435 |
+
- 或在 CI 前搭一层 Nginx 代理添加跨域头
|
| 436 |
+
|
| 437 |
+
### Q3: 缺陷系统“测试连接”失败?
|
| 438 |
+
A: 错误信息会原样显示, 常见原因:
|
| 439 |
+
- 地址填错 (禅道地址 **不要带** `/api.php`);
|
| 440 |
+
- API Key / 密码错误 (Bugzilla 请到用户偏好重新生成);
|
| 441 |
+
- 产品名称 / 产品 ID 不存在;
|
| 442 |
+
- 内网部署的 Bugzilla/禅道没向平台服务器开白名单
|
| 443 |
+
|
| 444 |
+
### Q4: 任务成功了, 但是 “缺陷数=0”?
|
| 445 |
+
A:
|
| 446 |
+
- 检查 **区域语言** 是否勾对 (截图上的语言和平台配的要一致);
|
| 447 |
+
- 检查 **识别缺陷类型** 是否勾了至少一项;
|
| 448 |
+
- 检查 **图片还原路径** 是否正确, 否则 AI 可能没拿到图;
|
| 449 |
+
- 查看任务 **执行进度**, 确认设备确实上传过图片
|
| 450 |
+
|
| 451 |
+
### Q5: 自动提单 (`create_bug=1`) 没有触发外部系统?
|
| 452 |
+
A:
|
| 453 |
+
- 任务表单里把 **create_bug** 勾上;
|
| 454 |
+
- 项目的 **缺陷系统** 不能是 `平台内记录(none)`;
|
| 455 |
+
- 查看 **缺陷单** 页, 若 “提单状态=提单失败”, 鼠标悬浮即可看到错误原因
|
| 456 |
+
|
| 457 |
+
### Q6: 回归任务跑了, 但是外部单据状态没变?
|
| 458 |
+
A:
|
| 459 |
+
- Bugzilla 需要在 **高级配置** 里把 `reopen_status` 配成你的工作流里允许回退的状态;
|
| 460 |
+
- 禅道需确保 **账号** 对该 Bug 有编辑权限;
|
| 461 |
+
- 平台只在 **回归结果** 产生变化时才会调用外部 API, 可到 **缺陷单** 页手动点 “重新同步” 触发
|
| 462 |
+
|
| 463 |
+
### Q7: 想把某项目的提单格式改一改?
|
| 464 |
+
A: 复制一份 `server/templates/spec2/default/`, 重命名为 `server/templates/spec2/<项目代号小写>/`, 修改其中的 `.md.jinja` 模板文件, 重启后端即可生效
|
| 465 |
+
|
| 466 |
+
---
|
| 467 |
+
|
| 468 |
+
## 11. 关联接口(供排错)
|
| 469 |
+
|
| 470 |
+
| 场景 | 接口 | 文档 |
|
| 471 |
+
|---|---|---|
|
| 472 |
+
| 登录 / 注册 / 用户 | `/api/user/*` | [api/user.md](api/user.md) |
|
| 473 |
+
| 项目 / 项目配置 | `/api/project/*` | [api/project.md](api/project.md) |
|
| 474 |
+
| 任务 / 启停 / 进度 | `/api/job/*` | [api/job.md](api/job.md) |
|
| 475 |
+
| 截图上传 / AI 识别 | `/api/image/*` | [api/image.md](api/image.md) |
|
| 476 |
+
| 缺陷 / 提单 / 回归 | `/api/bug/*` | [api/bug.md](api/bug.md) |
|
| 477 |
+
| 测试数据 | `/api/data/*` | [api/data.md](api/data.md) |
|
| 478 |
+
| 枚举 / 健康检查 | `/api/system/*` | [api/system.md](api/system.md) |
|
| 479 |
+
|
| 480 |
+
> 还原端 (UE/Unity 插件) 的接入细节请阅读 [integration/restorer.md](integration/restorer.md)
|
| 481 |
+
|
| 482 |
+
---
|
| 483 |
+
|
| 484 |
+
## 12. 变更建议 / 反馈
|
| 485 |
+
|
| 486 |
+
- 使用过程中遇到 Bug 或建议, 请在仓库提 Issue, 并附带:
|
| 487 |
+
- 平台版本 (可在页脚或 `/api/system/health` 看到)
|
| 488 |
+
- 浏览器与版本
|
| 489 |
+
- 复现步骤 + 截图 / 控制台报错
|
| 490 |
+
- 或者可直接联系项目维护者
|
| 491 |
+
|
| 492 |
+
---
|
timi_hok_game_translator/LQA_WMP/lqa_service/.gitignore
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 日志
|
| 2 |
+
/*.log
|
| 3 |
+
/log/
|
| 4 |
+
|
| 5 |
+
# 测试样例 (真实游戏截图与文案涉及版权, 不入库)
|
| 6 |
+
# 运行 python tests/gen_samples.py 生成可用的合成样例
|
| 7 |
+
/tests/test/
|
| 8 |
+
/tests/screenShot.png
|
| 9 |
+
/tests/v3_result.json
|
| 10 |
+
/tests/object/*
|
| 11 |
+
/tests/lqa_mark_img.png
|
| 12 |
+
/tests/lqa_rect_img.png
|
| 13 |
+
|
| 14 |
+
# 虚拟环境与隐藏目录
|
| 15 |
+
/.*/
|
| 16 |
+
.idea
|
| 17 |
+
.vscode
|
| 18 |
+
|
| 19 |
+
# Python 产物
|
| 20 |
+
*.py[cod]
|
| 21 |
+
__pycache__/
|
timi_hok_game_translator/LQA_WMP/lqa_service/Dockerfile
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
|
| 3 |
+
ENV PYTHONUNBUFFERED=1 \
|
| 4 |
+
PYTHONDONTWRITEBYTECODE=1 \
|
| 5 |
+
DEBUG_MODE=False \
|
| 6 |
+
TZ=Asia/Shanghai
|
| 7 |
+
|
| 8 |
+
# opencv 运行所需的系统库
|
| 9 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 10 |
+
libgl1 \
|
| 11 |
+
libglib2.0-0 \
|
| 12 |
+
tzdata \
|
| 13 |
+
&& ln -sf /usr/share/zoneinfo/$TZ /etc/localtime \
|
| 14 |
+
&& echo $TZ > /etc/timezone \
|
| 15 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 16 |
+
|
| 17 |
+
WORKDIR /data/lqa
|
| 18 |
+
|
| 19 |
+
COPY requirements.txt .
|
| 20 |
+
RUN pip install --no-cache-dir -r requirements.txt \
|
| 21 |
+
&& pip install --no-cache-dir gunicorn gevent
|
| 22 |
+
|
| 23 |
+
# 默认 OCR 引擎 rapidocr: 离线可用、体积小 (约 15MB), 开箱即用
|
| 24 |
+
ARG OCR_ENGINE=rapidocr
|
| 25 |
+
RUN set -eux; \
|
| 26 |
+
case "$OCR_ENGINE" in \
|
| 27 |
+
rapidocr) pip install --no-cache-dir rapidocr-onnxruntime ;; \
|
| 28 |
+
paddleocr) pip install --no-cache-dir paddlepaddle paddleocr ;; \
|
| 29 |
+
easyocr) pip install --no-cache-dir easyocr ;; \
|
| 30 |
+
none) echo "不安装本地 OCR, 需在运行时指向外部 OCR 服务" ;; \
|
| 31 |
+
*) echo "未知 OCR_ENGINE=$OCR_ENGINE" >&2; exit 1 ;; \
|
| 32 |
+
esac
|
| 33 |
+
|
| 34 |
+
COPY . .
|
| 35 |
+
|
| 36 |
+
# 预热: 构建期完成模型加载/下载, 避免首个请求超时
|
| 37 |
+
# 运行期默认 provider 跟随构建期引擎 (OCR_ENGINE=none 时即 OCR_PROVIDER=none)
|
| 38 |
+
ENV OCR_PROVIDER=${OCR_ENGINE}
|
| 39 |
+
RUN if [ "$OCR_ENGINE" != "none" ]; then \
|
| 40 |
+
python -c "from common.ocr_provider import get_provider; print(get_provider().test_connection())" || true; \
|
| 41 |
+
fi
|
| 42 |
+
|
| 43 |
+
EXPOSE 8086
|
| 44 |
+
|
| 45 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
| 46 |
+
CMD python -c "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8086/health',timeout=5).status==200 else 1)" || exit 1
|
| 47 |
+
|
| 48 |
+
CMD ["gunicorn", "-c", "config/gunicorn_config.py", "portal:app", "--preload"]
|
timi_hok_game_translator/LQA_WMP/lqa_service/README.md
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# LQA AI 识别服务
|
| 2 |
+
|
| 3 |
+

|
| 4 |
+
|
| 5 |
+
LQA 平台的 AI 识别后端, 基于 Flask, 平台通过 `AI_BASE_URL` 调用本服务完成本地化异常检测
|
| 6 |
+
|
| 7 |
+
## 功能
|
| 8 |
+
|
| 9 |
+
1. **LQA 本地化文本异常检测** `POST /image/lqa_check/`
|
| 10 |
+
- 支持多语种
|
| 11 |
+
- 支持多类型检测: 文本超文本框、文本超图像框、漏 key、漏译、错译及其他自定义异常类型
|
| 12 |
+
|
| 13 |
+
2. **图像前景提取** `POST /image/image_extraction/`
|
| 14 |
+
- 只支持含 alpha 通道的 `.png` 格式图像
|
| 15 |
+
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
## 快速开始
|
| 19 |
+
|
| 20 |
+
```bash
|
| 21 |
+
cd lqa_service
|
| 22 |
+
|
| 23 |
+
python -m venv .venv
|
| 24 |
+
.venv\Scripts\activate # Linux/macOS: source .venv/bin/activate
|
| 25 |
+
|
| 26 |
+
pip install -r requirements.txt
|
| 27 |
+
pip install rapidocr-onnxruntime # 默认 OCR 引擎, 离线可用
|
| 28 |
+
|
| 29 |
+
python portal.py # 监听 0.0.0.0:8086
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
自检 OCR 是否就绪:
|
| 33 |
+
|
| 34 |
+
```bash
|
| 35 |
+
python tests/check_ocr.py # 检测当前配置
|
| 36 |
+
python tests/check_ocr.py --list # 列出全部可选引擎
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
跑完整冒烟测试:
|
| 40 |
+
|
| 41 |
+
```bash
|
| 42 |
+
python tests/gen_samples.py # 首次需先生成测试样例
|
| 43 |
+
python tests/smoke_test.py 127.0.0.1:8086 lqa
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
---
|
| 47 |
+
|
| 48 |
+
## OCR 引擎选择
|
| 49 |
+
|
| 50 |
+
OCR 是**可选**能力, 未配置时服务仍可正常启动并完成大部分检测, 只会自动跳过, 必须依赖 OCR 的检测项 (见下方「OCR 不可用时的降级行为」)
|
| 51 |
+
|
| 52 |
+
依赖 OCR 的检测需要同时拿到 **文本内容 + 精确边界框**, 因此只支持能同时提供两者的 OCR, 通过环境变量 `OCR_PROVIDER` 切换, 默认 `rapidocr`
|
| 53 |
+
|
| 54 |
+
| `OCR_PROVIDER` | 类型 | 离线 | 安装 | 说明 |
|
| 55 |
+
|---|---|---|---|---|
|
| 56 |
+
| `rapidocr` | 开源 | ✅ | `pip install rapidocr-onnxruntime` | **推荐**, PaddleOCR 模型的 ONNX 推理版, 约 15MB,CPU 即可, 中英文效果好 |
|
| 57 |
+
| `paddleocr` | 开源 | ✅ | `pip install paddleocr paddlepaddle` | 精度最高, 中日韩支持好; 依赖较重 (约 2GB) |
|
| 58 |
+
| `paddleocr_http` | 开源 | ✅ | 无 | 调用独立部署的 PaddleOCR hubserving/PaddleX 服务, 适合 GPU 集中推理 |
|
| 59 |
+
| `easyocr` | 开源 | ✅ | `pip install easyocr` | 支持 80+ 语种, 泰文/越南文等小语种可选它 |
|
| 60 |
+
| `tesseract` | 开源 | ✅ | `pip install pytesseract` + 安装 tesseract | 老牌引擎; **对游戏 UI 的复杂背景、艺术字识别率明显偏低**, 仅建议简单场景 |
|
| 61 |
+
| `tencentcloud` | 商业 | ❌ | `pip install tencentcloud-sdk-python-ocr` | 腾讯云通用印刷体识别 |
|
| 62 |
+
| `baidu` | 商业 | ❌ | 无 | 百度智能云通用文字识别 (含位置) |
|
| 63 |
+
| `azure` | 商业 | ❌ | 无 | Azure AI Vision Read API |
|
| 64 |
+
| `cvtest` | 自建 | ❌ | 无 | 兼容内网自建 OCR 服务协议 |
|
| 65 |
+
| `none` | — | ✅ | 无 | **显式关闭 OCR**, 不产生任何识别调用 |
|
| 66 |
+
|
| 67 |
+
> 游戏本地化场景文本密集、字体特殊, 建议优先 `rapidocr` 或 `paddleocr`, 商业 API 按量计费, 批量识别需评估成本与 QPS 限制
|
| 68 |
+
|
| 69 |
+
### OCR 不可用时的降级行为
|
| 70 |
+
|
| 71 |
+
以下任一情况都视为「OCR 不可用」, 服务 **不会报错**, 而是自动降级:
|
| 72 |
+
|
| 73 |
+
- `OCR_PROVIDER=none` 或留空 (显式关闭)
|
| 74 |
+
- `OCR_PROVIDER` 名称写错
|
| 75 |
+
- 选定的引擎未安装 (如未 `pip install rapidocr-onnxruntime`)
|
| 76 |
+
- 云服务密钥缺失、外部 OCR 服务连不通
|
| 77 |
+
|
| 78 |
+
降级后各检测类型的可用性:
|
| 79 |
+
|
| 80 |
+
| 检测类型 | 需要 OCR | 降级后 |
|
| 81 |
+
|---|---|---|
|
| 82 |
+
| 1 漏译 (`##` 等标记) | ❌ | ✅ 正常 |
|
| 83 |
+
| 2-0 文本超文本框 | ✅ | ⛔ 跳过 |
|
| 84 |
+
| 2-1 文本框与图像框重叠 | ❌ | ✅ 正常 |
|
| 85 |
+
| 3 漏 key | ❌ | ✅ 正常 |
|
| 86 |
+
| 4 文本框重叠 | ❌ | ✅ 正常 (纯几何) |
|
| 87 |
+
| 5 错译 | ✅ | ⛔ 跳过 |
|
| 88 |
+
| 6 non_problem | ❌ | ✅ 正常 |
|
| 89 |
+
| 7 非标准框 | ❌ | ✅ 正常 |
|
| 90 |
+
|
| 91 |
+
降级时响应体额外返回三个字段, 便于调用方识别:
|
| 92 |
+
|
| 93 |
+
```json
|
| 94 |
+
{
|
| 95 |
+
"success": true,
|
| 96 |
+
"result": {
|
| 97 |
+
"ocr_degraded": true,
|
| 98 |
+
"ocr_message": "未配置 OCR (OCR_PROVIDER=none), 依赖 OCR 的检测项将跳过",
|
| 99 |
+
"skipped_check_type": ["2-0", "5"]
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
`GET /health` 始终返回 200 (服务本身健康), OCR 状态在 `ocr` 字段中体现:
|
| 105 |
+
|
| 106 |
+
```json
|
| 107 |
+
{"status": "ok", "ocr": {"available": false, "message": "...", "degraded": true}}
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
探测结果在进程内缓存 (成功 1 小时, 失败 60 秒后重试), 不会给每个请求带来额外开销, 可用 `python tests/check_ocr.py` 单独自检当前配置
|
| 111 |
+
|
| 112 |
+
### 配置示例
|
| 113 |
+
|
| 114 |
+
**完全不使用 OCR**
|
| 115 |
+
|
| 116 |
+
```bash
|
| 117 |
+
export OCR_PROVIDER=none
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
**离线 (推荐, 无任何外部依赖)**
|
| 121 |
+
|
| 122 |
+
```bash
|
| 123 |
+
export OCR_PROVIDER=rapidocr
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
**PaddleOCR 本地**
|
| 127 |
+
|
| 128 |
+
```bash
|
| 129 |
+
export OCR_PROVIDER=paddleocr
|
| 130 |
+
export OCR_LANG=ch # ch / en / japan / korean / fr / german ...
|
| 131 |
+
export OCR_USE_GPU=false
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
**PaddleOCR 独立服务**
|
| 135 |
+
|
| 136 |
+
```bash
|
| 137 |
+
export OCR_PROVIDER=paddleocr_http
|
| 138 |
+
export OCR_URL=http://<paddle-host>:8868/predict/ocr_system
|
| 139 |
+
```
|
| 140 |
+
|
| 141 |
+
**腾讯云**
|
| 142 |
+
|
| 143 |
+
```bash
|
| 144 |
+
export OCR_PROVIDER=tencentcloud
|
| 145 |
+
export OCR_SECRET_ID=xxx
|
| 146 |
+
export OCR_SECRET_KEY=xxx
|
| 147 |
+
export OCR_REGION=ap-guangzhou
|
| 148 |
+
```
|
| 149 |
+
|
| 150 |
+
**百度**
|
| 151 |
+
|
| 152 |
+
```bash
|
| 153 |
+
export OCR_PROVIDER=baidu
|
| 154 |
+
export OCR_API_KEY=xxx
|
| 155 |
+
export OCR_SECRET_KEY=xxx
|
| 156 |
+
```
|
| 157 |
+
|
| 158 |
+
**自建 / 内网服务**
|
| 159 |
+
|
| 160 |
+
```bash
|
| 161 |
+
export OCR_PROVIDER=cvtest
|
| 162 |
+
export OCR_HOST=http://<ocr-host>:80
|
| 163 |
+
export OCR_DEFAULT_PROJECT=lqa # 该服务用 project-method 头鉴权
|
| 164 |
+
```
|
| 165 |
+
|
| 166 |
+
### 接入自定义 OCR
|
| 167 |
+
|
| 168 |
+
实现 `common/ocr_provider/base.py` 中的 `OcrProvider`, 返回统一结构即可:
|
| 169 |
+
|
| 170 |
+
```python
|
| 171 |
+
[{"area": [x1, y1, x2, y2], "result": "识别出的文本"}, ...]
|
| 172 |
+
```
|
| 173 |
+
|
| 174 |
+
然后在 `common/ocr_provider/__init__.py` 的 `PROVIDERS` 中注册
|
| 175 |
+
|
| 176 |
+
---
|
| 177 |
+
|
| 178 |
+
## 环境变量
|
| 179 |
+
|
| 180 |
+
| 变量 | 默认值 | 说明 |
|
| 181 |
+
|---|---|---|
|
| 182 |
+
| `DEBUG_MODE` | `True` | `True` 时 `python portal.py` 直接启动开发服务器 (容器内已置为 `False`, 由 gunicorn 托管) |
|
| 183 |
+
| `OCR_PROVIDER` | `rapidocr` | OCR 引擎, 见上表; `none`/留空表示不使用 OCR |
|
| 184 |
+
| `OCR_URL` | 空 | HTTP 型 OCR 服务地址 |
|
| 185 |
+
| `OCR_HOST` | 空 | 服务 endpoint (`cvtest` / `azure` 使用) |
|
| 186 |
+
| `OCR_LANG` | `ch` | 识别语种 (本地引擎) |
|
| 187 |
+
| `OCR_USE_GPU` | `false` | 本地引擎是否用 GPU |
|
| 188 |
+
| `OCR_TIMEOUT` | `60` | 远程 OCR 超时 (秒) |
|
| 189 |
+
| `OCR_API_KEY` / `OCR_SECRET_ID` / `OCR_SECRET_KEY` | 空 | 云厂商鉴权 |
|
| 190 |
+
| `OCR_REGION` | `ap-guangzhou` | 腾讯云地域 |
|
| 191 |
+
| `OCR_TESSERACT_CMD` | 空 | tesseract 可执行文件路径 |
|
| 192 |
+
| `OCR_DEFAULT_PROJECT` | 空 | `cvtest` 的默认项目标识 |
|
| 193 |
+
| `LOG_PATH` | `./log` | 日志目录 |
|
| 194 |
+
| `BIND` | `0.0.0.0:8086` | gunicorn 监听地址 |
|
| 195 |
+
| `GUNICORN_WORKERS` | `3` | gunicorn worker 数 |
|
| 196 |
+
| `NO_TRANS_MARK_LIST` | `["##","#N","WWWW","N/A"]` | 漏译标记 |
|
| 197 |
+
| `ERROR_TRANS_MARK_LIST` | `["</",["color","#"]]` | 错译标记 |
|
| 198 |
+
|
| 199 |
+
测试脚本也支持 `LQA_TEST_HOST` / `LQA_TEST_PORT` / `LQA_TEST_DATA_DIR` / `LQA_TEST_PROJECT` 覆盖
|
| 200 |
+
|
| 201 |
+
---
|
| 202 |
+
|
| 203 |
+
## 生产部署
|
| 204 |
+
|
| 205 |
+
```bash
|
| 206 |
+
bash deploy/run_gunicorn.sh
|
| 207 |
+
# 等价于: gunicorn -c config/gunicorn_config.py portal:app --preload
|
| 208 |
+
```
|
| 209 |
+
|
| 210 |
+
> `gunicorn` + `gevent` 不支持 Windows, Windows 下请用 `python portal.py`
|
| 211 |
+
|
| 212 |
+
### 容器部署
|
| 213 |
+
|
| 214 |
+
```bash
|
| 215 |
+
# 默认内置 rapidocr, 开箱即可离线运行
|
| 216 |
+
docker build -t lqa-ai-service .
|
| 217 |
+
|
| 218 |
+
# 内置 PaddleOCR (镜像约 +2GB, 精度更高)
|
| 219 |
+
docker build --build-arg OCR_ENGINE=paddleocr -t lqa-ai-service:paddle .
|
| 220 |
+
|
| 221 |
+
# 不内置任何引擎 (镜像最小; 可指向外部 OCR, 或完全不用 OCR)
|
| 222 |
+
docker build --build-arg OCR_ENGINE=none -t lqa-ai-service:slim .
|
| 223 |
+
|
| 224 |
+
docker run -d -p 8086:8086 -e OCR_PROVIDER=rapidocr lqa-ai-service
|
| 225 |
+
```
|
| 226 |
+
|
| 227 |
+
---
|
| 228 |
+
|
| 229 |
+
## 调用约定
|
| 230 |
+
|
| 231 |
+
### 请求头
|
| 232 |
+
|
| 233 |
+
```
|
| 234 |
+
project-method: <项目名>_lqa
|
| 235 |
+
```
|
| 236 |
+
|
| 237 |
+
服务会剥离 `_lqa` 后缀得到项目名, 传递给 OCR provider, `cvtest` 等依赖该标识鉴权的服务必须传; 离线引擎可省略
|
| 238 |
+
|
| 239 |
+
LQA 平台侧对应 "项目设置" 中的 **AI识别项目名**
|
| 240 |
+
|
| 241 |
+
### 请求体
|
| 242 |
+
|
| 243 |
+
```json
|
| 244 |
+
{
|
| 245 |
+
"img_base64": "当前截图 base64",
|
| 246 |
+
"rect_locations": { "text": [...], "image": [...] },
|
| 247 |
+
"language": null,
|
| 248 |
+
"supervised": null,
|
| 249 |
+
"check_type": ["1", "2-0"],
|
| 250 |
+
"history_img_base64": null,
|
| 251 |
+
"history_result": null,
|
| 252 |
+
"no_trans_marks": [],
|
| 253 |
+
"error_trans_marks": [],
|
| 254 |
+
"ocr_detect": 1
|
| 255 |
+
}
|
| 256 |
+
```
|
| 257 |
+
|
| 258 |
+
| 字段 | 类型 | 说明 |
|
| 259 |
+
|---|---|---|
|
| 260 |
+
| `img_base64` | string | 必填, 待检测截图 |
|
| 261 |
+
| `rect_locations` | **object** | 必填, `{"text": [...], "image": [...]}`, 注意是对象不是数组 |
|
| 262 |
+
| `language` | int | 语种, 见下方枚举,`null` 为不限 |
|
| 263 |
+
| `check_type` | list[str] | 指定检测类型, `null` 为全部 |
|
| 264 |
+
| `ocr_detect` | int | `1` 文本框非精确位置需 OCR 定位 (默认); `0` 文本框已是最小外接矩 |
|
| 265 |
+
| `history_img_base64` | string | 差异识别时的上一次截图 |
|
| 266 |
+
|
| 267 |
+
> 注意: `ocr_detect=0` 分支 **同样会调用 OCR** (用于错译检测), 只是不再用 OCR 结果做位置校准
|
| 268 |
+
|
| 269 |
+
### 响应体
|
| 270 |
+
|
| 271 |
+
```json
|
| 272 |
+
{
|
| 273 |
+
"success": true,
|
| 274 |
+
"err_msg": null,
|
| 275 |
+
"result": {
|
| 276 |
+
"overframe": false,
|
| 277 |
+
"mark_img": "标注后图片 base64",
|
| 278 |
+
"rect_img": "文本框图片 base64",
|
| 279 |
+
"check_detail": {}
|
| 280 |
+
}
|
| 281 |
+
}
|
| 282 |
+
```
|
| 283 |
+
|
| 284 |
+
### 枚举
|
| 285 |
+
|
| 286 |
+
**检测类型 (`check_type`)**
|
| 287 |
+
|
| 288 |
+
| 值 | 说明 |
|
| 289 |
+
|---|---|
|
| 290 |
+
| `1` | 漏译 |
|
| 291 |
+
| `2` | 超框 (`2-0` 文本超文本框, `2-1` 文本超图像框) |
|
| 292 |
+
| `3` | 漏 key |
|
| 293 |
+
| `4` | 文本框重叠 |
|
| 294 |
+
| `5` | 错译 |
|
| 295 |
+
| `6` | non_problem 自定义 |
|
| 296 |
+
| `7` | 非标准框 |
|
| 297 |
+
|
| 298 |
+
**语种 (`language`)**
|
| 299 |
+
|
| 300 |
+
| 值 | 语种 |
|
| 301 |
+
|---|---|
|
| 302 |
+
| `0` | 简体中文 |
|
| 303 |
+
| `1` | 繁体中文 (台湾) |
|
| 304 |
+
| `2` | 英文 |
|
| 305 |
+
| `3` | 日文 |
|
| 306 |
+
| `4` | 泰文 |
|
| 307 |
+
| `5` | 越南文 |
|
| 308 |
+
|
| 309 |
+
---
|
| 310 |
+
|
| 311 |
+
## 测试样例
|
| 312 |
+
|
| 313 |
+
真实游戏截图与 UI 文案涉及版权, **未随仓库发布** (`tests/test/` 已在 `.gitignore` 中排除), 仓库提供生成器, 用 OpenCV 合成结构等价的样例:
|
| 314 |
+
|
| 315 |
+
```bash
|
| 316 |
+
python tests/gen_samples.py # 生成到 tests/test/
|
| 317 |
+
python tests/gen_samples.py --force # 覆盖已有样例
|
| 318 |
+
```
|
| 319 |
+
|
| 320 |
+
生成的场景:
|
| 321 |
+
|
| 322 |
+
| case | 场景 | 预期 |
|
| 323 |
+
|---|---|---|
|
| 324 |
+
| 0 | 正常界面 | 无异常 |
|
| 325 |
+
| 1 | 标准框小于文本 | 可能触发超框 (取决于 OCR 实际识别区域与阈值) |
|
| 326 |
+
| 2 | 含 `##` / `N/A` 标记 | 检出漏译 (类��� 1) |
|
| 327 |
+
| 3 | `textStr` 缺失 / 空串 | 不崩溃且无异常 |
|
| 328 |
+
| 4 | 标准框相交 | 可能触发重叠 |
|
| 329 |
+
| 5 | 密集文本 | 压力场景 |
|
| 330 |
+
| 6 | 非中文界面混入简体中文 | 检出漏 key (类型 3) |
|
| 331 |
+
|
| 332 |
+
> 合成图使用 OpenCV 内置字体, 仅含拉丁字符, 与真实游戏的艺术字、复杂背景差异较大, 它用于验证 **服务链路与接口契约** 是否正常, 不能用来评估检测算法的实际准确率, 调优算法请使用自有的真实截图
|
| 333 |
+
|
| 334 |
+
### 关于标准数据中的空文本
|
| 335 |
+
|
| 336 |
+
`rect_locations.text[*].textStr` 允许为 `None` / 空串, 表示该文本框未提供文本内容, 此时依赖文本内容的检测项 (漏译、漏 key、错译、non_problem) 会跳过该文本框,
|
| 337 |
+
不依赖文本的检测项 (超框、重叠、非标准框) 仍正常进行
|
| 338 |
+
|
| 339 |
+
---
|
| 340 |
+
|
| 341 |
+
## 与 LQA 平台对接
|
| 342 |
+
|
| 343 |
+
```bash
|
| 344 |
+
# LQA-OSS/.env
|
| 345 |
+
AI_BASE_URL=http://<本服务地址>:8086
|
| 346 |
+
```
|
| 347 |
+
|
| 348 |
+
平台会调用 `POST {AI_BASE_URL}/image/lqa_check/`, 并自动带上 `project-method: <AI识别项目名>_lqa` 请求头
|
| 349 |
+
|
| 350 |
+
---
|
timi_hok_game_translator/LQA_WMP/lqa_service/common/interface_ocr.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: interface_ocr.py
|
| 4 |
+
# @desc: OCR 能力统一接口模块, 对接 common/ocr_provider 实现, 提供以下能力:
|
| 5 |
+
# - ocr_available: 检测当前 OCR 能力是否可用 (带缓存), 未配置 OCR 时返回 False 而非报错,
|
| 6 |
+
# 便于调用方据此降级处理
|
| 7 |
+
# - ocr: 统一 OCR 识别入口, 具体识别逻辑由 OCR_PROVIDER 配置决定 (见 ocr_provider 模块),
|
| 8 |
+
# OCR 为可选能力, 未配置/调用失败时捕获异常并返回 None, 由调用方判空后
|
| 9 |
+
# 跳过依赖 OCR 的检测项, 而非视为服务错误
|
| 10 |
+
# - find_lcsubstr: 查找两个字符串的最长公共子串 (动态规划)
|
| 11 |
+
# - find_lcseque: 查找两个字符串的最长公共子序列 (动态规划+回溯),
|
| 12 |
+
# 可用于比对 OCR 识别文本与标准文本的相似度
|
| 13 |
+
"""
|
| 14 |
+
import traceback
|
| 15 |
+
from common.log import logger
|
| 16 |
+
from common.ocr_provider import get_provider, is_available, OcrError
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def find_lcsubstr(s1, s2):
|
| 20 |
+
""" 查找最长公共子串
|
| 21 |
+
:param s1: str, 字符串
|
| 22 |
+
:param s2: str, 字符串
|
| 23 |
+
:return: 最长公共子串
|
| 24 |
+
"""
|
| 25 |
+
m = [[0 for i in range(len(s2) + 1)] for j in range(len(s1) + 1)]
|
| 26 |
+
mmax = 0
|
| 27 |
+
p = 0
|
| 28 |
+
for i in range(len(s1)):
|
| 29 |
+
for j in range(len(s2)):
|
| 30 |
+
if s1[i] == s2[j]:
|
| 31 |
+
m[i + 1][j + 1] = m[i][j] + 1
|
| 32 |
+
if m[i + 1][j + 1] > mmax:
|
| 33 |
+
mmax = m[i + 1][j + 1]
|
| 34 |
+
p = i + 1
|
| 35 |
+
return s1[p - mmax:p], mmax
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def find_lcseque(s1, s2):
|
| 39 |
+
"""查找最长公共子序列
|
| 40 |
+
:param s1: str, 字符串
|
| 41 |
+
:param s2: str, 字符串
|
| 42 |
+
:return: 最长公共子序列
|
| 43 |
+
"""
|
| 44 |
+
# 生成字符串长度加 1 的 0 矩阵, m 用来保存对应位置匹配的结果
|
| 45 |
+
m = [[0 for x in range(len(s2) + 1)] for y in range(len(s1) + 1)]
|
| 46 |
+
# d 用来记录转移方向
|
| 47 |
+
d = [[None for x in range(len(s2) + 1)] for y in range(len(s1) + 1)]
|
| 48 |
+
|
| 49 |
+
for p1 in range(len(s1)):
|
| 50 |
+
for p2 in range(len(s2)):
|
| 51 |
+
if s1[p1] == s2[p2]: # 字符匹配成功, 则该位置的值为左上方的值加 1
|
| 52 |
+
m[p1 + 1][p2 + 1] = m[p1][p2] + 1
|
| 53 |
+
d[p1 + 1][p2 + 1] = 'ok'
|
| 54 |
+
elif m[p1 + 1][p2] > m[p1][p2 + 1]: # 左值大于上值, 则该位置的值为左值, 并标记回溯时的方向
|
| 55 |
+
m[p1 + 1][p2 + 1] = m[p1 + 1][p2]
|
| 56 |
+
d[p1 + 1][p2 + 1] = 'left'
|
| 57 |
+
else: # 上值大于左值, 则该位置的值为上值, 并标记方向 up
|
| 58 |
+
m[p1 + 1][p2 + 1] = m[p1][p2 + 1]
|
| 59 |
+
d[p1 + 1][p2 + 1] = 'up'
|
| 60 |
+
(p1, p2) = (len(s1), len(s2))
|
| 61 |
+
s = []
|
| 62 |
+
while m[p1][p2]: # 不为 None 时
|
| 63 |
+
c = d[p1][p2]
|
| 64 |
+
if c == 'ok': # 匹配成功, 插入该字符, 并向左上角找下一个
|
| 65 |
+
s.append(s1[p1 - 1])
|
| 66 |
+
p1 -= 1
|
| 67 |
+
p2 -= 1
|
| 68 |
+
if c == 'left': # 根据标记, 向左找下一个
|
| 69 |
+
p2 -= 1
|
| 70 |
+
if c == 'up': # 根据标记, 向上找下一个
|
| 71 |
+
p1 -= 1
|
| 72 |
+
s.reverse()
|
| 73 |
+
return ''.join(s), len(s)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def ocr_available(force=False):
|
| 77 |
+
"""OCR 能力是否可用 (带缓存, 未配置 OCR 时返回 False 而非报错)
|
| 78 |
+
|
| 79 |
+
:param force: True 时忽略缓存重新探测
|
| 80 |
+
:return: (bool, str) 是否可用、描述信息
|
| 81 |
+
"""
|
| 82 |
+
return is_available(force=force)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def ocr(img_base64, location=None, project_id=19998, project=None):
|
| 86 |
+
"""OCR 识别接口 (具体实现由 OCR_PROVIDER 决定, 见 common/ocr_provider)
|
| 87 |
+
|
| 88 |
+
OCR 为可选能力: 未配置或不可用时返回 None, 调用方需判空并跳过
|
| 89 |
+
依赖 OCR 的检测项, 而非视作错误
|
| 90 |
+
|
| 91 |
+
:param img_base64: str, base64 格式的图像数据
|
| 92 |
+
:param location: list, 保留参数, 当前实现统一识别整图后再按标准框过滤
|
| 93 |
+
:param project_id: int, 保留参数, cvtest provider 通过配置项传入
|
| 94 |
+
:param project: str, 调用方项目标识 (部分服务用于鉴权/路由)
|
| 95 |
+
:return: 识别结果 [{"area": [x1, y1, x2, y2], "result": '{text}'}, ..., {}]
|
| 96 |
+
失败或未配置时返回 None (调用方需判空)
|
| 97 |
+
"""
|
| 98 |
+
try:
|
| 99 |
+
return get_provider().recognize(img_base64, project=project)
|
| 100 |
+
except OcrError as ex:
|
| 101 |
+
# 配置缺失/鉴权失败/服务不可用等可预期错误, 打印明确原因便于排障
|
| 102 |
+
logger.error('OCR 调用失败: %s', ex)
|
| 103 |
+
return None
|
| 104 |
+
except Exception as ex: # pylint: disable=broad-except
|
| 105 |
+
logger.error(ex)
|
| 106 |
+
logger.error(traceback.format_exc())
|
| 107 |
+
return None
|
timi_hok_game_translator/LQA_WMP/lqa_service/common/log.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: log.py
|
| 4 |
+
# @desc: 日志配置初始化模块, 提供以下能力:
|
| 5 |
+
# - get_logger: 创建并配置名为 'handle' 的 logger, 日志级别为 INFO;
|
| 6 |
+
# 日志目录通过环境变量 LOG_PATH 指定 (默认 ./log), 不存在时自动创建;
|
| 7 |
+
# 日志输出到文件 log_lqa.log, 格式包含时间、级别、文件名、函数名、行号及消息内容
|
| 8 |
+
# - logger: 模块加载时创建的全局 logger 实例, 供其他模块直接导入使用
|
| 9 |
+
"""
|
| 10 |
+
import os
|
| 11 |
+
import logging
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def get_logger():
|
| 15 |
+
_logger = logging.getLogger('handle')
|
| 16 |
+
log_path = os.environ.get('LOG_PATH', './log')
|
| 17 |
+
if not os.path.exists(log_path):
|
| 18 |
+
os.makedirs(log_path)
|
| 19 |
+
_logger.setLevel(logging.INFO)
|
| 20 |
+
fh = logging.FileHandler('{}/log_lqa.log'.format(log_path))
|
| 21 |
+
fh.setFormatter(
|
| 22 |
+
logging.Formatter("%(asctime)s - %(levelname)s - %(filename)s %(funcName)s %(lineno)s - %(message)s"))
|
| 23 |
+
_logger.addHandler(fh)
|
| 24 |
+
return _logger
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
logger = get_logger()
|
timi_hok_game_translator/LQA_WMP/lqa_service/common/ocr_provider/__init__.py
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: ocr_provider/__init__.py
|
| 4 |
+
# @desc: OCR 适配层统一入口模块, 职责包括:
|
| 5 |
+
# - PROVIDERS: 注册表, 维护 OCR_PROVIDER 名称 -> (模块路径, 类名) 的映射,
|
| 6 |
+
# 支持 paddleocr/paddleocr_http/rapidocr/easyocr/tesseract/
|
| 7 |
+
# tencentcloud/baidu/azure/cvtest/none 共 10 种实现
|
| 8 |
+
# - resolve_name: 归一化 provider 名称, 空值及关闭别名 (''/none/null/off/
|
| 9 |
+
# disabled/false) 统一映射为 'none'
|
| 10 |
+
# - get_provider: 按配置懒加载并缓存 provider 实例, 避免重复初始化本地模型;
|
| 11 |
+
# 未配置或显式关闭时返回 NullOcr 空实现, 不抛异常
|
| 12 |
+
# - is_available: 探测当前 OCR 能力是否可用, 结果带缓存 (成功缓存 1 小时,
|
| 13 |
+
# 失败缓存 60 秒后允许重试), 可安全在每次请求中调用
|
| 14 |
+
# - reset_cache: 清空 provider 实例与可用性探测缓存 (用于测试)
|
| 15 |
+
#
|
| 16 |
+
# OCR 在本服务中是可选能力, 通过环境变量 OCR_PROVIDER 选择具体实现,
|
| 17 |
+
# 默认 rapidocr (开源离线, 无需额外部署), 当设置为 none 或指定引擎未安装/
|
| 18 |
+
# 不可用时, 服务仍可正常启动并完成检测, 仅会跳过依赖 OCR 的检测项
|
| 19 |
+
# (如错译检测、文本超框检测), 其余检测照常进行
|
| 20 |
+
#
|
| 21 |
+
# 典型用法:
|
| 22 |
+
# from common.ocr_provider import get_provider, is_available
|
| 23 |
+
# available, msg = is_available()
|
| 24 |
+
# if available:
|
| 25 |
+
# data = get_provider().recognize(img_base64, project='demo')
|
| 26 |
+
"""
|
| 27 |
+
import logging
|
| 28 |
+
import time
|
| 29 |
+
|
| 30 |
+
from .base import OcrProvider, OcrError, NullOcr, quad_to_box
|
| 31 |
+
|
| 32 |
+
logger = logging.getLogger('handle')
|
| 33 |
+
|
| 34 |
+
#: provider 名称 -> (模块路径, 类名)
|
| 35 |
+
PROVIDERS = {
|
| 36 |
+
'paddleocr': ('.paddle', 'PaddleOcrLocal'),
|
| 37 |
+
'paddleocr_http': ('.paddle', 'PaddleOcrHttp'),
|
| 38 |
+
'rapidocr': ('.local_engines', 'RapidOcr'),
|
| 39 |
+
'easyocr': ('.local_engines', 'EasyOcr'),
|
| 40 |
+
'tesseract': ('.local_engines', 'TesseractOcr'),
|
| 41 |
+
'tencentcloud': ('.cloud', 'TencentCloudOcr'),
|
| 42 |
+
'baidu': ('.cloud', 'BaiduOcr'),
|
| 43 |
+
'azure': ('.cloud', 'AzureOcr'),
|
| 44 |
+
'cvtest': ('.cvtest', 'CvtestOcr'),
|
| 45 |
+
#: 显式关闭 OCR
|
| 46 |
+
'none': ('.base', 'NullOcr'),
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
#: OCR_PROVIDER 取这些值时等同于 none
|
| 50 |
+
_DISABLED_ALIASES = ('', 'none', 'null', 'off', 'disabled', 'false')
|
| 51 |
+
|
| 52 |
+
_instance = None
|
| 53 |
+
_instance_key = None
|
| 54 |
+
|
| 55 |
+
#: 可用性探测缓存: (是否可用, 描述, 过期时间戳)
|
| 56 |
+
_probe_cache = None
|
| 57 |
+
#: 探测失败后的重试间隔 (秒); 成功结果在进程内长期有效
|
| 58 |
+
_PROBE_RETRY_INTERVAL = 60
|
| 59 |
+
_PROBE_OK_TTL = 3600
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def _build(name, config):
|
| 63 |
+
if name not in PROVIDERS:
|
| 64 |
+
raise OcrError(
|
| 65 |
+
' 未知的 OCR_PROVIDER=%s, 可选: %s' % (name, ', '.join(sorted(PROVIDERS)))
|
| 66 |
+
)
|
| 67 |
+
import importlib
|
| 68 |
+
|
| 69 |
+
module_path, class_name = PROVIDERS[name]
|
| 70 |
+
module = importlib.import_module(module_path, package=__name__)
|
| 71 |
+
return getattr(module, class_name)(config)
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def resolve_name(name=None):
|
| 75 |
+
"""归一化 provider 名称: 空值/关闭别名统一映射为 none"""
|
| 76 |
+
if name is None:
|
| 77 |
+
from config import baseconfig
|
| 78 |
+
|
| 79 |
+
name = baseconfig.OCR_PROVIDER
|
| 80 |
+
name = (name or '').strip().lower()
|
| 81 |
+
if name in _DISABLED_ALIASES:
|
| 82 |
+
return 'none'
|
| 83 |
+
return name
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def get_provider(name=None, config=None, cache=True):
|
| 87 |
+
"""获取 OCR provider 实例 (默认按配置缓存, 避免重复加载本地模型)
|
| 88 |
+
|
| 89 |
+
未配置或配置为关闭时返回 :class:`NullOcr`, 不会抛异常
|
| 90 |
+
"""
|
| 91 |
+
global _instance, _instance_key # pylint: disable=global-statement
|
| 92 |
+
|
| 93 |
+
from config import baseconfig
|
| 94 |
+
|
| 95 |
+
name = resolve_name(name)
|
| 96 |
+
if config is None:
|
| 97 |
+
config = baseconfig.ocr_provider_config()
|
| 98 |
+
if not cache:
|
| 99 |
+
return _build(name, config)
|
| 100 |
+
|
| 101 |
+
key = (name, tuple(sorted((k, str(v)) for k, v in config.items())))
|
| 102 |
+
if _instance is None or _instance_key != key:
|
| 103 |
+
_instance = _build(name, config)
|
| 104 |
+
_instance_key = key
|
| 105 |
+
logger.info('OCR provider 已初始化: %s', name)
|
| 106 |
+
return _instance
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def is_available(force=False):
|
| 110 |
+
"""OCR 能力是否可用 (结果带缓存, 可安全用于每次请求)
|
| 111 |
+
|
| 112 |
+
:param force: True 时忽略缓存重新探测
|
| 113 |
+
:return: (bool 是否可用, str 描述信息)
|
| 114 |
+
"""
|
| 115 |
+
global _probe_cache # pylint: disable=global-statement
|
| 116 |
+
|
| 117 |
+
now = time.time()
|
| 118 |
+
if not force and _probe_cache is not None and now < _probe_cache[2]:
|
| 119 |
+
return _probe_cache[0], _probe_cache[1]
|
| 120 |
+
|
| 121 |
+
name = resolve_name()
|
| 122 |
+
if name == 'none':
|
| 123 |
+
msg = '未配置 OCR (OCR_PROVIDER=none), 依赖 OCR 的检测项将跳过'
|
| 124 |
+
_probe_cache = (False, msg, now + _PROBE_OK_TTL)
|
| 125 |
+
return False, msg
|
| 126 |
+
|
| 127 |
+
try:
|
| 128 |
+
provider = get_provider()
|
| 129 |
+
if not getattr(provider, 'capable', True):
|
| 130 |
+
msg = 'OCR 已关闭: %s' % name
|
| 131 |
+
_probe_cache = (False, msg, now + _PROBE_OK_TTL)
|
| 132 |
+
return False, msg
|
| 133 |
+
detail = provider.test_connection()
|
| 134 |
+
msg = '%s: %s' % (name, detail)
|
| 135 |
+
_probe_cache = (True, msg, now + _PROBE_OK_TTL)
|
| 136 |
+
logger.info('OCR 可用 - %s', msg)
|
| 137 |
+
return True, msg
|
| 138 |
+
except OcrError as ex:
|
| 139 |
+
msg = 'OCR 不可用 (%s): %s' % (name, ex)
|
| 140 |
+
except Exception as ex: # pylint: disable=broad-except
|
| 141 |
+
msg = 'OCR 探测异常 (%s): %s' % (name, ex)
|
| 142 |
+
_probe_cache = (False, msg, now + _PROBE_RETRY_INTERVAL)
|
| 143 |
+
logger.warning('%s; 将跳过依赖 OCR 的检测项', msg)
|
| 144 |
+
return False, msg
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def reset_cache():
|
| 148 |
+
"""清空 provider 与探测缓存 (测试用)"""
|
| 149 |
+
global _instance, _instance_key, _probe_cache # pylint: disable=global-statement
|
| 150 |
+
_instance = None
|
| 151 |
+
_instance_key = None
|
| 152 |
+
_probe_cache = None
|
timi_hok_game_translator/LQA_WMP/lqa_service/common/ocr_provider/base.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: ocr_provider/base.py
|
| 4 |
+
# @desc: OCR 适配层抽象接口模块, 定义所有 OCR provider 必须遵循的统一规范, 包括:
|
| 5 |
+
# - OcrError: OCR 调用失败的统一异常类型, 各 provider 在识别失败/配置缺失时抛出
|
| 6 |
+
# - base64_to_ndarray: base64 图像数据解码为 OpenCV BGR ndarray, 供本地推理类
|
| 7 |
+
# provider (EasyOCR/RapidOCR/Tesseract/PaddleOCR本地) 使用
|
| 8 |
+
# - quad_to_box: 将任意四点多边形坐标 (如 PaddleOCR/EasyOCR 返回的文本框顶点)
|
| 9 |
+
# 转换为轴对齐的矩形包围盒 [x1, y1, x2, y2]
|
| 10 |
+
# - OcrProvider: provider 抽象基类, 约定子类属性 (name 标识、remote 是否依赖远程
|
| 11 |
+
# 服务、capable 是否具备真实识别能力) 及抽象方法 recognize;
|
| 12 |
+
# 并提供默认的 test_connection 自检方法, 通过识别一张内置测试图
|
| 13 |
+
# 验证 provider 是否正常工作
|
| 14 |
+
# - NullOcr: 空实现 provider(name='none'), 用于显式关闭 OCR 能力; 选用后不会
|
| 15 |
+
# 产生任何识别调用, 依赖 OCR 的检测项 (错译、文本超框) 自动跳过,
|
| 16 |
+
# 其余不依赖 OCR 的检测照常进行
|
| 17 |
+
#
|
| 18 |
+
# LQA 的超框/漏译检测依赖 OCR 返回「文本内容 + 精确边界框」, 因此只接受能同时
|
| 19 |
+
# 给出两者的 OCR 服务, 各 provider 的 recognize 方法需统一返回以下格式 (与历史
|
| 20 |
+
# 接口保持一致):
|
| 21 |
+
# [{"area": [x1, y1, x2, y2], "result": "识别出的文本"}, ...]
|
| 22 |
+
"""
|
| 23 |
+
from abc import ABC, abstractmethod
|
| 24 |
+
import base64
|
| 25 |
+
import logging
|
| 26 |
+
|
| 27 |
+
import numpy as np
|
| 28 |
+
import cv2
|
| 29 |
+
|
| 30 |
+
logger = logging.getLogger('handle')
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class OcrError(Exception):
|
| 34 |
+
"""OCR 调用失败"""
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def base64_to_ndarray(img_base64):
|
| 38 |
+
"""base64 -> BGR ndarray"""
|
| 39 |
+
raw = base64.b64decode(img_base64)
|
| 40 |
+
img = cv2.imdecode(np.frombuffer(raw, np.uint8), cv2.IMREAD_COLOR)
|
| 41 |
+
if img is None:
|
| 42 |
+
raise OcrError('图像解码失败')
|
| 43 |
+
return img
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def quad_to_box(points):
|
| 47 |
+
"""任意多边形顶点 -> 轴对齐包围盒 [x1, y1, x2, y2]
|
| 48 |
+
|
| 49 |
+
PaddleOCR / EasyOCR 等返回的是四点多边形, 需转为 LQA 需要的矩形
|
| 50 |
+
"""
|
| 51 |
+
xs = [int(round(float(p[0]))) for p in points]
|
| 52 |
+
ys = [int(round(float(p[1]))) for p in points]
|
| 53 |
+
return [min(xs), min(ys), max(xs), max(ys)]
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class OcrProvider(ABC):
|
| 57 |
+
"""OCR 提供方抽象基类"""
|
| 58 |
+
|
| 59 |
+
name = 'base'
|
| 60 |
+
#: 是否依赖外部网络服务
|
| 61 |
+
remote = True
|
| 62 |
+
#: 是否提供真实 OCR 能力 (NullOcr 为 False)
|
| 63 |
+
capable = True
|
| 64 |
+
|
| 65 |
+
def __init__(self, config=None):
|
| 66 |
+
self.config = config or {}
|
| 67 |
+
|
| 68 |
+
@abstractmethod
|
| 69 |
+
def recognize(self, img_base64, project=None):
|
| 70 |
+
"""识别整图文字
|
| 71 |
+
|
| 72 |
+
:param img_base64: str, base64 编码的图像
|
| 73 |
+
:param project: str, 调用方项目标识 (部分服务用于鉴权/路由, 可忽略)
|
| 74 |
+
:return: list[dict], [{"area": [x1,y1,x2,y2], "result": "文本"}, ...]
|
| 75 |
+
:raises OcrError: 调用失败
|
| 76 |
+
"""
|
| 77 |
+
|
| 78 |
+
def test_connection(self):
|
| 79 |
+
"""连通性自检, 返回描述信息字符串"""
|
| 80 |
+
img = np.full((48, 160, 3), 255, np.uint8)
|
| 81 |
+
cv2.putText(img, 'LQA123', (6, 34), cv2.FONT_HERSHEY_SIMPLEX, 1.0, (0, 0, 0), 2)
|
| 82 |
+
ok, buf = cv2.imencode('.png', img)
|
| 83 |
+
if not ok:
|
| 84 |
+
raise OcrError('测试图编码失败')
|
| 85 |
+
data = self.recognize(base64.b64encode(buf).decode('ascii'))
|
| 86 |
+
texts = [d.get('result', '') for d in (data or [])]
|
| 87 |
+
return '连接正常, 识别到 %d 个文本块: %s' % (len(texts), texts[:5])
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
class NullOcr(OcrProvider):
|
| 91 |
+
"""空实现: 显式声明「不使用 OCR」(OCR_PROVIDER=none)
|
| 92 |
+
|
| 93 |
+
OCR 在本服务中是可选能力, 选用本 provider 时不会产生任何识别调用,
|
| 94 |
+
依赖 OCR 的检测项 (错译、文本超框) 自动跳过, 其余检测照常进行
|
| 95 |
+
"""
|
| 96 |
+
|
| 97 |
+
name = 'none'
|
| 98 |
+
remote = False
|
| 99 |
+
capable = False
|
| 100 |
+
|
| 101 |
+
def recognize(self, img_base64, project=None):
|
| 102 |
+
return []
|
| 103 |
+
|
| 104 |
+
def test_connection(self):
|
| 105 |
+
return '已显式关闭 OCR (OCR_PROVIDER=none), 依赖 OCR 的检测项将跳过'
|
timi_hok_game_translator/LQA_WMP/lqa_service/common/ocr_provider/cloud.py
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: ocr_provider/cloud.py
|
| 4 |
+
# @desc: 云厂商 OCR 适配模块, 提供以下 provider 实现:
|
| 5 |
+
# - TencentCloudOcr (name='tencentcloud')
|
| 6 |
+
# 腾讯云通用印刷体识别 GeneralBasicOCR
|
| 7 |
+
# 依赖: pip install tencentcloud-sdk-python-ocr
|
| 8 |
+
# 相关配置: OCR_SECRET_ID / OCR_SECRET_KEY / OCR_REGION (默认 ap-guangzhou)
|
| 9 |
+
# - BaiduOcr (name='baidu')
|
| 10 |
+
# 百度智能云通用文字识别 (含位置信息)
|
| 11 |
+
# 相关配置: OCR_API_KEY / OCR_SECRET_KEY
|
| 12 |
+
# 内部通过 OAuth2 client_credentials 方式获取 access_token 并缓存 (类变量 _token)
|
| 13 |
+
# - AzureOcr (name='azure')
|
| 14 |
+
# Azure AI Vision Read API
|
| 15 |
+
# 相关配置: OCR_HOST (服务 endpoint) / OCR_API_KEY
|
| 16 |
+
#
|
| 17 |
+
# 这些服务均返回文本内容及对应边界框 (area: [x1,y1,x2,y2]), 满足 LQA 超框检测对
|
| 18 |
+
# 文本精确定位的要求, 均为按量计费的远程调用 (remote=True), 批量识别时需注意
|
| 19 |
+
# 云厂商侧的成本与 QPS 限制, 避免触发限流或产生高额费用
|
| 20 |
+
"""
|
| 21 |
+
import json
|
| 22 |
+
import logging
|
| 23 |
+
|
| 24 |
+
import requests
|
| 25 |
+
|
| 26 |
+
from .base import OcrProvider, OcrError, quad_to_box
|
| 27 |
+
|
| 28 |
+
logger = logging.getLogger('handle')
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class TencentCloudOcr(OcrProvider):
|
| 32 |
+
"""腾讯云通用印刷体识别 GeneralBasicOCR
|
| 33 |
+
|
| 34 |
+
需要 pip install tencentcloud-sdk-python-ocr
|
| 35 |
+
配置: OCR_SECRET_ID / OCR_SECRET_KEY / OCR_REGION
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
name = 'tencentcloud'
|
| 39 |
+
remote = True
|
| 40 |
+
|
| 41 |
+
def recognize(self, img_base64, project=None):
|
| 42 |
+
secret_id = self.config.get('secret_id')
|
| 43 |
+
secret_key = self.config.get('secret_key')
|
| 44 |
+
if not (secret_id and secret_key):
|
| 45 |
+
raise OcrError('未配置 OCR_SECRET_ID / OCR_SECRET_KEY')
|
| 46 |
+
try:
|
| 47 |
+
from tencentcloud.common import credential
|
| 48 |
+
from tencentcloud.ocr.v20181119 import ocr_client, models
|
| 49 |
+
except ImportError as err:
|
| 50 |
+
raise OcrError(
|
| 51 |
+
'未安装腾讯云 SDK, 请执行: pip install tencentcloud-sdk-python-ocr'
|
| 52 |
+
) from err
|
| 53 |
+
|
| 54 |
+
try:
|
| 55 |
+
cred = credential.Credential(secret_id, secret_key)
|
| 56 |
+
client = ocr_client.OcrClient(cred, self.config.get('region', 'ap-guangzhou'))
|
| 57 |
+
req = models.GeneralBasicOCRRequest()
|
| 58 |
+
req.from_json_string(json.dumps({'ImageBase64': img_base64}))
|
| 59 |
+
resp = client.GeneralBasicOCR(req)
|
| 60 |
+
except Exception as err: # pylint: disable=broad-except
|
| 61 |
+
raise OcrError('腾讯云 OCR 调用失败: %s' % err) from err
|
| 62 |
+
|
| 63 |
+
results = []
|
| 64 |
+
for item in resp.TextDetections or []:
|
| 65 |
+
text = item.DetectedText
|
| 66 |
+
poly = item.Polygon
|
| 67 |
+
if not text:
|
| 68 |
+
continue
|
| 69 |
+
if poly:
|
| 70 |
+
results.append({'area': quad_to_box([(p.X, p.Y) for p in poly]), 'result': text})
|
| 71 |
+
elif item.ItemPolygon:
|
| 72 |
+
p = item.ItemPolygon
|
| 73 |
+
results.append({
|
| 74 |
+
'area': [p.X, p.Y, p.X + p.Width, p.Y + p.Height],
|
| 75 |
+
'result': text,
|
| 76 |
+
})
|
| 77 |
+
return results
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
class BaiduOcr(OcrProvider):
|
| 81 |
+
"""百度智能云通用文字识别 (含位置信息)
|
| 82 |
+
|
| 83 |
+
配置: OCR_API_KEY / OCR_SECRET_KEY
|
| 84 |
+
"""
|
| 85 |
+
|
| 86 |
+
name = 'baidu'
|
| 87 |
+
remote = True
|
| 88 |
+
|
| 89 |
+
TOKEN_URL = 'https://aip.baidubce.com/oauth/2.0/token'
|
| 90 |
+
OCR_API = 'https://aip.baidubce.com/rest/2.0/ocr/v1/general'
|
| 91 |
+
|
| 92 |
+
_token = None
|
| 93 |
+
|
| 94 |
+
def _get_token(self):
|
| 95 |
+
if BaiduOcr._token:
|
| 96 |
+
return BaiduOcr._token
|
| 97 |
+
api_key = self.config.get('api_key')
|
| 98 |
+
secret_key = self.config.get('secret_key')
|
| 99 |
+
if not (api_key and secret_key):
|
| 100 |
+
raise OcrError('未配置 OCR_API_KEY / OCR_SECRET_KEY')
|
| 101 |
+
try:
|
| 102 |
+
resp = requests.post(self.TOKEN_URL, params={
|
| 103 |
+
'grant_type': 'client_credentials',
|
| 104 |
+
'client_id': api_key,
|
| 105 |
+
'client_secret': secret_key,
|
| 106 |
+
}, timeout=30)
|
| 107 |
+
BaiduOcr._token = resp.json()['access_token']
|
| 108 |
+
except Exception as err: # pylint: disable=broad-except
|
| 109 |
+
raise OcrError('百度 OCR 获取 token 失败: %s' % err) from err
|
| 110 |
+
return BaiduOcr._token
|
| 111 |
+
|
| 112 |
+
def recognize(self, img_base64, project=None):
|
| 113 |
+
token = self._get_token()
|
| 114 |
+
try:
|
| 115 |
+
resp = requests.post(
|
| 116 |
+
self.OCR_API,
|
| 117 |
+
params={'access_token': token},
|
| 118 |
+
data={'image': img_base64, 'recognize_granularity': 'small'},
|
| 119 |
+
headers={'Content-Type': 'application/x-www-form-urlencoded'},
|
| 120 |
+
timeout=int(self.config.get('timeout', 60)),
|
| 121 |
+
)
|
| 122 |
+
payload = resp.json()
|
| 123 |
+
except Exception as err: # pylint: disable=broad-except
|
| 124 |
+
raise OcrError('百度 OCR 调用失败: %s' % err) from err
|
| 125 |
+
|
| 126 |
+
if 'error_code' in payload:
|
| 127 |
+
raise OcrError('百度 OCR 错误 %s: %s' % (payload['error_code'], payload.get('error_msg')))
|
| 128 |
+
|
| 129 |
+
results = []
|
| 130 |
+
for item in payload.get('words_result') or []:
|
| 131 |
+
text = item.get('words')
|
| 132 |
+
loc = item.get('location') or {}
|
| 133 |
+
if not text or not loc:
|
| 134 |
+
continue
|
| 135 |
+
x, y = int(loc.get('left', 0)), int(loc.get('top', 0))
|
| 136 |
+
w, h = int(loc.get('width', 0)), int(loc.get('height', 0))
|
| 137 |
+
results.append({'area': [x, y, x + w, y + h], 'result': text})
|
| 138 |
+
return results
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
class AzureOcr(OcrProvider):
|
| 142 |
+
"""Azure AI Vision Read API
|
| 143 |
+
|
| 144 |
+
配置: OCR_HOST(endpoint) / OCR_API_KEY
|
| 145 |
+
"""
|
| 146 |
+
|
| 147 |
+
name = 'azure'
|
| 148 |
+
remote = True
|
| 149 |
+
|
| 150 |
+
def recognize(self, img_base64, project=None):
|
| 151 |
+
import base64 as _b64
|
| 152 |
+
|
| 153 |
+
endpoint = (self.config.get('host') or '').rstrip('/')
|
| 154 |
+
api_key = self.config.get('api_key')
|
| 155 |
+
if not (endpoint and api_key):
|
| 156 |
+
raise OcrError('未配置 OCR_HOST(endpoint) / OCR_API_KEY')
|
| 157 |
+
url = '%s/computervision/imageanalysis:analyze' % endpoint
|
| 158 |
+
try:
|
| 159 |
+
resp = requests.post(
|
| 160 |
+
url,
|
| 161 |
+
params={'features': 'read', 'api-version': '2024-02-01'},
|
| 162 |
+
headers={
|
| 163 |
+
'Ocp-Apim-Subscription-Key': api_key,
|
| 164 |
+
'Content-Type': 'application/octet-stream',
|
| 165 |
+
},
|
| 166 |
+
data=_b64.b64decode(img_base64),
|
| 167 |
+
timeout=int(self.config.get('timeout', 60)),
|
| 168 |
+
)
|
| 169 |
+
payload = resp.json()
|
| 170 |
+
except Exception as err: # pylint: disable=broad-except
|
| 171 |
+
raise OcrError('Azure OCR 调用失败: %s' % err) from err
|
| 172 |
+
|
| 173 |
+
if resp.status_code != 200:
|
| 174 |
+
raise OcrError('Azure OCR 返回 HTTP %s: %s' % (resp.status_code, payload))
|
| 175 |
+
|
| 176 |
+
results = []
|
| 177 |
+
blocks = (payload.get('readResult') or {}).get('blocks') or []
|
| 178 |
+
for block in blocks:
|
| 179 |
+
for line in block.get('lines') or []:
|
| 180 |
+
text = line.get('text')
|
| 181 |
+
poly = line.get('boundingPolygon') or []
|
| 182 |
+
if not text or not poly:
|
| 183 |
+
continue
|
| 184 |
+
results.append({
|
| 185 |
+
'area': quad_to_box([(p['x'], p['y']) for p in poly]),
|
| 186 |
+
'result': text,
|
| 187 |
+
})
|
| 188 |
+
return results
|
timi_hok_game_translator/LQA_WMP/lqa_service/common/ocr_provider/cvtest.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: ocr_provider/cvtest.py
|
| 4 |
+
# @desc: CVTest OCR 适配模块 (内网自建服务, 向后兼容历史接口), 提供 CvtestOcr provider 实现:
|
| 5 |
+
# - name='cvtest', remote=True, 通过 HTTP 调用内网自建的 OCR 识别服务
|
| 6 |
+
#
|
| 7 |
+
# 通信协议:
|
| 8 |
+
# POST {OCR_URL}
|
| 9 |
+
# headers: {"project-method": "<project>_ocr"}
|
| 10 |
+
# project 由调用方传入或取配置 OCR_DEFAULT_PROJECT; 缺失该请求头会被服务端
|
| 11 |
+
# 判为 "No authorization"
|
| 12 |
+
# body: {"img_base64": "...", "location": null, "projectid": <OCR_PROJECT_ID, 默认19998>}
|
| 13 |
+
# resp: {"errCode": 0, "data": [{"area": [x1,y1,x2,y2], "result": "文本"}, ...]}
|
| 14 |
+
#
|
| 15 |
+
# 错误处理与重试:
|
| 16 |
+
# - errCode == 0 且 data 非空: 识别成功, 返回 data
|
| 17 |
+
# - errCode == 0 但 data 为空: 通常是鉴权失败 (project-method 缺失或项目未授权),
|
| 18 |
+
# 抛出 OcrError 并提示检查请求头及项目授权
|
| 19 |
+
# - errCode == -2: 服务侧繁忙, 按 RETRY_INTERVAL(0.6s) 间隔重试, 最多 MAX_RETRY(10) 次
|
| 20 |
+
# - 其他 errCode: 直接抛出 OcrError, 附带 errCode 与 errMsg
|
| 21 |
+
# - HTTP 非 200 / 响应非 JSON / 请求异常: 均包装为 OcrError 抛出
|
| 22 |
+
#
|
| 23 |
+
# 相关配置: OCR_URL (服务地址)、OCR_TIMEOUT (请求超时, 默认 60s)、
|
| 24 |
+
# OCR_PROJECT_ID (默认项目ID, 默认19998)、OCR_DEFAULT_PROJECT (默认项目标识)
|
| 25 |
+
"""
|
| 26 |
+
import time
|
| 27 |
+
import logging
|
| 28 |
+
|
| 29 |
+
import requests
|
| 30 |
+
|
| 31 |
+
from .base import OcrProvider, OcrError
|
| 32 |
+
|
| 33 |
+
logger = logging.getLogger('handle')
|
| 34 |
+
|
| 35 |
+
MAX_RETRY = 10
|
| 36 |
+
RETRY_INTERVAL = 0.6
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
class CvtestOcr(OcrProvider):
|
| 40 |
+
"""内网 CVTest OCR 服务"""
|
| 41 |
+
|
| 42 |
+
name = 'cvtest'
|
| 43 |
+
remote = True
|
| 44 |
+
|
| 45 |
+
def recognize(self, img_base64, project=None):
|
| 46 |
+
url = self.config.get('url')
|
| 47 |
+
if not url:
|
| 48 |
+
raise OcrError('未配置 OCR_URL')
|
| 49 |
+
timeout = int(self.config.get('timeout', 60))
|
| 50 |
+
project_id = int(self.config.get('project_id', 19998))
|
| 51 |
+
|
| 52 |
+
data = {'img_base64': img_base64, 'location': None, 'projectid': project_id}
|
| 53 |
+
headers = {}
|
| 54 |
+
# 该服务依赖 project-method 请求头鉴权, 缺失时返回 No authorization 且 data 为 null
|
| 55 |
+
project = project or self.config.get('default_project')
|
| 56 |
+
if project:
|
| 57 |
+
headers['project-method'] = '%s_ocr' % project
|
| 58 |
+
|
| 59 |
+
last_err = None
|
| 60 |
+
for attempt in range(MAX_RETRY):
|
| 61 |
+
try:
|
| 62 |
+
resp = requests.post(url=url, json=data, headers=headers, timeout=timeout)
|
| 63 |
+
except requests.RequestException as err:
|
| 64 |
+
raise OcrError('OCR 服务请求失败: %s' % err) from err
|
| 65 |
+
if resp.status_code != 200:
|
| 66 |
+
raise OcrError('OCR 服务返回 HTTP %s' % resp.status_code)
|
| 67 |
+
try:
|
| 68 |
+
payload = resp.json()
|
| 69 |
+
except ValueError as err:
|
| 70 |
+
raise OcrError('OCR 服务返回非 JSON') from err
|
| 71 |
+
|
| 72 |
+
err_code = payload.get('errCode')
|
| 73 |
+
if err_code == 0:
|
| 74 |
+
result = payload.get('data')
|
| 75 |
+
if result is None:
|
| 76 |
+
# errCode=0 但 data 为空, 通常是鉴权失败, 历史实现会静默返回 None
|
| 77 |
+
raise OcrError(
|
| 78 |
+
'OCR 服务未返回数据: %s (请确认请求头 project-method 及项目授权)'
|
| 79 |
+
% (payload.get('err_msg') or payload.get('errMsg') or '未知原因')
|
| 80 |
+
)
|
| 81 |
+
return result
|
| 82 |
+
if err_code == -2: # 服务侧繁忙, 可重试
|
| 83 |
+
last_err = payload.get('errMsg')
|
| 84 |
+
logger.warning('OCR 重试 %s/%s: %s', attempt + 1, MAX_RETRY, last_err)
|
| 85 |
+
time.sleep(RETRY_INTERVAL)
|
| 86 |
+
continue
|
| 87 |
+
raise OcrError('OCR 服务错误 errCode=%s %s' % (err_code, payload.get('errMsg')))
|
| 88 |
+
raise OcrError('OCR 服务重试 %s 次仍失败: %s' % (MAX_RETRY, last_err))
|
timi_hok_game_translator/LQA_WMP/lqa_service/common/ocr_provider/local_engines.py
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: ocr_provider/local_engines.py
|
| 4 |
+
# @desc: 其他可离线部署的 OCR 引擎适配模块, 提供以下三个 provider 实现:
|
| 5 |
+
# - EasyOcr (name='easyocr')
|
| 6 |
+
# 开源 OCR 引擎, 支持 80+ 语种, 识别结果为四点框
|
| 7 |
+
# 依赖: pip install easyocr
|
| 8 |
+
# 相关配置: OCR_LANG (逗号分隔的语言列表, 默认 ch_sim,en)、OCR_USE_GPU (是否启用 GPU)
|
| 9 |
+
# 引擎以类变量缓存 (_reader), 同进程内仅初始化一次
|
| 10 |
+
# - RapidOcr (name='rapidocr', 默认 provider)
|
| 11 |
+
# PaddleOCR 模型的 ONNXRuntime 推理版, 无需安装 paddle 依赖, 体积小、启动快
|
| 12 |
+
# 依赖: pip install rapidocr-onnxruntime
|
| 13 |
+
# 引擎以类变量缓存 (_engine), 同进程内仅初始化一次
|
| 14 |
+
# - TesseractOcr (name='tesseract')
|
| 15 |
+
# 开源老牌 OCR 引擎
|
| 16 |
+
# 依赖: pip install pytesseract, 并需在系统中安装 tesseract 可执行程序及对应语言包
|
| 17 |
+
# 相关配置: OCR_TESSERACT_CMD (tesseract 可执行文件路径, 未加入 PATH 时需指定)、
|
| 18 |
+
# OCR_LANG (识别语言, 默认 chi_sim+eng)
|
| 19 |
+
# 注意: 对游戏 UI 这类复杂背景、艺术字体的识别率明显低于 PaddleOCR,
|
| 20 |
+
# 仅建议在简单纯色背景场景下使用
|
| 21 |
+
#
|
| 22 |
+
# 通过环境变量 OCR_PROVIDER 设置为对应 name 值 (easyocr/rapidocr/tesseract) 以启用相应实现
|
| 23 |
+
"""
|
| 24 |
+
import logging
|
| 25 |
+
|
| 26 |
+
from .base import OcrProvider, OcrError, quad_to_box, base64_to_ndarray
|
| 27 |
+
|
| 28 |
+
logger = logging.getLogger('handle')
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class EasyOcr(OcrProvider):
|
| 32 |
+
"""EasyOCR (开源, 80+ 语种, 返回四点框)
|
| 33 |
+
|
| 34 |
+
pip install easyocr
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
name = 'easyocr'
|
| 38 |
+
remote = False
|
| 39 |
+
|
| 40 |
+
_reader = None
|
| 41 |
+
|
| 42 |
+
def _get_reader(self):
|
| 43 |
+
if EasyOcr._reader is not None:
|
| 44 |
+
return EasyOcr._reader
|
| 45 |
+
try:
|
| 46 |
+
import easyocr
|
| 47 |
+
except ImportError as err:
|
| 48 |
+
raise OcrError('未安装 EasyOCR, 请执行: pip install easyocr') from err
|
| 49 |
+
langs = [x.strip() for x in str(self.config.get('lang', 'ch_sim,en')).split(',') if x.strip()]
|
| 50 |
+
use_gpu = str(self.config.get('use_gpu', 'false')).lower() == 'true'
|
| 51 |
+
EasyOcr._reader = easyocr.Reader(langs, gpu=use_gpu, verbose=False)
|
| 52 |
+
logger.info('EasyOCR 引擎已加载 langs=%s gpu=%s', langs, use_gpu)
|
| 53 |
+
return EasyOcr._reader
|
| 54 |
+
|
| 55 |
+
def recognize(self, img_base64, project=None):
|
| 56 |
+
reader = self._get_reader()
|
| 57 |
+
img = base64_to_ndarray(img_base64)
|
| 58 |
+
try:
|
| 59 |
+
raw = reader.readtext(img)
|
| 60 |
+
except Exception as err: # pylint: disable=broad-except
|
| 61 |
+
raise OcrError('EasyOCR 识别失败: %s' % err) from err
|
| 62 |
+
results = []
|
| 63 |
+
for item in raw or []:
|
| 64 |
+
try:
|
| 65 |
+
points, text = item[0], item[1]
|
| 66 |
+
except (IndexError, TypeError):
|
| 67 |
+
continue
|
| 68 |
+
if not text:
|
| 69 |
+
continue
|
| 70 |
+
results.append({'area': quad_to_box(points), 'result': text})
|
| 71 |
+
return results
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
class RapidOcr(OcrProvider):
|
| 75 |
+
"""RapidOCR (PaddleOCR 模型的 ONNXRuntime 推理版, 无需 paddle 依赖, 体积小)
|
| 76 |
+
|
| 77 |
+
pip install rapidocr-onnxruntime
|
| 78 |
+
"""
|
| 79 |
+
|
| 80 |
+
name = 'rapidocr'
|
| 81 |
+
remote = False
|
| 82 |
+
|
| 83 |
+
_engine = None
|
| 84 |
+
|
| 85 |
+
def _get_engine(self):
|
| 86 |
+
if RapidOcr._engine is not None:
|
| 87 |
+
return RapidOcr._engine
|
| 88 |
+
try:
|
| 89 |
+
from rapidocr_onnxruntime import RapidOCR
|
| 90 |
+
except ImportError as err:
|
| 91 |
+
raise OcrError('未安装 RapidOCR, 请执行: pip install rapidocr-onnxruntime') from err
|
| 92 |
+
RapidOcr._engine = RapidOCR()
|
| 93 |
+
logger.info('RapidOCR 引擎已加载')
|
| 94 |
+
return RapidOcr._engine
|
| 95 |
+
|
| 96 |
+
def recognize(self, img_base64, project=None):
|
| 97 |
+
engine = self._get_engine()
|
| 98 |
+
img = base64_to_ndarray(img_base64)
|
| 99 |
+
try:
|
| 100 |
+
raw, _elapse = engine(img)
|
| 101 |
+
except Exception as err: # pylint: disable=broad-except
|
| 102 |
+
raise OcrError('RapidOCR 识别失败: %s' % err) from err
|
| 103 |
+
results = []
|
| 104 |
+
for item in raw or []:
|
| 105 |
+
try:
|
| 106 |
+
points, text = item[0], item[1]
|
| 107 |
+
except (IndexError, TypeError):
|
| 108 |
+
continue
|
| 109 |
+
if not text:
|
| 110 |
+
continue
|
| 111 |
+
results.append({'area': quad_to_box(points), 'result': text})
|
| 112 |
+
return results
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
class TesseractOcr(OcrProvider):
|
| 116 |
+
"""Tesseract (开源老牌引擎)
|
| 117 |
+
|
| 118 |
+
pip install pytesseract 并安装 tesseract 可执行程序与语言包
|
| 119 |
+
注意: 对游戏 UI 这类复杂背景、艺术字体的识别率明显低于 PaddleOCR,
|
| 120 |
+
仅建议在简单纯色背景场景使用
|
| 121 |
+
"""
|
| 122 |
+
|
| 123 |
+
name = 'tesseract'
|
| 124 |
+
remote = False
|
| 125 |
+
|
| 126 |
+
def recognize(self, img_base64, project=None):
|
| 127 |
+
try:
|
| 128 |
+
import pytesseract
|
| 129 |
+
from pytesseract import Output
|
| 130 |
+
except ImportError as err:
|
| 131 |
+
raise OcrError('未安装 pytesseract, 请执行: pip install pytesseract') from err
|
| 132 |
+
|
| 133 |
+
cmd = self.config.get('tesseract_cmd')
|
| 134 |
+
if cmd:
|
| 135 |
+
pytesseract.pytesseract.tesseract_cmd = cmd
|
| 136 |
+
lang = self.config.get('lang', 'chi_sim+eng')
|
| 137 |
+
img = base64_to_ndarray(img_base64)
|
| 138 |
+
try:
|
| 139 |
+
data = pytesseract.image_to_data(img, lang=lang, output_type=Output.DICT)
|
| 140 |
+
except Exception as err: # pylint: disable=broad-except
|
| 141 |
+
raise OcrError('Tesseract 识别失败: %s' % err) from err
|
| 142 |
+
|
| 143 |
+
results = []
|
| 144 |
+
count = len(data.get('text', []))
|
| 145 |
+
for i in range(count):
|
| 146 |
+
text = (data['text'][i] or '').strip()
|
| 147 |
+
if not text:
|
| 148 |
+
continue
|
| 149 |
+
try:
|
| 150 |
+
conf = float(data['conf'][i])
|
| 151 |
+
except (ValueError, TypeError):
|
| 152 |
+
conf = -1
|
| 153 |
+
if conf < 0:
|
| 154 |
+
continue
|
| 155 |
+
x, y = int(data['left'][i]), int(data['top'][i])
|
| 156 |
+
w, h = int(data['width'][i]), int(data['height'][i])
|
| 157 |
+
results.append({'area': [x, y, x + w, y + h], 'result': text})
|
| 158 |
+
return results
|
timi_hok_game_translator/LQA_WMP/lqa_service/common/ocr_provider/paddle.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: ocr_provider/paddle.py
|
| 4 |
+
# @desc: PaddleOCR 适配模块, 提供两个 OCR provider 实现:
|
| 5 |
+
# - PaddleOcrLocal (name='paddleocr')
|
| 6 |
+
# 本进程内直接加载 PaddleOCR 模型进行识别 (离线, 无需外部服务)
|
| 7 |
+
# 依赖: pip install paddleocr paddlepaddle
|
| 8 |
+
# 相关配置: OCR_LANG (识别语言,默认 ch)、OCR_USE_GPU (是否启用 GPU, 默认 false)
|
| 9 |
+
# 模型以类变量缓存 (_engine), 同进程内仅加载一次, 兼容新旧版本 PaddleOCR 的初始化参数差异
|
| 10 |
+
# - PaddleOcrHttp (name='paddleocr_http')
|
| 11 |
+
# 调用 PaddleOCR 官方 hubserving / PaddleX 部署的 HTTP 服务进行远程识别
|
| 12 |
+
# 相关配置: OCR_URL (服务地址, 必填)、OCR_TIMEOUT (请求超时时间, 默认 60s)
|
| 13 |
+
# 期望响应格式: {"results": [[{"text": "abc", "text_region": [[x,y],...]}, ...]]}
|
| 14 |
+
#
|
| 15 |
+
# PaddleOCR 对中日韩、拉丁语系支持较好, 可离线部署, 是一般场景下的推荐选择
|
| 16 |
+
# 通过环境变量 OCR_PROVIDER 设置为 paddleocr 或 paddleocr_http 以启用对应实现
|
| 17 |
+
"""
|
| 18 |
+
import base64
|
| 19 |
+
import logging
|
| 20 |
+
|
| 21 |
+
import requests
|
| 22 |
+
|
| 23 |
+
from .base import OcrProvider, OcrError, quad_to_box, base64_to_ndarray
|
| 24 |
+
|
| 25 |
+
logger = logging.getLogger('handle')
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class PaddleOcrLocal(OcrProvider):
|
| 29 |
+
"""进程内加载 PaddleOCR 模型 (离线, 无需外部服务)"""
|
| 30 |
+
|
| 31 |
+
name = 'paddleocr'
|
| 32 |
+
remote = False
|
| 33 |
+
|
| 34 |
+
_engine = None
|
| 35 |
+
|
| 36 |
+
def _get_engine(self):
|
| 37 |
+
if PaddleOcrLocal._engine is not None:
|
| 38 |
+
return PaddleOcrLocal._engine
|
| 39 |
+
try:
|
| 40 |
+
from paddleocr import PaddleOCR
|
| 41 |
+
except ImportError as err:
|
| 42 |
+
raise OcrError(
|
| 43 |
+
'未安装 PaddleOCR, 请执行: pip install paddleocr paddlepaddle'
|
| 44 |
+
) from err
|
| 45 |
+
lang = self.config.get('lang', 'ch')
|
| 46 |
+
use_gpu = str(self.config.get('use_gpu', 'false')).lower() == 'true'
|
| 47 |
+
kwargs = {'lang': lang, 'show_log': False, 'use_angle_cls': True}
|
| 48 |
+
try:
|
| 49 |
+
PaddleOcrLocal._engine = PaddleOCR(use_gpu=use_gpu, **kwargs)
|
| 50 |
+
except TypeError:
|
| 51 |
+
# 新版本 PaddleOCR 移除了 use_gpu / show_log 参数
|
| 52 |
+
PaddleOcrLocal._engine = PaddleOCR(lang=lang)
|
| 53 |
+
logger.info('PaddleOCR 本地引擎已加载 lang=%s use_gpu=%s', lang, use_gpu)
|
| 54 |
+
return PaddleOcrLocal._engine
|
| 55 |
+
|
| 56 |
+
def recognize(self, img_base64, project=None):
|
| 57 |
+
engine = self._get_engine()
|
| 58 |
+
img = base64_to_ndarray(img_base64)
|
| 59 |
+
try:
|
| 60 |
+
raw = engine.ocr(img)
|
| 61 |
+
except Exception as err: # pylint: disable=broad-except
|
| 62 |
+
raise OcrError('PaddleOCR 识别失败: %s' % err) from err
|
| 63 |
+
|
| 64 |
+
results = []
|
| 65 |
+
if not raw:
|
| 66 |
+
return results
|
| 67 |
+
# 兼容 [[...]] 与 [...] 两种返回层级
|
| 68 |
+
lines = raw[0] if raw and isinstance(raw[0], list) else raw
|
| 69 |
+
for line in lines or []:
|
| 70 |
+
if not line:
|
| 71 |
+
continue
|
| 72 |
+
try:
|
| 73 |
+
points, (text, _score) = line[0], line[1]
|
| 74 |
+
except (ValueError, IndexError, TypeError):
|
| 75 |
+
continue
|
| 76 |
+
if not text:
|
| 77 |
+
continue
|
| 78 |
+
results.append({'area': quad_to_box(points), 'result': text})
|
| 79 |
+
return results
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
class PaddleOcrHttp(OcrProvider):
|
| 83 |
+
"""PaddleOCR hubserving / PaddleX HTTP 服务
|
| 84 |
+
|
| 85 |
+
期望响应形如:
|
| 86 |
+
|
| 87 |
+
{"results": [[{"text": "abc", "text_region": [[x,y],...]}, ...]]}
|
| 88 |
+
"""
|
| 89 |
+
|
| 90 |
+
name = 'paddleocr_http'
|
| 91 |
+
remote = True
|
| 92 |
+
|
| 93 |
+
def recognize(self, img_base64, project=None):
|
| 94 |
+
url = self.config.get('url')
|
| 95 |
+
if not url:
|
| 96 |
+
raise OcrError('未配置 OCR_URL (PaddleOCR HTTP 服务地址)')
|
| 97 |
+
timeout = int(self.config.get('timeout', 60))
|
| 98 |
+
try:
|
| 99 |
+
resp = requests.post(url, json={'images': [img_base64]}, timeout=timeout)
|
| 100 |
+
except requests.RequestException as err:
|
| 101 |
+
raise OcrError('PaddleOCR 服务请求失败: %s' % err) from err
|
| 102 |
+
if resp.status_code != 200:
|
| 103 |
+
raise OcrError('PaddleOCR 服务返回 HTTP %s' % resp.status_code)
|
| 104 |
+
try:
|
| 105 |
+
payload = resp.json()
|
| 106 |
+
except ValueError as err:
|
| 107 |
+
raise OcrError('PaddleOCR 服务返回非 JSON') from err
|
| 108 |
+
|
| 109 |
+
groups = payload.get('results') or []
|
| 110 |
+
if groups and isinstance(groups[0], list):
|
| 111 |
+
items = groups[0]
|
| 112 |
+
else:
|
| 113 |
+
items = groups
|
| 114 |
+
results = []
|
| 115 |
+
for item in items or []:
|
| 116 |
+
text = item.get('text')
|
| 117 |
+
region = item.get('text_region') or item.get('text_box_position')
|
| 118 |
+
if not text or not region:
|
| 119 |
+
continue
|
| 120 |
+
results.append({'area': quad_to_box(region), 'result': text})
|
| 121 |
+
return results
|
timi_hok_game_translator/LQA_WMP/lqa_service/common/tools.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: tools.py
|
| 4 |
+
# @desc: 图像数据处理通用工具模块, 提供以下接口:
|
| 5 |
+
# - base64_to_mat: 将 base64 格式的图像数据解码为 OpenCV ndarray 格式,
|
| 6 |
+
# 支持灰度图 (gray)、带 alpha 通道 (alpha) 两种解码模式
|
| 7 |
+
# - mat_to_base64: 将 OpenCV ndarray 格式的图像数据编码 (JPEG) 并转换为 base64 字符串
|
| 8 |
+
# - img_draw_rect: 在图像上绘制标记框, 支持标准矩形框 (4维坐标 x1,y1,x2,y2)
|
| 9 |
+
# 和非标准四边形框 (8维坐标, 4个点) 两种绘制方式, 可自定义颜色和线宽样式
|
| 10 |
+
"""
|
| 11 |
+
import base64
|
| 12 |
+
import cv2
|
| 13 |
+
import numpy as np
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def base64_to_mat(base64_img, gray=False, alpha=False):
|
| 17 |
+
""" 数据base64转ndarray
|
| 18 |
+
:param base64_img: str, base64 格式的图像数据
|
| 19 |
+
:param gray: bool, 标记是否是灰度图
|
| 20 |
+
:param alpha: bool, 标记数据是否带有 alpha 通道
|
| 21 |
+
:return: ndarray 格式的图像数据
|
| 22 |
+
"""
|
| 23 |
+
if base64_img is None:
|
| 24 |
+
return None
|
| 25 |
+
img_b64decode = base64.b64decode(base64_img)
|
| 26 |
+
# np.fromstring 的二进制模式在 numpy>=1.22 已废弃、2.x 中移除, 改用 frombuffer
|
| 27 |
+
img_array = np.frombuffer(img_b64decode, np.uint8)
|
| 28 |
+
if gray:
|
| 29 |
+
trans_type = cv2.IMREAD_GRAYSCALE
|
| 30 |
+
elif alpha:
|
| 31 |
+
trans_type = -1
|
| 32 |
+
else:
|
| 33 |
+
trans_type = cv2.COLOR_BGR2RGB
|
| 34 |
+
img = cv2.imdecode(img_array, trans_type)
|
| 35 |
+
return img
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def mat_to_base64(img):
|
| 39 |
+
""" 数据 ndarray 转 base64
|
| 40 |
+
:param img: ndarray, ndarray 格式的图像数据
|
| 41 |
+
:return: base64 格式的图像数据
|
| 42 |
+
"""
|
| 43 |
+
if img is None:
|
| 44 |
+
return None
|
| 45 |
+
# ndarray.tostring() 在 numpy 2.x 中已移除, 改用等价的 tobytes()
|
| 46 |
+
image = cv2.imencode('.jpg', img)[1].tobytes()
|
| 47 |
+
base64_img = base64.b64encode(image).decode()
|
| 48 |
+
return base64_img
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def img_draw_rect(img, rect, draw_style=((0, 0, 255), 1)):
|
| 52 |
+
"""标记图像
|
| 53 |
+
:param img: ndarray, 图像
|
| 54 |
+
:param rect: x1, y1, x2, y2, 标记位置 (标准矩形框), 非标框 4 个点 8 维向量
|
| 55 |
+
:param draw_style: tuple, 绘制样式, 取值 DrawStyle, 包括颜色, 线条 size
|
| 56 |
+
:return: img, 标记后的图像
|
| 57 |
+
"""
|
| 58 |
+
if rect:
|
| 59 |
+
if len(rect) == 4:
|
| 60 |
+
x1, y1, x2, y2 = rect
|
| 61 |
+
cv2.rectangle(img, (x1, y1), (x2, y2), draw_style[0], draw_style[1])
|
| 62 |
+
|
| 63 |
+
if len(rect) == 8:
|
| 64 |
+
rect_array = np.array(rect)
|
| 65 |
+
rect_reshape = rect_array.reshape(-1, 2, 1)
|
| 66 |
+
cv2.polylines(img, [rect_reshape], isClosed=True, color=draw_style[0], thickness=draw_style[1]) # 红色多边形
|
| 67 |
+
|
| 68 |
+
return img
|
timi_hok_game_translator/LQA_WMP/lqa_service/common/util_network.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: util_network.py
|
| 4 |
+
# @desc: 网络请求响应处理工具模块, 提供统一的 HTTP 响应格式封装:
|
| 5 |
+
# - response: 构造统一结构的 JSON 响应体 (success/err_msg/result),
|
| 6 |
+
# 并支持通过 **args 追加自定义扩展字段, 最终以 Flask jsonify 返回
|
| 7 |
+
"""
|
| 8 |
+
from flask import jsonify
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def response(success=True, err_msg="", result=None, **args):
|
| 12 |
+
""" 网络请求response消息处理
|
| 13 |
+
:param success: bool, http 相应码
|
| 14 |
+
:param err_msg: str, 错误消息
|
| 15 |
+
:param result: 结果数据
|
| 16 |
+
:param args: dict, 其他补充内容
|
| 17 |
+
:return: response 数据
|
| 18 |
+
"""
|
| 19 |
+
ret = {
|
| 20 |
+
"success": success,
|
| 21 |
+
"err_msg": err_msg,
|
| 22 |
+
"result": result
|
| 23 |
+
}
|
| 24 |
+
ret.update(args)
|
| 25 |
+
return jsonify(ret)
|
timi_hok_game_translator/LQA_WMP/lqa_service/config/baseconfig.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: baseconfig.py
|
| 4 |
+
# @desc: LQA 服务基础配置模块, 包含调试模式开关 (DEBUG_MODE)、
|
| 5 |
+
# OCR 服务接入配置 (支持 rapidocr/paddleocr/tesseract/tencentcloud/baidu/azure 等多种 provider)、
|
| 6 |
+
# 以及 LQA 检测所需的未译/错译标记和中文简繁体字符集等常量配置
|
| 7 |
+
"""
|
| 8 |
+
import os
|
| 9 |
+
import json
|
| 10 |
+
|
| 11 |
+
DEBUG_MODE = os.getenv("DEBUG_MODE", 'True').upper() == "TRUE"
|
| 12 |
+
|
| 13 |
+
# OCR 服务配置 (OCR 为可选能力)
|
| 14 |
+
# OCR_PROVIDER 可选: rapidocr (默认, 开源离线) / paddleocr / paddleocr_http / easyocr /
|
| 15 |
+
# tesseract / tencentcloud / baidu / azure / cvtest (自建) /
|
| 16 |
+
# none (显式关闭)
|
| 17 |
+
# 留空或设为 none 时不进行任何 OCR 调用, 服务仍可启动并完成不依赖 OCR 的检测
|
| 18 |
+
OCR_PROVIDER = os.getenv("OCR_PROVIDER", "rapidocr")
|
| 19 |
+
OCR_HOST = os.getenv("OCR_HOST", "")
|
| 20 |
+
OCR_URL = os.getenv("OCR_URL", f"{OCR_HOST}/image/general/ocr/uiflow/" if OCR_HOST else "")
|
| 21 |
+
OCR_LANG = os.getenv("OCR_LANG", "ch")
|
| 22 |
+
OCR_TIMEOUT = int(os.getenv("OCR_TIMEOUT", "60"))
|
| 23 |
+
OCR_USE_GPU = os.getenv("OCR_USE_GPU", "false")
|
| 24 |
+
# 云厂商 / 自建服务鉴权
|
| 25 |
+
OCR_API_KEY = os.getenv("OCR_API_KEY", "")
|
| 26 |
+
OCR_SECRET_ID = os.getenv("OCR_SECRET_ID", "")
|
| 27 |
+
OCR_SECRET_KEY = os.getenv("OCR_SECRET_KEY", "")
|
| 28 |
+
OCR_REGION = os.getenv("OCR_REGION", "ap-guangzhou")
|
| 29 |
+
# tesseract 可执行文件路径 (未加入 PATH 时需指定)
|
| 30 |
+
OCR_TESSERACT_CMD = os.getenv("OCR_TESSERACT_CMD", "")
|
| 31 |
+
# cvtest 专用
|
| 32 |
+
OCR_PROJECT_ID = int(os.getenv("OCR_PROJECT_ID", "19998"))
|
| 33 |
+
OCR_DEFAULT_PROJECT = os.getenv("OCR_DEFAULT_PROJECT", "")
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def ocr_provider_config():
|
| 37 |
+
"""汇总 OCR provider 所需配置"""
|
| 38 |
+
return {
|
| 39 |
+
"url": OCR_URL,
|
| 40 |
+
"host": OCR_HOST,
|
| 41 |
+
"lang": OCR_LANG,
|
| 42 |
+
"timeout": OCR_TIMEOUT,
|
| 43 |
+
"use_gpu": OCR_USE_GPU,
|
| 44 |
+
"api_key": OCR_API_KEY,
|
| 45 |
+
"secret_id": OCR_SECRET_ID,
|
| 46 |
+
"secret_key": OCR_SECRET_KEY,
|
| 47 |
+
"region": OCR_REGION,
|
| 48 |
+
"tesseract_cmd": OCR_TESSERACT_CMD,
|
| 49 |
+
"project_id": OCR_PROJECT_ID,
|
| 50 |
+
"default_project": OCR_DEFAULT_PROJECT,
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
# LQA 识别相关配置
|
| 54 |
+
NO_TRANS_MARK = os.getenv("NO_TRANS_MARK", "##")
|
| 55 |
+
NO_TRANS_MARK_LIST = json.loads(os.getenv("NO_TRANS_MARK_LIST", '["##", "#N", "WWWW", "N/A"]'))
|
| 56 |
+
ERROR_TRANS_MARK_LIST = json.loads(os.getenv("ERROR_TRANS_MARK_LIST", '["</",["color", "#"]]'))
|
| 57 |
+
NON_PROBLEM_MARK = os.getenv("NO_PROBLEM_MARK", "__nonProblem")
|
| 58 |
+
SIMPLIFIED_CHINESE = ('耀挂怀涉谈邋伊随茂抗脖料蜚亟洞造瞥瘤般蚯作河欲侵临犷然吸场宽线捂反牌盏科噢嚏拗庸若窗话爻赞凡瓣卢知除巩惫罪揭扬'
|
| 59 |
+
'衰泳狷其闹呸驼绿渔愁萃掂暄覆匍湃引应枚灵踟儡滤假胆崩鲨循芬是械讲刷冶咸贞鸿胀琉橇视俊契寒录绔酸教跻也睥囤秦峨捭'
|
| 60 |
+
'括景诲滴凶铸须基孽广巾漪僧沉上后频餐底缔默蒙攘键辟厄跚岩芭茬枯惜椰足亵伴痒妈甸离笼羿尾胁灿框泉凋罩壑绕槛虚迟嗣'
|
| 61 |
+
'牢坤拭跳轴号偶啸移忿态膀节构消厌堑馐媒帕悖褛伟逡冠颦渝愫纪掬术澜踵吹稽精拂柄歇汉珍克今前双坏铎塑姐幕翔胖匾湍泞'
|
| 62 |
+
'几镣巨绪扭杯筒卷妨固导齿骁脂萄辉丈再侃霎库砂尔挖邮沟伞删嚣碧符篝披爆躲涵水嗒眈瘸禽菁所旅摄么勋浊重灌坎篑结渎贻'
|
| 63 |
+
'噤澈学翩臭恬诱倒践培秽胫持技彪标殆班越笑妒耗掖辞加嘣冢甥缩纨悬贵霹稻簿晃懂故蓄识免辣城筑痹秒荏蝙江连卡狠略铤彩'
|
| 64 |
+
'扫惬赵偷叶睹相驻闺好箫屿忾螃怂钦媚争梭王谊傍吃疏阎骑崔或蜘趟踞务花垣逢钥唤缨莫妆斯澳贴冷制霸礼牧徊擅舷友煌子糕'
|
| 65 |
+
'曙毛玻跟狡占遢哥啤绩躏惭普俳殒浴盹缕寻饼掀蜃搅薄三辈倍册嚎鼓桂抖昙糅榜负圣疤大窦鸩徨挫憬支骜樱记趴状诋扁权肠义'
|
| 66 |
+
'迈瓶遍里畏盎寐当飒展鲁拖湎滞珠督嗤捐荫恭蛮橱佳聒具铺顽肃蜂躇嘀栈咋鞍抬墓宕稔暗沛挚依东那判座妩枭段嚷逸区羽帼社'
|
| 67 |
+
'旁嫡胃杂爷仇浆觉案陌煎飓归蒸聘泛罢保楞嗡面句继秩傀拯腮深汰裳轲诵雷镶凹系忽幼竿叵考茅抄万殊霍睛岐徒噩肘氛溜锡拱'
|
| 68 |
+
'瀣垢猥帧天墨石贱敕珊炸玺聋稿蕴恃捅跆诊坍野忒孕旖佝蔫啡铠遣矢勤左磨葫良泰陷兹罕类综穿滔攀昂茄辇喋鎏颂悯林氅涛戚'
|
| 69 |
+
'唠墩筝雏本兀串琶点刺纽宿砾担过豆棉雍偎湿姓答爸踊靥潜诟院忧票婪泱走蹲烹典牺绽彼寿顾搁暂沆锋瞌炎少朗耙洛抚丝辜弧'
|
| 70 |
+
'馨攫昭振农谱亲殴眷刽帽碾摁揄潇览降协郎屑绒蝗礴恙赛九远俑酣团剥古峦柬药惮煦仲说坷银勺幽翼极漆同猎帐馕研艘战些脚'
|
| 71 |
+
'谜瘠劣锢冥弦太断搬肯辱丰洲眶券麻尼渊但诉像华忑踹髓塔杖托距碑燥饪葬惯据俱买瓷靶叹鱼签蚀悄辆怖和透弑庐夕胯妄折丛'
|
| 72 |
+
'贝忱鹰骨撬怯液匹犸粼宾蛀胄汇歉陋觊偏网麦著拘湛黎诞睡因入烤孩虫蓬息仰韶狸幻出顿蚁最搂誉型熏蹙斗翘芙供眠琢傥带笨'
|
| 73 |
+
'枫堪播蔬戮估讳谲梵褴喷阶犹庵债杀情获埋响界减绑齐寓壕奔旗晖拙进聚妻槟靠口呢巧嫩拦敬扮轰汲棵闷陶卸翻蜉姿驾酵烁范'
|
| 74 |
+
'蒂者了看名徐粒堕暖掘诶肚垠匣钢寇紧约末搭踱辰唷隶爹鼻尽痴擂饷浇仆拍毫忐硕委佛惚汝襟陡遥凤寨乱述零特司彻盾饿要沃'
|
| 75 |
+
'辅脆浏箍序崎逐钓阔会晚焦吨被训溯孜醉挲尸傻强弓唾见血猊迅蹄苇腆藉磋经金遐遏卒毯翠悲蛟敞鹤琐周语浮恰晴饶僻囿调验'
|
| 76 |
+
'妙吓痂隔挝芜星颠客弥纤甩咨鸭瞪鸷淳港脱莲朵暴稷岸逻阿疾襁检膨扇蕉蟊嫌鹏兑囔畸拜齑剧哨衫惰菲杵更穷偻狼黏梁老猪溅'
|
| 77 |
+
'怆馋窍划栖沙膛业茜搞缤倦钩用瘪侯氮蜴窄粹冻吾裁坡跃仅康菇聆蓉效始忏哀嗓雕诗酥咻摞奠糙陪譬俯蘼腰色蝴篷顶击矿瑾喘'
|
| 78 |
+
'清辄指肆蚊稍完式瀑犒袖谙诅亚期撞堡鸥群邦吩诛伯沮昵爽倡久俄熠奋蛊富遑勒埔淘滚菜束卧烦门压诬软违眺柴壶屹养建睿链'
|
| 79 |
+
'殁言溃超谄骋妍砌鼎塘辙丘抛撮膝怜管稠纣尤垄莱舰拟常冽值霾证淅荆立种塌发剐酒痕这乘招赚寡绣奢工烧卦矩器番衬泯轮扰'
|
| 80 |
+
'曳磷幸狻函灼铿七概饭有俭程复碌小美冒咔栗殖伙亘戛辛骠鸣瀚鲤眩胳嘶家弹纸刻炼乃观浅泄蝉屏翎卑狐街余付扛哎胜章另革'
|
| 81 |
+
'雨闪修捱役绸兽较獗舆月宋碍唬匐递咕唔优睐骄笠囚在琪袭涯踮抱脉螳氲撵鬼娶纹缸去尺炽椴促掊资图摊畔仙潘豚虞愚璐睨诫'
|
| 82 |
+
'路湮英柳垒膂整究都兼百倏谅趄址砍刑霓炒吕喔辘瓮思膜宠濡瘩咪贯亮舱掰育舟夷羸医难酋诀裂荷拆筋惶绎剑靓瑕量乙还扎焚'
|
| 83 |
+
'黑履照罐险烽哐哪篓杳锵葵祷磕琵长雾趁漂暇弭希骏躬疑吐枝唱恚锦倨沫匪戴纷妹砸钻笺势紊毅橄蛇坠峋忍奎呐青剔仗赖苟巡'
|
| 84 |
+
'屠形寥啦遨鞋蹦迭蹬想廷矽噼勿洁愉哭猖咐瞒匕渗朝戟锚骤储京撰耳茵肮帷夹吻嚼饴流桃迂嗷荧屋铐道单棘葛诚曜畜嗦酩部豫'
|
| 85 |
+
'只们侩恳她盼剿沁嘁贪肉愈宏唐撂辗蜜素鸢窥瞧否爪亭眨讯抵德夸喻隽眼逾蹂炷摆慈绍衣哑脏俗裙曝杜峡姣幢童孤韧呦全淫剪'
|
| 86 |
+
'佬误数至祸闻空国逼灾谁把後碎向众嗅果挟红娥室咦倩贫努中新舵蹈锻匿汁淀赊评鞠懈潦忌风盒叔敛蝎柜损胞屡哦赫度蹭廓森'
|
| 87 |
+
'葱曲援彷项莉白一撇掉戈脊阐姻冕倔搜悟挞御索妥堤咧玩身吆蛾梯悉芳容夺喽吼猾迁觅男杆揉扈腊巍限兢燕毙橘蛛楚惟忡哧坦'
|
| 88 |
+
'叩警柱晰拳敲懵对饺嗽呼企涂椅袄按芈膊岌隐哂焕辖凄纠夥颤吧猩动丫购议朱戳诈骸阻什摇草懊坑踢汗霉巢奥壤俐琦蛰扳慵筹'
|
| 89 |
+
'登哼偿躁茁殃航梅文抉律鲍福税皑匮世舞纡张宣胚喧瘦助贬嘲予瞻砺咽猴仁颓求装拉聊嵌监坐兔跗乖健蓝赧狩迫杰巷并竹顺啼'
|
| 90 |
+
'凿丁貂榄孔授弋夏咒熔洗望萝斜感鸡砥唧利厨漫邪谭悚厢蒲怵庶疼儿蹁激歃衅规馁蛆扉黍惊籍奏卓哒诏他橙诘佻幡忠季秤啧物'
|
| 91 |
+
'叨淬弩晒致延穹寸磺命酿勾退璃瞅骇肋弊舌炬辕且疙宝娜废怠涩谨炫伪爬售砰岳徵方机讽派铃附屈惋揍觑桐乔狗员坚寝统换查'
|
| 92 |
+
'晤烫叭盯藐念年拷摸诽仿莺鲸邀球厂的娇馆羊昏转谓臂五列错窜鸟悠探蜥犬疮失碰户改撸螺趾允呃参雄姆配恋捍拌虏旎毒何仔'
|
| 93 |
+
'奸留侥孝州惠董来触浩注火迪独问饱声米维蹿喃隅霄宇堆粉憋萎褐井演咙甘窝龟股质个钳纵缴掷榻便阴郁捡剂雅篇渍鹊苍受啥'
|
| 94 |
+
'邻翟属胡缺诧狭饰绵皿恶智歼送冀阅瞄领尉床舍掌树北翅宜弟怡孱抢春拇欧梦谩涨溪钮媲沾遁净啃狂际母绊才菌杏擎桑鸦浓亢'
|
| 95 |
+
'返南瑙赎鳞凑散拢歧跨八仪召哮称捷胶摹使刀各颇徉师祖而褒气化嘘媛甚偌锄吱斥萤梧薰辩丨劫洪咯剜箱纳尴茶格沿病窒职李'
|
| 96 |
+
'译仓卖画糟握慢日武往浪凭驰绳饲猿捶蟹槽犀锅堇缉肌搏檐专逗隘疚颜羞挡攥撤漩亨别催启垮妲涟耷跋测达十畅哄密终手奶背'
|
| 97 |
+
'翌跹乓角遗取静盘祝轶锤荡详佩跪六烬矮筱平揶旺犁垃适甄妇娆弈尊悍明输冗刖隙宛额夜抡挠玫氪炭疯崴携举污埃遂啄婆廉父'
|
| 98 |
+
'慌族虎法赔眸瑚恢皆珂滩轨叫豪热公闯聩翳扶曹读楼湾刁��善备很妖耍硫漓谕趔鞘笛咚庞掠肢营温辨猫穆冬唯皮娱宰盲嘟翡栽'
|
| 99 |
+
'珀届奇糊恍敏体棒藏酗缥筛姜绞蝣藤蹩俨卫泪灭镯目驱寰巴瑜璨虹死羁邃厅庇剖融昌谐写岛莞帜窟斡患接产账咫霆鞭犯玉玲宵'
|
| 100 |
+
'娴收耸治挺辽奈荣织獠秉遭苏慎跑汐毕盗镖博忝耻竟神浦表歪短噬煮己壳署嘿恸泻捺追蹼途锁璀逃垂包瓦颈服戏酬沐嗯鄙厚缝'
|
| 101 |
+
'府组蔡枢挥护丧润梨含圭悸掺赴羡狄渠奉浑濒噗络慑钧副峰孵晷时腹胸乾载享盔销将斋掏怎炙刚报挤侧谦疫横环逮嬴枷侈脸呕'
|
| 102 |
+
'似访铁燃祈旋描赐蹒烙皎绝察塞臣示拥荤姑疽园缓可遮干惹添艺份佼吁喀玄馈民褓互咖候崛靡帝徜增酱愣沦栩榨甫嘭瞬炮就纲'
|
| 103 |
+
'宴蜷活丽滋围元刹俩捏胎比块孟飞葡无轧桩韬山踩女婵侨茫阀内蓦安萌茎辑渐誓洒榕锯刘暮盛墟缄映沧伦让褪听噌献破莹踪款'
|
| 104 |
+
'陀勃蛋捎近乐衔靖叙党川食锐敢恤车诩睦闭棺翱级戒蝶任孑省刃喂涸宗簇嬉莎休源烂吗匙帛鲜实蜡痨肤谧侦瘫咬厮弱稳碴架主'
|
| 105 |
+
'吞洽沼设睁雀剃泊充忆等晋姊凌佑裔呗糜寞条扣既腥迦癫灯叮影绰驳已饵泼课需帆笈戎云伐嶂疗阖通粝掣肥愤涧垫株甬刮纱缰'
|
| 106 |
+
'害头抹茸仞绷朴雁着兄叠嫉操敌沌滑佐裕楔癖狙做鼠蝠揣渺书芽矫铭啬凯彰奴旷晶苹杠泽阁壁僭逅熄崇庆豁守朋颊意丑辐蠕则'
|
| 107 |
+
'厘尝够挣急货亦讨吭粲堵借蔷船肺秋千铂酷细婉拎运俘盖牙变僚祟竞柠捣贼桀狮页敷批轻惺汽西禁待毗喉合袋亏膑耐觐枕昔骗'
|
| 108 |
+
'外嶙尘渴缚欢煽两斩萨未箭纯咳嘴褶永悻伺莽放私础魂必幄勇兆呈棋坊词济懑恐荒虔奖滥烛罚嘻盟穴泣止迥拧早士马绯絮灰韵'
|
| 109 |
+
'淹潺揽扼替蕾礁噪缅庄切针栋踏涎脑熙搓排蜕首粘瀛羚猝琼队谣订交慰枪捉琳牲费沸总挽押寂罅黄片准皙哈乏腑插穗遛睑询令'
|
| 110 |
+
'执懦填差共味史直腕俺拼颁弄率逆钉锈谎斓舒蚕朔算砖军劝猜瞟径趣亥伤控撩匠第羯瓜焰殷油贸为抽磁祀绅哉歌俏惑腐扒漏峙'
|
| 111 |
+
'饥凛卜域瑞以徽韦竭兰割靴请桶浸臻拽荼码禀骂帅龄呀吉伏蔓芒颖初真校责严茧悦夫艳弯粮冰申劲阵土趸人蜿秀幅升囊住晌拒'
|
| 112 |
+
'晕柔字渥绚坟衡淑找捧惦摩旨驭凰躯陵避袅汹试腻板宁稀射匆阈伎成蚓碗龙帘力缀倜钟霞计薇昨缠唳到疵琴边游贺怼练奂巅桥'
|
| 113 |
+
'啊行低摔策忙凝停哟非诡代躺汤惧晨赦硬糯置雳蹰迹慷恼松布如历眉喊植澎挑易鹅创兮吟迄次渣败性钝薪缈微阳冲电钴样讶悼'
|
| 114 |
+
'婴魁益遇漠盈痊迎拐晓懒舐绘牛酝峻瑟澄蛙祭屯危狰衷茨突堂醇分圈残吊袍与抑螓怒撕庙缘玛尚喟嘞欠侣蠢沥贤憧木宫帮励瞳'
|
| 115 |
+
'钵伸显嫁心汪采毋告棍乎荐染恒姗给叛憎兜泥赤杨狱印音畴嗨潸能虾威简弃雪嘉逍于我掐佯窖徘猛岚逝谛生模梢涤愧芦镳累爱'
|
| 116 |
+
'现傲吵丹耽政葆居咀衍槌赏从扑提套竖忘釜回诠佣淤慧苦姬绮台呵间迸捻曾境异宅皇冉湖侍斑搐蜒舔店崖香涅咛功涡暧憩怨挪'
|
| 117 |
+
'央炳露嘈核欺昼抿脾局雇商凉半乌扔邸蔚铛噜募煞淡池玷该敦恨端饮瑰籁鉴价赶拿腾恪颗疆焉谋伍二蔑徙夙题君定障贡瘟昧蝰'
|
| 118 |
+
'您熬措缭妮由霁论朽房憾审光烈及位觎救蟒捕拔飘呛燎氤档步旦惨揪驯瞩卵裸戍诺曼承臾岁妃市理炉趋刊撑槐投得尖墙稚霜原'
|
| 119 |
+
'逞没瞠丢萦肩截庭钱田决防祥谶喵吴秃魄呆先淋削仍每桎锥志丸飙痛婚尿泡赠解此惩慨巫续确镰凳陲却迷汶裹耕圾蝼封毁娅震'
|
| 120 |
+
'咆选冈洋不斐脓扯弗岖骚溢认憨紫捆席郑爵陈根筵攻溺屁寄均摘赋乍桌鹿罗糖秘矜象珑楣豹擦恩冤璧鹭壮关殿牵虽伫征窃禅圆'
|
| 121 |
+
'厉事梏抓攒怔粗编宙娘多喝苛澡嘱财朦掩尬劳甲况伶施肿翁哇叉版介酊虐拓联四嗝呜烟信习赢胧菩绫筮韩陨笔娃啪预劈下熊貌'
|
| 122 |
+
'栏愕悔笙窘嘛潮速袤萧艰倾盆崭疲谷蔽撼耿狈之释淌村打慕忖孙高陛铜裤摧倚拨鹫自篮困闲兵歹开它颅处喇匈例逊暑莓帖砚苗'
|
| 123 |
+
'甜熟亡传谢斧挨怪岭皱地渲蔼戾层磅奄症陆勉午赌材驶惕腔站存矛辎镜廊满你诣豢旧晦择快聪峭积驮剩右醒僵兴混懿艾币品笃'
|
| 124 |
+
'岂禄唇隆谍涌咱蘑析撒怕官颚吝喜办渡侠欣推夯阱瞰铲贷溶许落於愿繁海镇集又郊跌虑某擒恕津坛嗜狞乡正波补曦扩即哲遵起'
|
| 125 |
+
'件诸拾腿魔')
|
| 126 |
+
TRADITIONAL_CHINESE = ('誇預錢礦黝踴銷鐸談豈織軟遠綺緩歲個謝丟無禦氳殲鈷頻骼運鋌嗎饑衛諜蹟鑣鏢盤併剷斃贈劍鞏經馱閣鴨憫媽簾釋湊呎奐聖'
|
| 127 |
+
'敘譜濟寧絨繪該堅詫鈍頑訝貞鬧鰩脫蠱課皺蟄車睏駐髒轟賞勢編慫蓮迴獷彿糾戀贊鮑纓餒錯閥義褲傷猶鼾凍瓏饒鏡牠難詰襲'
|
| 128 |
+
'淵陸嫻攔憂載莖誰覲貴隸碼毆轉剋絕詛補陣顧實黨摯賴遷飼躉頒純舖條鐺綿績詆佈兌漸裝婦菫諱議飽幾會複階講撚亞傢羨許'
|
| 129 |
+
'渟麾鍋賊問巔據衝奧髦繩繽話棲噹謊弒撫漲訴夾壓齒闡鑠鉤給慮當選繼變圍頓輝連風農缽麼習體揚機灣鋤曬開訊紐搖溝輜碩'
|
| 130 |
+
'館吶綻爺擁時瑣過結叢慘員釣癢綽華執價緻掄嘍餓麒別蘭鴻總佇韌驕臘痠離蟬滲鹽飾計邏徑掙梟產暫礪萬澱檳嶽資轆雋楊烏'
|
| 131 |
+
'獎駕慚棟噠畢糧審奪濱篩諳斂脅來瘋瀏搗減憚蠟殞禪蔭絲證緒饕賜闢煥蕭擬聯揮詳極鋸掃肅貝樞窩澆攬雞禿慄韋濛詞盡僥樓'
|
| 132 |
+
'潰狹獸遺峽駿國龐輛語瘡膚斬為簽嶼幹敗曖艙潛獻癡哢穩鯨飪長潔謂纏冑嘔趙鬢犧茲骷襖詬滯聰捲鷹鏽與鬍託視簣騷紹閾轅'
|
| 133 |
+
'滄筍號寢燦湯巒祕鋼訂蘊嬌導傑間嚕夠麥鎧辯戲犽滅轄恆爍僑緣穢諭惱狽響們愛躚帥閨險設輯臉鷲颶儻觀諂葉饋積齏灑釐鋒'
|
| 134 |
+
'勸汙懺瑩盪詭牽禍頌爐欖悅夢錦戰徹眾惇嫋姍題彎兒廣籤漿翹遼暈甕讖隨喪嶺噓燒淚摟幣橫並業懲敵擴寶鷺鑿謀暉箋萊餌劑'
|
| 135 |
+
'錐亙掛愜蘇鄉儼濃懇曉韓換鳥撐靨瑪聲腫樁讀較嬋圓覬縹毀晉擊額鉑闔論濘壢內艱競鹹卻災燼攆龍礎閑鐐園贖甦貫辭測檯頸'
|
| 136 |
+
'曇應荊髏譚虜籠盧發昇尋莊續讚鬥闆榮縷霽熾賀係滌絡兩復聳蟲誅欄脈舊澗岡刪漬雜閻瀾況槃緋彌顎癒動協聞擱煩亂紋鈕沖'
|
| 137 |
+
'簡綠霧擰強頹鍵窺瞼傾晝締廢篤適鋪譯腳罷鳶塹陽埼興記窣頤溫優隻濁櫃擇籌達藝絢豬電鑼鍾漁憊納嚐閒謙誘攝綢鞦責簷窸'
|
| 138 |
+
'軀棄顏噸虛齡黠賬東現蘆騎攜錨暱愴帶爾穎囑鑒僕識臟屢獨濫賭詮學韻澀舉對瀕準標殘鬣撲確曆菈屍違慟繡偽襯諮擲聵壺鑽'
|
| 139 |
+
'專貓鐘麟輪厭靜禱頰証釁竇鱈齊賓濕飛靚廟絞諧淩顰鳳慶藹滿鴉輕萣覦洩貨倫銬嘯單張憶蠻欽誼鉗顛矚幟罵艷懶譽邁儀閃順'
|
| 140 |
+
'紈躕輔倖販醫鐮颱瀉麵顆佔鏗駛惡矯數誒皚膠趨躪爭報紳悶褻殼輿釀飆態諒淨顱鬆縈趕妝採騰檻覽貿輾盃鑄壇筆繈拋詐豔駝'
|
| 141 |
+
'藥棧燭廳櫻銀鎖娛喚墜從蔥輩鄭鬱骰帳註狀緊鏖嗚籟淪繳鳴職書濾唄謐團撥攤傭嘮嬰砲戶渾勁區彈歐雙繞試懷製羈攏樑崙輓'
|
| 142 |
+
'搥誦貪醬嚮稱綴僂祇島點諦質飲練擺滾鴆須輒瞭綱颳費調靂絆擋豐詔燙灘饞寵繹餉檔嘗傘稟螢脹獅鯊術闖煙驟擠湧壽統軼銅'
|
| 143 |
+
'錄覓誕備儘訪細馳搶療獄屆饈廝類懣嫵腸門監這紛龜暢說匯囂鉅竊楓評遙釘歎壞慣賦畫懸歿劃養踐樂圖攢貧瀆錮場鶴韁築藍'
|
| 144 |
+
'黛緝壟臥鵲隕嚀還將蘋訓飯猙銘縛辦誨親鎮網貼潑淒鵝曠緲飴葷臺購桿嶇嬈讓嘖錘渦斷貽參呂僅塊務剮罰籲賽墊損沒綜憤喬'
|
| 145 |
+
'縱馴輻涼噁燄訣賒雖鏘恥詩糲塵縫諾羅劇閉憑撓鮮薩紆紮熱駁權尷鷙啞賣蹤腦黯凱獲噴諷誌紙銜氣吳厲嚴貸蘿籃則蝕驗癟蕩'
|
| 146 |
+
'顫坵濺倆見認躥墳鄰蠶廠構豎繚勝裡詢潤僱蹺幫頁隊憐硯脛檢澤礫週蓋撾處緘廚剝濤寬護擾斕級攪馭儲膽撿驀黃祂請槍勛針'
|
| 147 |
+
'遜睞蕪駭紅疊頗爛瞞誠匱繃驍橋闊擔塗彙剛線歡蹣賤穫陳軸淺頂約蔔誡謠鶯縮進覷輸組牆囉靈艦寫獰遲決騁嶄蠍贏薔瀝醜漣'
|
| 148 |
+
'闇頭馬鐵驁節歷兇饗鍛凜啟盞詡孫賺聽懼綁嚇薑麗領鬚漢膩骯餮閱傳鈴洶愾鍊願魚跡奮鑰慾崁儉蒐礙醞負誤薦簫禮環殺魅竄'
|
| 149 |
+
'嗆煉轍軌幗壘盜賠虧廬獵摻懾紀儈躍餘財鼬褸診莿竅軍驚睜遞櫥葦異癲勵聾餃稅崗倉劊朧墮貶廂驅範偉燈韜臨繭魯雲創觸躋'
|
| 150 |
+
'謎際誣庫維颯銳買樸挾幀終軋譎雛層蝦屬壯陰勳側蛻餅冊瀟樣師宮喲侶謹檸覺蒼飄韆鱗詣繫顯諸擼疇嘆規討鈞妳種隱鐲債誹'
|
| 151 |
+
'螻膿嗇遊鷗魘塚營襤捨鑲郵歸蟻項邊紗纖騙償貢鰭窮樹鏈磚關勞俠賢嵐緬髮癱偵嚨嚙')
|
| 152 |
+
SIMPLIFIED_CHINESE_SET = set(list(SIMPLIFIED_CHINESE.replace(" ", "")))
|
| 153 |
+
TRADITIONAL_CHINESE_SET = set(list(TRADITIONAL_CHINESE.replace(" ", "")))
|
timi_hok_game_translator/LQA_WMP/lqa_service/config/gunicorn_config.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: gunicorn_config.py
|
| 4 |
+
# @desc: Gunicorn WSGI 服务器配置文件, 用于配置 lqa_service 的启动参数, 包括:
|
| 5 |
+
# - bind: 服务监听地址及端口 (默认 0.0.0.0:8086)
|
| 6 |
+
# - worker_class: worker 工作模式 (默认 gevent 协程模式)
|
| 7 |
+
# - timeout: 请求处理超时时间, 单位秒 (默认 120)
|
| 8 |
+
# - workers: worker 进程数量 (默认 3, 可通过环境变量 GUNICORN_WORKERS 调整)
|
| 9 |
+
# - accesslog/errorlog: 访问日志与错误日志文件路径
|
| 10 |
+
# - loglevel: 日志级别 (默认 info)
|
| 11 |
+
"""
|
| 12 |
+
import os
|
| 13 |
+
|
| 14 |
+
bind = os.getenv("BIND", '0.0.0.0:8086')
|
| 15 |
+
worker_class = os.getenv("WORK_CLASS", "gevent")
|
| 16 |
+
# 注意: 此处历史上误用了 BIND 变量, 设置 BIND 后会导致 int() 解析失败
|
| 17 |
+
timeout = int(os.getenv("TIMEOUT", 120))
|
| 18 |
+
|
| 19 |
+
# os.cpu_count()
|
| 20 |
+
workers = int(os.getenv("GUNICORN_WORKERS", 3))
|
| 21 |
+
accesslog = os.getenv("ACCESSLOG", "gunicirn_access.log")
|
| 22 |
+
errorlog = os.getenv("ERRORLOG", "gunicirn_error.log")
|
| 23 |
+
loglevel = os.getenv("LOGLEVEL", "info")
|
timi_hok_game_translator/LQA_WMP/lqa_service/deploy/run_gunicorn.sh
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
export LANG="zh_CN.UTF-8"
|
| 3 |
+
|
| 4 |
+
#cd /data/lqa/
|
| 5 |
+
gunicorn -c config/gunicorn_config.py portal:app --preload
|
timi_hok_game_translator/LQA_WMP/lqa_service/handles/handle_lqa.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: handle_lqa.py
|
| 4 |
+
# @desc: LQA 服务相关 HTTP 接口 (Blueprint: app_lqa), 提供以下能力:
|
| 5 |
+
# - GET /health 健康检查接口, 供容器编排探活使用, 并返回 OCR 可用状态
|
| 6 |
+
# - POST /image/lqa_check/ 图像本地化异常 (LQA) 检测接口, 支持 OCR 识别定位和已知坐标两种模式,
|
| 7 |
+
# 可识别未译、错译等问题, 并支持与历史检测结果比对 (supervised)
|
| 8 |
+
# - POST /image/image_extraction/ 图像前景提取接口, 用于从截图中提取前景/文本区域
|
| 9 |
+
"""
|
| 10 |
+
import time
|
| 11 |
+
import json
|
| 12 |
+
import traceback
|
| 13 |
+
from flask import Blueprint, request
|
| 14 |
+
from common.log import logger
|
| 15 |
+
from common.interface_ocr import ocr_available
|
| 16 |
+
from task.lqa import ImageLqa
|
| 17 |
+
from task.image_processing import ImageProcessing
|
| 18 |
+
|
| 19 |
+
app_lqa = Blueprint('app_lqa', __name__)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
# 健康检查 (供容器编排探活使用)
|
| 23 |
+
# OCR 是可选能力, 不可用时服务依然健康 (返回 200), 仅在 ocr 字段中体现,
|
| 24 |
+
# 便于运维确认当前是否处于降级检测状态
|
| 25 |
+
@app_lqa.route("/health", methods=["GET"])
|
| 26 |
+
def health():
|
| 27 |
+
try:
|
| 28 |
+
available, message = ocr_available()
|
| 29 |
+
except Exception as ex: # pylint: disable=broad-except
|
| 30 |
+
available, message = False, str(ex)
|
| 31 |
+
return json.dumps({
|
| 32 |
+
"status": "ok",
|
| 33 |
+
"ocr": {
|
| 34 |
+
"available": available,
|
| 35 |
+
"message": message,
|
| 36 |
+
"degraded": not available,
|
| 37 |
+
},
|
| 38 |
+
}, ensure_ascii=False)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
# lqa 本地化异常检测服务接口
|
| 42 |
+
@app_lqa.route("/image/lqa_check/", methods=["POST"])
|
| 43 |
+
def image_lqa():
|
| 44 |
+
t0 = time.time()
|
| 45 |
+
resp = {
|
| 46 |
+
"success": False,
|
| 47 |
+
"err_msg": None,
|
| 48 |
+
"result": {}
|
| 49 |
+
}
|
| 50 |
+
try:
|
| 51 |
+
project = None
|
| 52 |
+
headers = request.headers.get("project-method", None)
|
| 53 |
+
if headers is not None:
|
| 54 |
+
project = headers.split('_lqa')[0]
|
| 55 |
+
arguments = request.get_json()
|
| 56 |
+
if not arguments:
|
| 57 |
+
resp["err_msg"] = "body is None!"
|
| 58 |
+
return
|
| 59 |
+
img_base64 = arguments.get("img_base64", None)
|
| 60 |
+
rect_locations = arguments.get("rect_locations", None)
|
| 61 |
+
language = arguments.get("language", None)
|
| 62 |
+
supervised = arguments.get("supervised", None)
|
| 63 |
+
check_type = arguments.get("check_type", None)
|
| 64 |
+
history_img_base64 = arguments.get("history_img_base64", None)
|
| 65 |
+
history_result = arguments.get("history_result", None)
|
| 66 |
+
no_trans_marks = arguments.get("no_trans_marks", None)
|
| 67 |
+
error_trans_marks = arguments.get("error_trans_marks", None)
|
| 68 |
+
ocr_detect = arguments.get("ocr_detect", 1)
|
| 69 |
+
if img_base64 is None or rect_locations is None:
|
| 70 |
+
resp["err_msg"] = "img is None!"
|
| 71 |
+
return
|
| 72 |
+
if ocr_detect == 1: # 文本非精准位置, 需要 ocr 识别
|
| 73 |
+
res = ImageLqa.lqa_check(img_base64, rect_locations, language, supervised, check_type,
|
| 74 |
+
history_img_base64, history_result, project, no_trans_marks, error_trans_marks)
|
| 75 |
+
else: # 文本框已经是文本实际最小外接矩, 不需要识别
|
| 76 |
+
res = ImageLqa.lqa_check_no_ocr(img_base64, rect_locations, language, supervised, check_type,
|
| 77 |
+
history_img_base64, history_result, project, no_trans_marks, error_trans_marks)
|
| 78 |
+
|
| 79 |
+
resp["success"] = True
|
| 80 |
+
resp["result"] = res
|
| 81 |
+
except Exception as ex: # pylint: disable=broad-except
|
| 82 |
+
logger.error(traceback.format_exc())
|
| 83 |
+
resp["err_msg"] = str(ex)
|
| 84 |
+
finally:
|
| 85 |
+
t3 = time.time()
|
| 86 |
+
logger.info("request costs %ss" % str(t3 - t0))
|
| 87 |
+
return json.dumps(resp)
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
# 图像前景提取服务接口
|
| 91 |
+
@app_lqa.route("/image/image_extraction/", methods=["POST"])
|
| 92 |
+
def image_extraction():
|
| 93 |
+
t0 = time.time()
|
| 94 |
+
resp = {
|
| 95 |
+
"success": False,
|
| 96 |
+
"err_msg": None,
|
| 97 |
+
"result": {}
|
| 98 |
+
}
|
| 99 |
+
try:
|
| 100 |
+
arguments = request.get_json()
|
| 101 |
+
if not arguments:
|
| 102 |
+
resp["err_msg"] = "body is None!"
|
| 103 |
+
return
|
| 104 |
+
img_base64 = arguments.get("img_base64", None)
|
| 105 |
+
zero_type = arguments.get("zero_type", 0)
|
| 106 |
+
position_type = arguments.get("position_type", 0)
|
| 107 |
+
alpha_t = arguments.get("alpha_t", 50)
|
| 108 |
+
if img_base64 is None:
|
| 109 |
+
resp["err_msg"] = "img is None!"
|
| 110 |
+
return
|
| 111 |
+
res = ImageProcessing.image_extraction(img_base64, zero_type, position_type, alpha_t)
|
| 112 |
+
resp["success"] = True
|
| 113 |
+
resp["result"] = res
|
| 114 |
+
except Exception as ex: # pylint: disable=broad-except
|
| 115 |
+
logger.error(traceback.format_exc())
|
| 116 |
+
resp["err_msg"] = str(ex)
|
| 117 |
+
finally:
|
| 118 |
+
t3 = time.time()
|
| 119 |
+
logger.info("request costs %ss" % str(t3 - t0))
|
| 120 |
+
return json.dumps(resp)
|
timi_hok_game_translator/LQA_WMP/lqa_service/portal.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: portal.py
|
| 4 |
+
# @desc: 服务入口文件, 创建 Flask app 并注册 LQA 相关 blueprint;
|
| 5 |
+
# 调试模式下直接启动开发服务器, 生产模式下由 gunicorn 加载本模块的 app 对象启动
|
| 6 |
+
"""
|
| 7 |
+
from flask import Flask
|
| 8 |
+
from config import baseconfig
|
| 9 |
+
from handles.handle_lqa import app_lqa
|
| 10 |
+
from common.log import logger
|
| 11 |
+
|
| 12 |
+
app = Flask(__name__)
|
| 13 |
+
app.register_blueprint(app_lqa)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
# 仅在直接运行本文件时启动开发服务器
|
| 17 |
+
# 不能放在模块级: gunicorn --preload 会 import 本模块, 模块级 app.run()
|
| 18 |
+
# 会阻塞 master 进程导致容器无法启动
|
| 19 |
+
if __name__ == '__main__':
|
| 20 |
+
if baseconfig.DEBUG_MODE:
|
| 21 |
+
logger.info("debug mode started")
|
| 22 |
+
app.run("0.0.0.0", 8086, debug=True)
|
| 23 |
+
else:
|
| 24 |
+
logger.info("debug mode off, serve with: gunicorn -c config/gunicorn_config.py portal:app")
|
| 25 |
+
app.run("0.0.0.0", 8086, debug=False)
|
timi_hok_game_translator/LQA_WMP/lqa_service/requirements.txt
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask==3.0.3
|
| 2 |
+
opencv-python-headless==4.10.0.84
|
| 3 |
+
numpy==1.26.4
|
| 4 |
+
requests==2.32.3
|
| 5 |
+
|
| 6 |
+
# 生产部署 (Linux/容器) 使用; Windows 本地开发不需要
|
| 7 |
+
gunicorn==23.0.0; sys_platform != "win32"
|
| 8 |
+
gevent==24.2.1; sys_platform != "win32"
|
| 9 |
+
|
| 10 |
+
# ---------------------------------------------------------------
|
| 11 |
+
# OCR 引擎: 按 OCR_PROVIDER 的选择安装其中一项, 详见 README
|
| 12 |
+
# ---------------------------------------------------------------
|
| 13 |
+
# OCR_PROVIDER=rapidocr 轻量离线, 默认推荐 (约 15MB, CPU 即可)
|
| 14 |
+
# pip install rapidocr-onnxruntime
|
| 15 |
+
#
|
| 16 |
+
# OCR_PROVIDER=paddleocr 精度更高的离线方案 (依赖较重, 约 2GB)
|
| 17 |
+
# pip install paddleocr paddlepaddle
|
| 18 |
+
#
|
| 19 |
+
# OCR_PROVIDER=easyocr 多语种离线方案
|
| 20 |
+
# pip install easyocr
|
| 21 |
+
#
|
| 22 |
+
# OCR_PROVIDER=tesseract 需额外安装 tesseract 可执行程序与语言包
|
| 23 |
+
# pip install pytesseract
|
| 24 |
+
#
|
| 25 |
+
# OCR_PROVIDER=tencentcloud
|
| 26 |
+
# pip install tencentcloud-sdk-python-ocr
|
| 27 |
+
#
|
| 28 |
+
# OCR_PROVIDER=baidu / azure / paddleocr_http / cvtest
|
| 29 |
+
# 仅需 requests, 无额外依赖
|
timi_hok_game_translator/LQA_WMP/lqa_service/task/image_processing.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: image_processing.py
|
| 4 |
+
# @desc: 图像前景区域提取相关数据处理模块, 提供以下枚举和 ImageProcessing 类:
|
| 5 |
+
# - ZeroType: 坐标原点类型 (左上角/左下角)
|
| 6 |
+
# - PositionType: 位置表示类型 (像素坐标/比例坐标)
|
| 7 |
+
# - ImageProcessing.coordinate_trans: 根据指定的坐标原点 (zero_type) 和表示方式 (position_type),
|
| 8 |
+
# 对矩形区域坐标 (x1,y1,x2,y2) 进行转换
|
| 9 |
+
# - ImageProcessing.get_extraction_rect: 根据 alpha 通道图像及阈值, 扫描计算出非透明
|
| 10 |
+
# 前景内容的最小外接矩形区域, 并处理边界坐标
|
| 11 |
+
# - ImageProcessing.single_image_extraction: 对单张四通道 (RGBA) 图像提取前景区域,
|
| 12 |
+
# 当图像整体透明度偏低时自适应调整阈值, 再按指定坐标原点/表示方式输出结果
|
| 13 |
+
# - ImageProcessing.image_extraction: 批量处理多张图像 (以图像名为 key 的字典),
|
| 14 |
+
# 逐一调用 single_image_extraction 提取前景区域并汇总返回
|
| 15 |
+
"""
|
| 16 |
+
from enum import Enum
|
| 17 |
+
import cv2
|
| 18 |
+
import numpy as np
|
| 19 |
+
from common.tools import base64_to_mat
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class ZeroType(Enum):
|
| 23 |
+
"""坐标原点类型"""
|
| 24 |
+
LEFT_TOP = 0 # 左上角为原点
|
| 25 |
+
LEFT_BOTTOM = 1 # 左下角为原点
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class PositionType(Enum):
|
| 29 |
+
"""位置表示类型"""
|
| 30 |
+
PIXEL = 0 # 像素坐标
|
| 31 |
+
SCALE = 1 # 比例坐标
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class ImageProcessing:
|
| 35 |
+
"""图形处理类"""
|
| 36 |
+
|
| 37 |
+
@staticmethod
|
| 38 |
+
def coordinate_trans(rect, h, w, zero_type=0, position_type=0):
|
| 39 |
+
""" 坐标变换, 根据 zero_type 和 position_type 转换坐标
|
| 40 |
+
:param rect: tuple 或者 list, 四维向量表示区域, 左上角右下角双点定位 (x1, y1, x2, y2)
|
| 41 |
+
:param h: int, 图像高度
|
| 42 |
+
:param w: int, 图像宽度
|
| 43 |
+
:param zero_type: int, 标记坐标原点方式, 默认 0, 取值 ZeroType
|
| 44 |
+
:param position_type: int, 标记位置表示方式, 默认 0, 取值 PositionType
|
| 45 |
+
:return: 转化后的坐标 (x1, y1, x2, y2)
|
| 46 |
+
"""
|
| 47 |
+
if zero_type == ZeroType.LEFT_TOP.value:
|
| 48 |
+
x1, y1, x2, y2 = rect
|
| 49 |
+
elif zero_type == ZeroType.LEFT_BOTTOM.value:
|
| 50 |
+
x1, y1, x2, y2 = rect
|
| 51 |
+
y1 = h - y1
|
| 52 |
+
y2 = h - y2
|
| 53 |
+
else:
|
| 54 |
+
return None
|
| 55 |
+
if position_type == PositionType.PIXEL.value:
|
| 56 |
+
return int(x1), int(y1), int(x2), int(y2)
|
| 57 |
+
elif position_type == PositionType.SCALE.value:
|
| 58 |
+
x1 = round(x1/w, 4)
|
| 59 |
+
y1 = round(y1/h, 4)
|
| 60 |
+
x2 = round(x2/w, 4)
|
| 61 |
+
y2 = round(y2/h, 4)
|
| 62 |
+
return x1, y1, x2, y2
|
| 63 |
+
else:
|
| 64 |
+
return None
|
| 65 |
+
|
| 66 |
+
@staticmethod
|
| 67 |
+
def get_extraction_rect(img_alpha, alpha_t):
|
| 68 |
+
""" 计算前景提取区域
|
| 69 |
+
:param img_alpha: ndarray, alpha通道图像数据
|
| 70 |
+
:param alpha_t: int, alpha通道数据阈值
|
| 71 |
+
:return: rect, 提取的位置
|
| 72 |
+
"""
|
| 73 |
+
h, w = img_alpha.shape
|
| 74 |
+
h_list = []
|
| 75 |
+
w_list = []
|
| 76 |
+
for j in range(h):
|
| 77 |
+
for i in range(w):
|
| 78 |
+
if img_alpha[j, i] > alpha_t:
|
| 79 |
+
h_list.append(j)
|
| 80 |
+
w_list.append(i)
|
| 81 |
+
if len(w_list) > 0 and len(h_list) > 0:
|
| 82 |
+
x1 = np.min(w_list)
|
| 83 |
+
y1 = np.min(h_list)
|
| 84 |
+
x2 = np.max(w_list)
|
| 85 |
+
y2 = np.max(h_list)
|
| 86 |
+
else:
|
| 87 |
+
x1 = 0
|
| 88 |
+
y1 = 0
|
| 89 |
+
x2 = w
|
| 90 |
+
y2 = h
|
| 91 |
+
# 处理边界坐标
|
| 92 |
+
if x1 + 1 == 1:
|
| 93 |
+
x1 = 0
|
| 94 |
+
if y1 + 1 == 1:
|
| 95 |
+
y1 = 0
|
| 96 |
+
if x2 + 1 >= w:
|
| 97 |
+
x2 = w
|
| 98 |
+
if y2 + 1 >= h:
|
| 99 |
+
y2 = h
|
| 100 |
+
rect = (x1, y1, x2, y2)
|
| 101 |
+
return rect
|
| 102 |
+
|
| 103 |
+
@staticmethod
|
| 104 |
+
def single_image_extraction(img_base64, zero_type=0, position_type=0, alpha_t=50):
|
| 105 |
+
""" 单图像前景提取
|
| 106 |
+
:param img_base64: str, base64 格式的图像数据
|
| 107 |
+
:param zero_type: int, 标记坐标原点方式, 支持左下角和左上角原点
|
| 108 |
+
:param position_type: int, 标记位置表示方式, 支持像素和小数比例表示
|
| 109 |
+
:param alpha_t: int, alpha通道数据阈值
|
| 110 |
+
:return: {图像名: 图像位置,...}
|
| 111 |
+
"""
|
| 112 |
+
rect_res = None
|
| 113 |
+
if img_base64 is None:
|
| 114 |
+
return rect_res
|
| 115 |
+
img = base64_to_mat(img_base64, alpha=True)
|
| 116 |
+
if img.shape[2] != 4:
|
| 117 |
+
return rect_res
|
| 118 |
+
# 提取 alpha 通道数据
|
| 119 |
+
_, _, _, a = cv2.split(img)
|
| 120 |
+
h, w = a.shape
|
| 121 |
+
max_a = max([max(item) for item in a.tolist()])
|
| 122 |
+
a_t = alpha_t
|
| 123 |
+
if max_a < a_t:
|
| 124 |
+
a_t = int(max_a / 3 * 2)
|
| 125 |
+
rect = ImageProcessing.get_extraction_rect(a, a_t)
|
| 126 |
+
# 根据坐标原点和位置标记类型参数进行坐标转化
|
| 127 |
+
rect_res = ImageProcessing.coordinate_trans(rect, h, w, zero_type=zero_type, position_type=position_type)
|
| 128 |
+
if not rect_res:
|
| 129 |
+
rect_res = rect
|
| 130 |
+
return rect_res
|
| 131 |
+
|
| 132 |
+
@staticmethod
|
| 133 |
+
def image_extraction(img_base64, zero_type=0, position_type=0, alpha_t=50):
|
| 134 |
+
""" 提取图像前景的实际区域, 支持多张图片批量处理 (四通道图像)
|
| 135 |
+
:param img_base64: dict, 待处理的图像数据 {图像名: base64 图像数据, ...}
|
| 136 |
+
:param zero_type: int, 标记坐标原点方式, 默认 0, 取值 ZeroType
|
| 137 |
+
:param position_type: int, 标记位置表示方式, 默认0, 取值 PositionType
|
| 138 |
+
:param alpha_t: int, alpha 通道数据阈值
|
| 139 |
+
:return: 提取后的结果 {图像名: 图像位置, ...}
|
| 140 |
+
"""
|
| 141 |
+
res = {
|
| 142 |
+
"image_extraction": {}
|
| 143 |
+
}
|
| 144 |
+
if img_base64 is None:
|
| 145 |
+
return res
|
| 146 |
+
for item in img_base64:
|
| 147 |
+
rect_res = ImageProcessing.single_image_extraction(img_base64[item],
|
| 148 |
+
zero_type=zero_type,
|
| 149 |
+
position_type=position_type,
|
| 150 |
+
alpha_t=alpha_t)
|
| 151 |
+
if rect_res:
|
| 152 |
+
res['image_extraction'].update({item: rect_res})
|
| 153 |
+
return res
|
timi_hok_game_translator/LQA_WMP/lqa_service/task/lqa.py
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: lqa.py
|
| 4 |
+
# @desc: LQA 本地化文本异常检测核心逻辑模块, 提供 ImageLqa 类实现以下能力:
|
| 5 |
+
# - lqa_check: 基于 OCR 识别的完整检测流程, 支持漏译、超框 (文本超文本框/图像框)、漏key、
|
| 6 |
+
# 文本框重叠、错译、non_problem 自定义、非标准框等多种异常类型检测,
|
| 7 |
+
# 并支持人工半监督数据 (supervised) 和历史检测结果 (history_result) 辅助判断
|
| 8 |
+
# - lqa_check_no_ocr: 不依赖 OCR 的检测流程, 直接使用标注文本框的实际位置进行检测,
|
| 9 |
+
# 适用于文本框已是文本最小外接矩的场景
|
| 10 |
+
# - degrade_check_type: 当 OCR 服务不可用时, 自动将检测类型降级为仅保留不依赖 OCR 的类型
|
| 11 |
+
# (漏译/文本框与图像框重叠/漏key/文本框重叠/non_problem/非标准框),
|
| 12 |
+
# 跳过依赖 OCR 的类型 (文本超文本框/错译)
|
| 13 |
+
"""
|
| 14 |
+
from common.tools import base64_to_mat, mat_to_base64
|
| 15 |
+
from common.interface_ocr import ocr_available
|
| 16 |
+
from common.log import logger
|
| 17 |
+
from task.lqa_processing import LqaProcessing
|
| 18 |
+
from task.lqa_supervised import Supervised
|
| 19 |
+
from task.lqa_abnormal import ErrorTrans, LqaAbnormal
|
| 20 |
+
from task.lqa_config import LqaCheckType
|
| 21 |
+
|
| 22 |
+
#: 必须依赖 OCR 的检测类型; OCR 不可用时自动剔除
|
| 23 |
+
#: 2-0 文本超文本框需要 OCR 给出文本实际边界; 5 错译需要 OCR 文本内容
|
| 24 |
+
OCR_DEPENDENT_CHECK_TYPES = ('2-0', str(LqaCheckType.ERROR_TRANS.value))
|
| 25 |
+
|
| 26 |
+
#: 不依赖 OCR 的全部检测类型 (纯几何 / 基于标注 textStr)
|
| 27 |
+
#: 1 漏译、2-1 文本框与图像框重叠、3 漏key、4 文本框重叠、6 non_problem、7 非标准框
|
| 28 |
+
OCR_FREE_CHECK_TYPES = ('1', '2-1', '3', '4', '6', '7')
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def degrade_check_type(check_type):
|
| 32 |
+
"""剔除依赖 OCR 的检测类型
|
| 33 |
+
|
| 34 |
+
:param check_type: list[str] 或 None (None 表示全部类型)
|
| 35 |
+
:return: (list[str] 降级后的类型, list[str] 被跳过的类型)
|
| 36 |
+
"""
|
| 37 |
+
if not check_type:
|
| 38 |
+
return list(OCR_FREE_CHECK_TYPES), list(OCR_DEPENDENT_CHECK_TYPES)
|
| 39 |
+
kept, skipped = [], []
|
| 40 |
+
for item in check_type:
|
| 41 |
+
if str(item) in OCR_DEPENDENT_CHECK_TYPES:
|
| 42 |
+
skipped.append(str(item))
|
| 43 |
+
else:
|
| 44 |
+
kept.append(item)
|
| 45 |
+
return kept, skipped
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class ImageLqa:
|
| 49 |
+
"""
|
| 50 |
+
本地化异常处理类
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
@staticmethod
|
| 54 |
+
def lqa_check(img_base64, rect_locations, language, supervised, check_type, history_img_base64, history_result,
|
| 55 |
+
project, no_trans_marks, error_trans_marks):
|
| 56 |
+
"""v0.1: 文本本身超过文本框
|
| 57 |
+
v0.2: 文本框内没有文本; 文本框内文本包含 ##NoTrans; 文本框和图像框重叠
|
| 58 |
+
v0.3: 新增简体中文漏译, 过滤长条状文本框和图像框
|
| 59 |
+
v0.4: 新增图像框缩小
|
| 60 |
+
v1.1: 新增文本框重叠检测
|
| 61 |
+
v1.2: 优化超框和重叠文本框处理 (细分归属判断)
|
| 62 |
+
v1.3: 新增人工半监督
|
| 63 |
+
v1.4: 新增历史数据先验知识
|
| 64 |
+
v1.5: 新增错误翻译检测
|
| 65 |
+
v1.6: 新增 non_problem 检测
|
| 66 |
+
v1.7: 新增 project, 记录调用项目
|
| 67 |
+
:param project: str, 项目
|
| 68 |
+
:param img_base64: str, 被测图像 base64
|
| 69 |
+
:param rect_locations: dict, 待检测标准的 text 和 image 矩形框位置信息
|
| 70 |
+
:param language: int, 游戏包语言代码序号
|
| 71 |
+
:param supervised: dict, 监督数据 (人工审核)
|
| 72 |
+
:param check_type: list[str], 指定检查类型, 与 LqaCheckType-LqaCheckSubType 一致, 如 ['1','2-0','2-1','3']
|
| 73 |
+
:param history_img_base64: str, 历史图像 base64 (用作对比参考)
|
| 74 |
+
:param history_result: dict, 历史图像检测结果 (用作对比参考)
|
| 75 |
+
:param project: 项目
|
| 76 |
+
:param no_trans_marks: str, 漏译匹配标记
|
| 77 |
+
:param error_trans_marks: str, 错译匹配标记
|
| 78 |
+
:return: res, dict, 检测结果
|
| 79 |
+
"""
|
| 80 |
+
# OCR 为可选能力: 不可用时降级走无 OCR 流程, 跳过依赖 OCR 的检测项,
|
| 81 |
+
# 其余检测 (漏译/漏key/框重叠/non_problem/非标准框) 照常返回
|
| 82 |
+
available, ocr_msg = ocr_available()
|
| 83 |
+
if not available:
|
| 84 |
+
kept, skipped = degrade_check_type(check_type)
|
| 85 |
+
logger.warning('OCR 不可用, 降级为无 OCR 检测; 跳过类型 %s (%s)', skipped, ocr_msg)
|
| 86 |
+
res = ImageLqa.lqa_check_no_ocr(img_base64, rect_locations, language, supervised, kept,
|
| 87 |
+
history_img_base64, history_result, project,
|
| 88 |
+
no_trans_marks, error_trans_marks)
|
| 89 |
+
res["ocr_degraded"] = True
|
| 90 |
+
res["ocr_message"] = ocr_msg
|
| 91 |
+
res["skipped_check_type"] = skipped
|
| 92 |
+
return res
|
| 93 |
+
|
| 94 |
+
res = {
|
| 95 |
+
"overframe": False,
|
| 96 |
+
"mark_img": None,
|
| 97 |
+
"rect_img": None,
|
| 98 |
+
"check_detail": None
|
| 99 |
+
}
|
| 100 |
+
img = base64_to_mat(img_base64)
|
| 101 |
+
history_img = base64_to_mat(history_img_base64)
|
| 102 |
+
lqa_img = img.copy()
|
| 103 |
+
rect_img = img.copy()
|
| 104 |
+
text_location_list = rect_locations.get("text", [])
|
| 105 |
+
image_location_list = rect_locations.get("image", [])
|
| 106 |
+
# 提取所有标准文本框信息, 包括位置信息, 过滤脏数据的索引
|
| 107 |
+
gt_text_info = LqaProcessing.detect_gt_text_locations(img, text_location_list, preprocessing=True)
|
| 108 |
+
# 提取所有标准图像框信息
|
| 109 |
+
gt_image_info = LqaProcessing.detect_gt_image_locations(img, image_location_list)
|
| 110 |
+
# 绘制提供的标准框
|
| 111 |
+
rect_img = LqaProcessing.draw_gt_locations(rect_img, gt_text_info, gt_image_info)
|
| 112 |
+
# 预处理数据 (根据历史数据)
|
| 113 |
+
text_location_list, image_location_list, lqa_img, check_detail = Supervised.preprocessing(img,
|
| 114 |
+
lqa_img,
|
| 115 |
+
rect_locations,
|
| 116 |
+
history_img,
|
| 117 |
+
history_result)
|
| 118 |
+
# 预处理的异常 ———— 直接上报的, 只需要直接绘制结果和返回错误
|
| 119 |
+
lqa_img, check_detail = Supervised.preprocessing_errs(lqa_img, rect_locations, gt_text_info, check_detail)
|
| 120 |
+
|
| 121 |
+
if len(check_detail) > 0:
|
| 122 |
+
res['overframe'] = True
|
| 123 |
+
# 无数据直接返回
|
| 124 |
+
if len(text_location_list) <= 0 and len(image_location_list) <= 0:
|
| 125 |
+
res["mark_img"] = mat_to_base64(lqa_img)
|
| 126 |
+
res["rect_img"] = mat_to_base64(rect_img)
|
| 127 |
+
res["check_detail"] = check_detail
|
| 128 |
+
return res
|
| 129 |
+
# 获取各类监督信息
|
| 130 |
+
no_trans_list, over_frame_text_text_list, over_frame_text_image_list, no_key_list, overlap_list, \
|
| 131 |
+
error_trans_list, non_problem_list, non_rectangle_list = Supervised.get_supervised_data(supervised)
|
| 132 |
+
|
| 133 |
+
# 标准数据预处理: 分类, 过滤脏数据
|
| 134 |
+
# 提取所有标准文本框信息, 包括位置信息, 过滤脏数据的索引
|
| 135 |
+
gt_text_info = LqaProcessing.detect_gt_text_locations(img, text_location_list)
|
| 136 |
+
gt_text_locations = gt_text_info['gt_text_locations']
|
| 137 |
+
# 提取所有标准图像框信息
|
| 138 |
+
gt_image_info = LqaProcessing.detect_gt_image_locations(img, image_location_list)
|
| 139 |
+
# 提取所有 OCR 检测信息
|
| 140 |
+
all_ocr_dict = LqaProcessing.detect_ocr_data(img, gt_text_info, project=project)
|
| 141 |
+
all_ocr_error_trans_dict = ErrorTrans.filter_error_trans_ocr_data(all_ocr_dict, error_trans_marks)
|
| 142 |
+
# 标准文本框划分 (判断是否重叠)
|
| 143 |
+
classify_text_location_res = LqaProcessing.classify_text_location_overlap(gt_text_info)
|
| 144 |
+
for text_index in range(len(gt_text_locations)):
|
| 145 |
+
if text_index in gt_text_info['dirty_text_ids']: # 脏标准框数据跳过
|
| 146 |
+
continue
|
| 147 |
+
if text_index in gt_text_info['non_rectangle_ids']: # 非标准框数据
|
| 148 |
+
non_rectangle = True
|
| 149 |
+
else:
|
| 150 |
+
non_rectangle = False
|
| 151 |
+
# 判断每一个文本框
|
| 152 |
+
res, check_detail, rect_img, lqa_img = LqaAbnormal.judge_single_text(
|
| 153 |
+
check_type, language, text_index, img, gt_image_info, gt_text_locations, classify_text_location_res,
|
| 154 |
+
all_ocr_dict, all_ocr_error_trans_dict, no_trans_list, over_frame_text_text_list,
|
| 155 |
+
over_frame_text_image_list, no_key_list, error_trans_list, non_problem_list, non_rectangle_list,
|
| 156 |
+
text_location_list, lqa_img, rect_img, res, check_detail, no_trans_marks, error_trans_marks,
|
| 157 |
+
non_rectangle=non_rectangle, project=project)
|
| 158 |
+
# 处理重叠文本框
|
| 159 |
+
overlap_group = classify_text_location_res['overlap_group']
|
| 160 |
+
overlap_group_id = classify_text_location_res['overlap_group_id']
|
| 161 |
+
if len(overlap_group) > 0:
|
| 162 |
+
# 处理每一组重叠文本框
|
| 163 |
+
for group_index in range(len(overlap_group)):
|
| 164 |
+
res, check_detail, rect_img, lqa_img = LqaAbnormal.judge_single_group_overlap_text(
|
| 165 |
+
check_type, group_index, overlap_group, overlap_group_id,
|
| 166 |
+
img, gt_text_locations, all_ocr_dict,
|
| 167 |
+
classify_text_location_res, text_location_list,
|
| 168 |
+
overlap_list, over_frame_text_text_list, error_trans_list,
|
| 169 |
+
lqa_img, rect_img, res, check_detail, error_trans_marks, project=project)
|
| 170 |
+
res["mark_img"] = mat_to_base64(lqa_img)
|
| 171 |
+
res["rect_img"] = mat_to_base64(rect_img)
|
| 172 |
+
res["check_detail"] = check_detail
|
| 173 |
+
return res
|
| 174 |
+
|
| 175 |
+
@staticmethod
|
| 176 |
+
def lqa_check_no_ocr(img_base64, rect_locations, language, supervised, check_type, history_img_base64, history_result,
|
| 177 |
+
project, no_trans_marks, error_trans_marks):
|
| 178 |
+
"""
|
| 179 |
+
无 ocr 识别, 直接返回文本框内文本的直接位置
|
| 180 |
+
:param project: str, 项目
|
| 181 |
+
:param img_base64: str, 被测图像 base64
|
| 182 |
+
:param rect_locations: dict, 待检测标准的 text 和 image 矩形框位置信息
|
| 183 |
+
:param language: int, 游戏包语言代码序号
|
| 184 |
+
:param supervised: dict, 监督数据 (人工审核)
|
| 185 |
+
:param check_type: list[str], 指定检查类型, 与 LqaCheckType-LqaCheckSubType 一致, 如 ['1','2-0','2-1','3']
|
| 186 |
+
:param history_img_base64: str, 历史图像 base64 (用作对比参考)
|
| 187 |
+
:param history_result: dict, 历史图像检测结果 (用作对比参考)
|
| 188 |
+
:param project: 项目
|
| 189 |
+
:param no_trans_marks: str, 漏译匹配标记
|
| 190 |
+
:param error_trans_marks: str, 错译匹配标记
|
| 191 |
+
:return: res, dict, 检测结果
|
| 192 |
+
"""
|
| 193 |
+
res = {
|
| 194 |
+
"overframe": False,
|
| 195 |
+
"mark_img": None,
|
| 196 |
+
"rect_img": None,
|
| 197 |
+
"check_detail": None
|
| 198 |
+
}
|
| 199 |
+
img = base64_to_mat(img_base64)
|
| 200 |
+
history_img = base64_to_mat(history_img_base64)
|
| 201 |
+
lqa_img = img.copy()
|
| 202 |
+
rect_img = img.copy()
|
| 203 |
+
text_location_list = rect_locations.get("text", [])
|
| 204 |
+
image_location_list = rect_locations.get("image", [])
|
| 205 |
+
# 提取所有标准文本框信息, 包括位置信息, 过滤脏数据的索引
|
| 206 |
+
gt_text_info = LqaProcessing.detect_gt_text_locations(img, text_location_list, preprocessing=True)
|
| 207 |
+
# 提取所有标准图像框信息
|
| 208 |
+
gt_image_info = LqaProcessing.detect_gt_image_locations(img, image_location_list)
|
| 209 |
+
# 绘制标准框
|
| 210 |
+
rect_img = LqaProcessing.draw_gt_locations(rect_img, gt_text_info, gt_image_info)
|
| 211 |
+
# 预处理数据 (根据历史数据)
|
| 212 |
+
text_location_list, image_location_list, lqa_img, check_detail = Supervised.preprocessing(img,
|
| 213 |
+
lqa_img,
|
| 214 |
+
rect_locations,
|
| 215 |
+
history_img,
|
| 216 |
+
history_result)
|
| 217 |
+
# 预处理的异常 ———— 直接上报的, 只需要直接绘制结果和返回错误
|
| 218 |
+
lqa_img, check_detail = Supervised.preprocessing_errs(lqa_img, rect_locations, gt_text_info, check_detail)
|
| 219 |
+
|
| 220 |
+
if len(check_detail) > 0:
|
| 221 |
+
res['overframe'] = True
|
| 222 |
+
# 无数据直接返回
|
| 223 |
+
if len(text_location_list) <= 0 and len(image_location_list) <= 0:
|
| 224 |
+
res["mark_img"] = mat_to_base64(lqa_img)
|
| 225 |
+
res["rect_img"] = mat_to_base64(rect_img)
|
| 226 |
+
res["check_detail"] = check_detail
|
| 227 |
+
return res
|
| 228 |
+
# 获取各类监督信息
|
| 229 |
+
no_trans_list, over_frame_text_text_list, over_frame_text_image_list, no_key_list, overlap_list, \
|
| 230 |
+
error_trans_list, non_problem_list, non_rectangle_list = Supervised.get_supervised_data(supervised)
|
| 231 |
+
|
| 232 |
+
# 标准数据预处理: 分类, 过滤脏数据
|
| 233 |
+
# 提取所有标准文本框信息, 包括位置信息, 过滤脏数据的索引
|
| 234 |
+
gt_text_info = LqaProcessing.detect_gt_text_locations(img, text_location_list)
|
| 235 |
+
gt_text_locations = gt_text_info['gt_text_locations']
|
| 236 |
+
# 提取所有标准图像框信息
|
| 237 |
+
gt_image_info = LqaProcessing.detect_gt_image_locations(img, image_location_list)
|
| 238 |
+
|
| 239 |
+
# 指定错译检查__提取所有OCR检测信息 (只检查一遍, 用于判断是否有错译)
|
| 240 |
+
check_type_id = LqaCheckType.ERROR_TRANS.value
|
| 241 |
+
if not check_type or str(check_type_id) in check_type:
|
| 242 |
+
all_ocr_dict = LqaProcessing.detect_ocr_data(img, gt_text_info, project=project)
|
| 243 |
+
all_ocr_error_trans_dict = ErrorTrans.filter_error_trans_ocr_data(all_ocr_dict, error_trans_marks)
|
| 244 |
+
else:
|
| 245 |
+
all_ocr_dict = {}
|
| 246 |
+
all_ocr_error_trans_dict = {}
|
| 247 |
+
# 所有文本框碰撞检测, 不重复
|
| 248 |
+
dirty_text_ids = gt_text_info['dirty_text_ids']
|
| 249 |
+
overlap_dict = {}
|
| 250 |
+
cnt = len(gt_text_locations)
|
| 251 |
+
for i in range(cnt):
|
| 252 |
+
if i in dirty_text_ids: # 脏数据过滤, 便于后续检测, 无需处理
|
| 253 |
+
continue
|
| 254 |
+
overlap_dict = LqaProcessing.judge_overlap_with_text_i(overlap_dict, i, gt_text_locations, dirty_text_ids)
|
| 255 |
+
# 判断每一个文本框
|
| 256 |
+
for text_index in range(cnt):
|
| 257 |
+
if text_index in dirty_text_ids: # 脏标准框数据跳过
|
| 258 |
+
continue
|
| 259 |
+
if text_index in gt_text_info['non_rectangle_ids']: # 非标准框数据
|
| 260 |
+
non_rectangle = True
|
| 261 |
+
else:
|
| 262 |
+
non_rectangle = False
|
| 263 |
+
res, check_detail, rect_img, lqa_img = LqaAbnormal.judge_single_text_no_ocr(
|
| 264 |
+
check_type, language, text_index, img, gt_image_info, gt_text_locations, overlap_dict,
|
| 265 |
+
all_ocr_dict, all_ocr_error_trans_dict,
|
| 266 |
+
no_trans_list, error_trans_list, over_frame_text_text_list,
|
| 267 |
+
over_frame_text_image_list, no_key_list, non_problem_list, non_rectangle_list,
|
| 268 |
+
text_location_list, lqa_img, rect_img, res, check_detail, no_trans_marks, error_trans_marks,
|
| 269 |
+
non_rectangle=non_rectangle, project=project)
|
| 270 |
+
|
| 271 |
+
res["mark_img"] = mat_to_base64(lqa_img)
|
| 272 |
+
res["rect_img"] = mat_to_base64(rect_img)
|
| 273 |
+
res["check_detail"] = check_detail
|
| 274 |
+
return res
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
if __name__ == '__main__':
|
| 278 |
+
pass
|
timi_hok_game_translator/LQA_WMP/lqa_service/task/lqa_abnormal.py
ADDED
|
@@ -0,0 +1,1029 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: lqa_abnormal.py
|
| 4 |
+
# @desc: LQA 本地化异常检测核心判断逻辑模块, 提供以下三个类:
|
| 5 |
+
# - ErrorTrans: 错译检测类, 根据错译标记词 (error_trans_marks) 判断文本/OCR 结果是否命中错译,
|
| 6 |
+
# 并支持从全图 OCR 结果中过滤出所有错译候选项
|
| 7 |
+
# - OverlapText: 重叠文本框处理类, 当多个标准文本框存在重叠 (合并为一个外接矩形) 时,
|
| 8 |
+
# 通过 OCR 识别该区域并按重叠面积归属各子文本框, 必要时对 OCR 结果做二值化
|
| 9 |
+
# 细分割 (split_ocr), 再逐一判断子文本框是否存在错译/超框/重叠等异常
|
| 10 |
+
# - LqaAbnormal: 异常检测主类, 汇总各类判断方法:
|
| 11 |
+
# * no_trans: 漏译检测 (命中漏译标记词)
|
| 12 |
+
# * no_key: 漏key检测 (简繁体字符集比对, 识别出简体中文残留)
|
| 13 |
+
# * custom_abnormal: 自定义 non_problem 标记检测
|
| 14 |
+
# * error_trans: 错译检测 (全局/单文本框两种模式)
|
| 15 |
+
# * text_overframe/ocr_image_overlap: 文本超文本框、文本与图像框重叠的碰撞检测
|
| 16 |
+
# * judge_single_text/judge_single_text_no_ocr: 对单个文本框执行全部类型检测
|
| 17 |
+
# (分别对应依赖 OCR 识别定位 和 已知精确坐标两种模式)
|
| 18 |
+
# * judge_single_independent_text: 对无重叠的独立文本框做 OCR 位置校准后再检测
|
| 19 |
+
# * judge_single_group_overlap_text: 对一组重叠文本框做 OCR 识别、归属判断及检测
|
| 20 |
+
# * update_check_type_detail/update_check_res: 统一记录检测结果详情,
|
| 21 |
+
# 并在结果图上绘制对应的标注框 (需排除已被人工监督确认的数据)
|
| 22 |
+
"""
|
| 23 |
+
import cv2
|
| 24 |
+
import json
|
| 25 |
+
import numpy as np
|
| 26 |
+
from config.baseconfig import NO_TRANS_MARK_LIST, SIMPLIFIED_CHINESE_SET, TRADITIONAL_CHINESE_SET, \
|
| 27 |
+
ERROR_TRANS_MARK_LIST, NON_PROBLEM_MARK
|
| 28 |
+
from common.tools import img_draw_rect, mat_to_base64
|
| 29 |
+
from common.interface_ocr import ocr
|
| 30 |
+
from task.lqa_config import LqaCheckType, LqaCheckSubType, Language, DrawStyle
|
| 31 |
+
from task.lqa_processing import LqaProcessing
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class ErrorTrans:
|
| 35 |
+
"""错译检测类"""
|
| 36 |
+
|
| 37 |
+
@staticmethod
|
| 38 |
+
def error_trans_mark(text_str, error_trans_marks):
|
| 39 |
+
"""判断文本是否包含错误翻译标记
|
| 40 |
+
:param text_str: str, 文本字符串
|
| 41 |
+
:param error_trans_marks: str, 错译标识
|
| 42 |
+
:return: have_error_trans_mark, bool, 是否包含错译标记词条
|
| 43 |
+
"""
|
| 44 |
+
have_error_trans_mark = False
|
| 45 |
+
if not text_str: # 标准数据未提供文本内容, 无从判断
|
| 46 |
+
return have_error_trans_mark
|
| 47 |
+
if error_trans_marks not in ['', None]: # 项目自定义
|
| 48 |
+
error_trans_marks_list = json.loads(error_trans_marks)
|
| 49 |
+
else:
|
| 50 |
+
error_trans_marks_list = ERROR_TRANS_MARK_LIST # 默认
|
| 51 |
+
for mask in error_trans_marks_list:
|
| 52 |
+
if isinstance(mask, list): # 多标记组合
|
| 53 |
+
cnt = 0
|
| 54 |
+
for item in mask:
|
| 55 |
+
if item in text_str:
|
| 56 |
+
cnt += 1
|
| 57 |
+
if cnt == len(mask):
|
| 58 |
+
have_error_trans_mark = True
|
| 59 |
+
break
|
| 60 |
+
else:
|
| 61 |
+
if mask in text_str:
|
| 62 |
+
have_error_trans_mark = True
|
| 63 |
+
break
|
| 64 |
+
return have_error_trans_mark
|
| 65 |
+
|
| 66 |
+
@staticmethod
|
| 67 |
+
def filter_error_trans_ocr_data(all_ocr_dict, error_trans_marks):
|
| 68 |
+
"""从检测图像所有 ocr 结果中, 过滤出包含错误翻译标记的数据
|
| 69 |
+
:param all_ocr_dict: dict, 全图 ocr 识别结果
|
| 70 |
+
:param error_trans_marks: str, 错译标识
|
| 71 |
+
:return: all_ocr_error_trans_dict, dict, 所有包含错误翻译标记的 ocr 识别结果
|
| 72 |
+
"""
|
| 73 |
+
all_ocr_error_trans_dict = {}
|
| 74 |
+
for ocr_result in all_ocr_dict:
|
| 75 |
+
if ErrorTrans.error_trans_mark(ocr_result, error_trans_marks):
|
| 76 |
+
all_ocr_error_trans_dict[ocr_result] = all_ocr_dict[ocr_result]
|
| 77 |
+
return all_ocr_error_trans_dict
|
| 78 |
+
|
| 79 |
+
@staticmethod
|
| 80 |
+
def all_error_trans(text_location, ocr_data):
|
| 81 |
+
"""全图文本框区域检测错译
|
| 82 |
+
:param text_location: list, 文本位置信息
|
| 83 |
+
:param ocr_data: dict, ocr识别结果
|
| 84 |
+
:return: bool, 是否错译
|
| 85 |
+
"""
|
| 86 |
+
for ocr_str in ocr_data:
|
| 87 |
+
for ocr_location in ocr_data[ocr_str]:
|
| 88 |
+
# 文本区域与错译 ocr_data 发生碰撞
|
| 89 |
+
is_overlap, ratio, _ = LqaProcessing.overlap(text_location, ocr_location, x_t=0, y_t=0)
|
| 90 |
+
if is_overlap and ratio > 0.3:
|
| 91 |
+
return True
|
| 92 |
+
return False
|
| 93 |
+
|
| 94 |
+
@staticmethod
|
| 95 |
+
def single_error_trans(ocr_data, error_trans_marks):
|
| 96 |
+
"""局部文本框区域检测错译
|
| 97 |
+
:param ocr_data: dict, ocr识别结果
|
| 98 |
+
:param error_trans_marks: str, 错译标识
|
| 99 |
+
:return: bool, 是否错译
|
| 100 |
+
"""
|
| 101 |
+
if isinstance(ocr_data, list):
|
| 102 |
+
for item in ocr_data:
|
| 103 |
+
ocr_result = item['result']
|
| 104 |
+
if ErrorTrans.error_trans_mark(ocr_result, error_trans_marks):
|
| 105 |
+
return True
|
| 106 |
+
elif isinstance(ocr_data, dict) and 'result' in ocr_data:
|
| 107 |
+
ocr_result = ocr_data['result']
|
| 108 |
+
if ErrorTrans.error_trans_mark(ocr_result, error_trans_marks):
|
| 109 |
+
return True
|
| 110 |
+
return False
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
class OverlapText:
|
| 114 |
+
"""重叠文本框处理类"""
|
| 115 |
+
|
| 116 |
+
@staticmethod
|
| 117 |
+
def judge_overlap_ocr_belong(align_res, align_ocr_res, group_id, gt_text_locations):
|
| 118 |
+
"""判断重叠文本框中各个 OCR 子项的归属
|
| 119 |
+
:param align_res: list, ocr识别位置信息
|
| 120 |
+
:param align_ocr_res: list, ocr 识别文本信息
|
| 121 |
+
:param group_id: list, 多个重叠文本框聚合的 id 列表
|
| 122 |
+
:param gt_text_locations: dict, 所有文本框信息
|
| 123 |
+
:return: overlap_info, 重叠文本框归属信息
|
| 124 |
+
"""
|
| 125 |
+
overlap_info = {}
|
| 126 |
+
for i in range(len(align_res)):
|
| 127 |
+
align_location = align_res[i]
|
| 128 |
+
ocr_res = align_ocr_res[i] if len(align_ocr_res) == len(align_res) else []
|
| 129 |
+
# 过滤合并区域识别出的非文本框内容
|
| 130 |
+
overlap_item_ratio = []
|
| 131 |
+
overlap_item_sub_px = []
|
| 132 |
+
overlap_item_id = []
|
| 133 |
+
for item in group_id:
|
| 134 |
+
is_overlap, ratio, sub_px = LqaProcessing.overlap(gt_text_locations[item], align_location, x_t=0, y_t=0)
|
| 135 |
+
if is_overlap and ratio > 0.3:
|
| 136 |
+
overlap_item_id.append(item)
|
| 137 |
+
overlap_item_ratio.append(ratio)
|
| 138 |
+
overlap_item_sub_px.append(sub_px)
|
| 139 |
+
if len(overlap_item_id) > 0:
|
| 140 |
+
# 计算最大重叠率判断归属
|
| 141 |
+
max_ratio_index = overlap_item_ratio.index(max(overlap_item_ratio))
|
| 142 |
+
belong_id = overlap_item_id[max_ratio_index]
|
| 143 |
+
if belong_id not in overlap_info:
|
| 144 |
+
overlap_info[belong_id] = []
|
| 145 |
+
overlap_info[belong_id].append({'ocr_res': ocr_res,
|
| 146 |
+
'ocr_location': align_location,
|
| 147 |
+
'gt_location': gt_text_locations[belong_id],
|
| 148 |
+
'ratio': overlap_item_ratio[max_ratio_index],
|
| 149 |
+
'sub_px': overlap_item_sub_px[max_ratio_index]})
|
| 150 |
+
return overlap_info
|
| 151 |
+
|
| 152 |
+
@staticmethod
|
| 153 |
+
def check_every_overlap_ocr(check_type, rect_img, lqa_img, overlap_info, text_location_list, gt_text_locations,
|
| 154 |
+
res, check_detail, supervised_info, error_trans_marks):
|
| 155 |
+
"""判断重叠文本框中各个 OCR 子项的归属
|
| 156 |
+
:param check_type: list, 检测类型
|
| 157 |
+
:param rect_img: ndarray, 标记图
|
| 158 |
+
:param lqa_img: ndarray, lqa识别结果图
|
| 159 |
+
:param overlap_info: dict, 一组重叠文本框的信息
|
| 160 |
+
:param text_location_list: list, 待测试文本框信息 (去掉脏数据等)
|
| 161 |
+
:param gt_text_locations: list, 标准文本框信息
|
| 162 |
+
:param res: dict, 结果数据
|
| 163 |
+
:param check_detail: dict, 已检测结果详情
|
| 164 |
+
:param supervised_info: dict, 监督信息
|
| 165 |
+
:param error_trans_marks: str, 错译标识
|
| 166 |
+
:return: res, 检测结果数据
|
| 167 |
+
check_detail, 检测结果详情
|
| 168 |
+
rect_img, 标记图像
|
| 169 |
+
lqa_img, 检测结果图像
|
| 170 |
+
"""
|
| 171 |
+
# 一组重叠文本框各个对象检测
|
| 172 |
+
for g_id in overlap_info:
|
| 173 |
+
text_location_dict = text_location_list[g_id]
|
| 174 |
+
text_str = text_location_dict.get("textStr")
|
| 175 |
+
# 错译
|
| 176 |
+
check_type_id = LqaCheckType.ERROR_TRANS.value
|
| 177 |
+
if check_type is None or str(check_type_id) in check_type:
|
| 178 |
+
for overlap_item_i in overlap_info[g_id]:
|
| 179 |
+
is_abnormal = LqaAbnormal.error_trans(text_str,
|
| 180 |
+
overlap_item_i['gt_location'],
|
| 181 |
+
overlap_item_i['ocr_res'],
|
| 182 |
+
error_trans_marks,
|
| 183 |
+
check_type='single')
|
| 184 |
+
if is_abnormal:
|
| 185 |
+
detail_data = [text_str, list(gt_text_locations[g_id])]
|
| 186 |
+
supervised_error_trans = supervised_info['error_trans']
|
| 187 |
+
res, check_detail, lqa_img = LqaAbnormal.update_check_res(res,
|
| 188 |
+
check_detail,
|
| 189 |
+
check_type_id,
|
| 190 |
+
detail_data,
|
| 191 |
+
supervised_error_trans,
|
| 192 |
+
lqa_img,
|
| 193 |
+
overlap_item_i['gt_location'],
|
| 194 |
+
DrawStyle.ERROR_TRANS.value)
|
| 195 |
+
# 碰撞检测, 文本超过文本框
|
| 196 |
+
type_id = LqaCheckType.OVER_FRAME.value
|
| 197 |
+
sub_type_id = LqaCheckSubType.OVER_FRAME_TEXT_TEXT.value
|
| 198 |
+
check_type_id = str(type_id) + "-" + str(sub_type_id)
|
| 199 |
+
if check_type is None or check_type_id in check_type:
|
| 200 |
+
for overlap_item_i in overlap_info[g_id]:
|
| 201 |
+
rect_img = img_draw_rect(rect_img, overlap_item_i['ocr_location'],
|
| 202 |
+
draw_style=DrawStyle.OVERLAP.value)
|
| 203 |
+
is_abnormal = LqaAbnormal.text_overframe(overlap_item_i['ocr_location'],
|
| 204 |
+
overlap_item_i['gt_location'],
|
| 205 |
+
t=(5, 5, 5, 5))
|
| 206 |
+
if is_abnormal:
|
| 207 |
+
detail_data = [text_str, list(gt_text_locations[g_id])]
|
| 208 |
+
draw_style = DrawStyle.GT_TEXT.value
|
| 209 |
+
supervised_over_frame_text_text = supervised_info['over_frame_text_text']
|
| 210 |
+
res, check_detail, lqa_img = LqaAbnormal.update_check_res(res,
|
| 211 |
+
check_detail,
|
| 212 |
+
type_id,
|
| 213 |
+
detail_data,
|
| 214 |
+
supervised_over_frame_text_text,
|
| 215 |
+
lqa_img,
|
| 216 |
+
overlap_item_i['gt_location'],
|
| 217 |
+
draw_style,
|
| 218 |
+
sub_type_id=sub_type_id)
|
| 219 |
+
return res, check_detail, rect_img, lqa_img
|
| 220 |
+
|
| 221 |
+
@staticmethod
|
| 222 |
+
def sorted_detail_data(group_text_id, text_location_list, gt_text_locations):
|
| 223 |
+
"""结果详情排序
|
| 224 |
+
:param group_text_id: list, 一组重叠文本框对应的索引列表
|
| 225 |
+
:param text_location_list: list, 待测试文本框信息 (去掉脏数据等)
|
| 226 |
+
:param gt_text_locations: list, 标准文本框信息
|
| 227 |
+
:return: detail_data, 排序后的结果详情
|
| 228 |
+
"""
|
| 229 |
+
detail_data = []
|
| 230 |
+
for text_id in group_text_id:
|
| 231 |
+
text_location_dict = text_location_list[text_id]
|
| 232 |
+
text_str = text_location_dict.get("textStr")
|
| 233 |
+
detail_data_item = [text_str, list(gt_text_locations[text_id])]
|
| 234 |
+
detail_data.append(detail_data_item)
|
| 235 |
+
detail_data = sorted(detail_data)
|
| 236 |
+
return detail_data
|
| 237 |
+
|
| 238 |
+
@staticmethod
|
| 239 |
+
def judge_split(overlap_item):
|
| 240 |
+
"""判断文本框是否需要再次细分割
|
| 241 |
+
:param overlap_item: dict, 子文本框
|
| 242 |
+
:return: bool, 是否细分割
|
| 243 |
+
"""
|
| 244 |
+
if overlap_item['ratio'] > 0.9 or (overlap_item['sub_px'][0] < 5 and overlap_item['sub_px'][1] < 4):
|
| 245 |
+
return False
|
| 246 |
+
return True
|
| 247 |
+
|
| 248 |
+
@staticmethod
|
| 249 |
+
def get_split_tags(binary_img):
|
| 250 |
+
""" 提取二值图像的分割标记
|
| 251 |
+
:param binary_img: ndarray, 二值图像
|
| 252 |
+
:return: split_tags, list, 分割标记
|
| 253 |
+
"""
|
| 254 |
+
split_tags = []
|
| 255 |
+
h, w = binary_img.shape[:2]
|
| 256 |
+
for i in range(w):
|
| 257 |
+
split = True
|
| 258 |
+
for j in range(h):
|
| 259 |
+
if binary_img[j][i] > 0:
|
| 260 |
+
split = False
|
| 261 |
+
break
|
| 262 |
+
if split:
|
| 263 |
+
split_tags.append(1)
|
| 264 |
+
else:
|
| 265 |
+
split_tags.append(0)
|
| 266 |
+
return split_tags
|
| 267 |
+
|
| 268 |
+
@staticmethod
|
| 269 |
+
def get_split_range(split_tags):
|
| 270 |
+
""" 根据分割标记提取分割范围
|
| 271 |
+
:param split_tags, list, 分割标记
|
| 272 |
+
:return: split_range, list, 分割范围
|
| 273 |
+
"""
|
| 274 |
+
start = -1
|
| 275 |
+
split_range = []
|
| 276 |
+
for i in range(len(split_tags)):
|
| 277 |
+
if split_tags[i] == 1 and start == -1:
|
| 278 |
+
start = i
|
| 279 |
+
elif (split_tags[i] == 0 or i == len(split_tags) - 1) and start != -1:
|
| 280 |
+
end = i
|
| 281 |
+
split_range.append((end - start, (start, end)))
|
| 282 |
+
start = -1
|
| 283 |
+
return split_range
|
| 284 |
+
|
| 285 |
+
@staticmethod
|
| 286 |
+
def get_split_ocr_locations(ocr_location, split_range, k):
|
| 287 |
+
"""根据分割目标, 对分割结果排序, 计算分割结果
|
| 288 |
+
:param ocr_location: list, 区域位置
|
| 289 |
+
:param split_range: list, 可���的分割范围
|
| 290 |
+
:param k: int, 分割的子区域数目
|
| 291 |
+
:return: split_ocr_locations, list, 分割结果
|
| 292 |
+
"""
|
| 293 |
+
# 根据间隔对预分割线进行排序
|
| 294 |
+
sort_split_range = sorted(split_range, key=lambda x: x[0], reverse=True)
|
| 295 |
+
t_k = min(k - 1, len(sort_split_range))
|
| 296 |
+
top_k = sort_split_range[:t_k]
|
| 297 |
+
sort_top_k = sorted(top_k, key=lambda x: x[1][0])
|
| 298 |
+
split_ocr_locations = []
|
| 299 |
+
for i in range(t_k):
|
| 300 |
+
if i == 0:
|
| 301 |
+
ocr_x = (ocr_location[0], sort_top_k[i][1][0] + ocr_location[0] - 1)
|
| 302 |
+
else:
|
| 303 |
+
ocr_x = (sort_top_k[i - 1][1][1] + ocr_location[0] + 1, sort_top_k[i][1][0] + ocr_location[0] - 1)
|
| 304 |
+
split_ocr_location = (ocr_x[0], ocr_location[1], ocr_x[1], ocr_location[3])
|
| 305 |
+
split_ocr_locations.append(split_ocr_location)
|
| 306 |
+
tail_ocr_x = (sort_top_k[-1][1][1] + ocr_location[0] + 1, ocr_location[2])
|
| 307 |
+
split_ocr_location = (tail_ocr_x[0], ocr_location[1], tail_ocr_x[1], ocr_location[3])
|
| 308 |
+
split_ocr_locations.append(split_ocr_location)
|
| 309 |
+
return split_ocr_locations
|
| 310 |
+
|
| 311 |
+
@staticmethod
|
| 312 |
+
def split_ocr(img, ocr_location, k):
|
| 313 |
+
""" ocr 识别结果细分割, 将 ocr_location 区域分为 k 个子区域
|
| 314 |
+
:param img: ndarray, 图像
|
| 315 |
+
:param ocr_location: list, x1,y1,x2,y2 格式
|
| 316 |
+
:param k: int, 分割子串数目
|
| 317 |
+
:return: split_ocr_locations, list, 分割结果
|
| 318 |
+
"""
|
| 319 |
+
# 二值化, 计算预分割线
|
| 320 |
+
rect_img = img.copy()
|
| 321 |
+
rect_img = rect_img[ocr_location[1]:ocr_location[3], ocr_location[0]:ocr_location[2]]
|
| 322 |
+
gray_img = cv2.cvtColor(rect_img, cv2.COLOR_BGR2GRAY)
|
| 323 |
+
binary_threshold = np.mean(gray_img)
|
| 324 |
+
_, th = cv2.threshold(gray_img, binary_threshold, 255, cv2.THRESH_BINARY)
|
| 325 |
+
if binary_threshold > 150:
|
| 326 |
+
th = ~th
|
| 327 |
+
# 提取可能分割标记
|
| 328 |
+
split_tags = OverlapText.get_split_tags(th)
|
| 329 |
+
# 提取分割范围
|
| 330 |
+
split_range = OverlapText.get_split_range(split_tags)
|
| 331 |
+
if len(split_range) <= 0:
|
| 332 |
+
return []
|
| 333 |
+
# 根据间隔对预分割线进行排序, 提取分割结果
|
| 334 |
+
split_ocr_locations = OverlapText.get_split_ocr_locations(ocr_location, split_range, k)
|
| 335 |
+
return split_ocr_locations
|
| 336 |
+
|
| 337 |
+
@staticmethod
|
| 338 |
+
def recheck_every_overlap_ocr(check_type, img, rect_img, lqa_img, overlap_item, group_id, gt_text_locations,
|
| 339 |
+
res, check_detail, detail_data, supervised_info):
|
| 340 |
+
"""细粒度判断重叠文本框中的 OCR 子项
|
| 341 |
+
:param check_type: list, 检测类型
|
| 342 |
+
:param img: ndarray, 原测试图
|
| 343 |
+
:param rect_img: ndarray, 标记图
|
| 344 |
+
:param lqa_img: ndarray, lqa 识别结果图
|
| 345 |
+
:param overlap_item: dict, 一组重叠文本框的子文本框
|
| 346 |
+
:param group_id: list, 待测试文本框信息 (去掉脏数据等)
|
| 347 |
+
:param gt_text_locations: list, 标准文本框信息
|
| 348 |
+
:param res: dict, 结果数据
|
| 349 |
+
:param check_detail: dict, 已检测结果详情
|
| 350 |
+
:param detail_data: dict, 检测详情
|
| 351 |
+
:param supervised_info: dict, 监督信息
|
| 352 |
+
:return: res, 检测结果数据
|
| 353 |
+
check_detail, 检测结果详情
|
| 354 |
+
rect_img, 标记图像
|
| 355 |
+
lqa_img, 检测结果图像
|
| 356 |
+
"""
|
| 357 |
+
draw_style = DrawStyle.OVERLAP.value
|
| 358 |
+
# 重叠率足够, 无需细分判断
|
| 359 |
+
if not OverlapText.judge_split(overlap_item):
|
| 360 |
+
draw_rect = overlap_item['ocr_location']
|
| 361 |
+
rect_img = img_draw_rect(rect_img, draw_rect, draw_style)
|
| 362 |
+
|
| 363 |
+
# 需要细分进行分割
|
| 364 |
+
else:
|
| 365 |
+
split_ocr_rect = overlap_item['ocr_location']
|
| 366 |
+
split_ocr_locations = OverlapText.split_ocr(img, split_ocr_rect, k=len(group_id))
|
| 367 |
+
split_overlap_info = OverlapText.judge_overlap_ocr_belong(split_ocr_locations,
|
| 368 |
+
[],
|
| 369 |
+
group_id,
|
| 370 |
+
gt_text_locations)
|
| 371 |
+
for split_g_id in split_overlap_info:
|
| 372 |
+
for split_item_i in split_overlap_info[split_g_id]:
|
| 373 |
+
draw_rect = split_item_i['ocr_location']
|
| 374 |
+
rect_img = img_draw_rect(rect_img, draw_rect, draw_style)
|
| 375 |
+
if not OverlapText.judge_split(split_item_i):
|
| 376 |
+
continue
|
| 377 |
+
else:
|
| 378 |
+
check_type_id = LqaCheckType.OVERLAP.value
|
| 379 |
+
supervised_overlap = supervised_info['overlap']
|
| 380 |
+
if check_type is None or str(check_type_id) in check_type:
|
| 381 |
+
res, check_detail, lqa_img = LqaAbnormal.update_check_res(res,
|
| 382 |
+
check_detail,
|
| 383 |
+
check_type_id,
|
| 384 |
+
detail_data,
|
| 385 |
+
supervised_overlap,
|
| 386 |
+
lqa_img,
|
| 387 |
+
draw_rect,
|
| 388 |
+
draw_style)
|
| 389 |
+
return res, check_detail, rect_img, lqa_img
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
class LqaAbnormal:
|
| 393 |
+
"""lqa 数据异常检测类"""
|
| 394 |
+
|
| 395 |
+
@staticmethod
|
| 396 |
+
def update_check_type_detail(check_detail, type_id, data, sub_type_id=None):
|
| 397 |
+
"""检测结果分类详情
|
| 398 |
+
:param check_detail: dict, 结果分类详情
|
| 399 |
+
:param type_id: int 问题类型 id
|
| 400 |
+
:param data: 记录的详细数据
|
| 401 |
+
:param sub_type_id: int 问题子类型 id
|
| 402 |
+
:return: res, 更新后的结果数据
|
| 403 |
+
check_detail, 更新后的检测结果详情
|
| 404 |
+
img, 标记后的图像
|
| 405 |
+
"""
|
| 406 |
+
if not check_detail:
|
| 407 |
+
check_detail = {}
|
| 408 |
+
|
| 409 |
+
if type_id not in check_detail:
|
| 410 |
+
if sub_type_id is None:
|
| 411 |
+
check_detail[type_id] = []
|
| 412 |
+
else:
|
| 413 |
+
check_detail[type_id] = {}
|
| 414 |
+
if sub_type_id is None:
|
| 415 |
+
if data not in check_detail[type_id]:
|
| 416 |
+
check_detail[type_id].append(data)
|
| 417 |
+
else:
|
| 418 |
+
if sub_type_id not in check_detail[type_id]:
|
| 419 |
+
check_detail[type_id][sub_type_id] = []
|
| 420 |
+
if data not in check_detail[type_id][sub_type_id]:
|
| 421 |
+
check_detail[type_id][sub_type_id].append(data)
|
| 422 |
+
|
| 423 |
+
return check_detail
|
| 424 |
+
|
| 425 |
+
@staticmethod
|
| 426 |
+
def update_check_res(res, check_detail, type_id, detail_data, supervised_detail_data,
|
| 427 |
+
img, draw_rect, draw_style, sub_type_id=None):
|
| 428 |
+
"""标记异常
|
| 429 |
+
:param res: dict, 结果数据
|
| 430 |
+
:param check_detail: dict, 已检测结果详情
|
| 431 |
+
:param type_id: int, 异常检测类型 id
|
| 432 |
+
:param detail_data: list, 待记录数据
|
| 433 |
+
:param supervised_detail_data: list, 监督数据列表
|
| 434 |
+
:param img: ndarray, 图像
|
| 435 |
+
:param draw_rect: x1, y1, x2, y2, 标记位置
|
| 436 |
+
:param draw_style: tuple, 绘制样式, 取值 DrawStyle, 包括颜色, 线条 size
|
| 437 |
+
:param sub_type_id: int, 异常检测子类型 id
|
| 438 |
+
:return: res, 更新后的结果数据
|
| 439 |
+
check_detail, 更新后的检测结果详情
|
| 440 |
+
img, 标记后的图像
|
| 441 |
+
"""
|
| 442 |
+
if detail_data not in supervised_detail_data:
|
| 443 |
+
res["overframe"] = True
|
| 444 |
+
check_detail = LqaAbnormal.update_check_type_detail(check_detail, type_id, detail_data,
|
| 445 |
+
sub_type_id=sub_type_id)
|
| 446 |
+
img = img_draw_rect(img, draw_rect, draw_style=draw_style)
|
| 447 |
+
return res, check_detail, img
|
| 448 |
+
|
| 449 |
+
@staticmethod
|
| 450 |
+
def no_key(text_str, language):
|
| 451 |
+
"""简体中文漏 key 检测
|
| 452 |
+
:param text_str: str, 待检测文本
|
| 453 |
+
:param language: int, 语言 int
|
| 454 |
+
:return: is_abnormal, bool, 是否异常
|
| 455 |
+
"""
|
| 456 |
+
is_abnormal = False
|
| 457 |
+
traditional_chinese = False
|
| 458 |
+
if not text_str: # 标准数据未提供文本内容, 无从判断
|
| 459 |
+
return is_abnormal
|
| 460 |
+
ocr_set = set(list(text_str))
|
| 461 |
+
# 判断有繁体字
|
| 462 |
+
traditional_intersection = ocr_set & TRADITIONAL_CHINESE_SET
|
| 463 |
+
if traditional_intersection:
|
| 464 |
+
traditional_chinese = True
|
| 465 |
+
# 判断有简体中文
|
| 466 |
+
simple_intersection = ocr_set & SIMPLIFIED_CHINESE_SET
|
| 467 |
+
# 异常判断: 1.没有繁体中文但存在简体中文 2.外语误识别的中文
|
| 468 |
+
if not traditional_chinese and simple_intersection:
|
| 469 |
+
if language == Language.ja_JP.value:
|
| 470 |
+
if len(simple_intersection) == len(ocr_set):
|
| 471 |
+
is_abnormal = True
|
| 472 |
+
else:
|
| 473 |
+
if len(simple_intersection) >= 1:
|
| 474 |
+
is_abnormal = True
|
| 475 |
+
return is_abnormal
|
| 476 |
+
|
| 477 |
+
@staticmethod
|
| 478 |
+
def no_trans(text_str, no_trans_marks):
|
| 479 |
+
"""漏译检测
|
| 480 |
+
:param text_str: str, 待检测文本
|
| 481 |
+
:param no_trans_marks: str, 漏译标识
|
| 482 |
+
:return: is_abnormal, bool, 是否异常
|
| 483 |
+
"""
|
| 484 |
+
is_abnormal = False
|
| 485 |
+
if not text_str: # 标准数据未提供文本内容, 无从判断
|
| 486 |
+
return is_abnormal
|
| 487 |
+
if no_trans_marks not in ['', None]: # 项目自定义
|
| 488 |
+
no_trans_marks_list = json.loads(no_trans_marks)
|
| 489 |
+
else:
|
| 490 |
+
no_trans_marks_list = NO_TRANS_MARK_LIST # 默认
|
| 491 |
+
for no_trans_mask in no_trans_marks_list:
|
| 492 |
+
if no_trans_mask in text_str:
|
| 493 |
+
is_abnormal = True
|
| 494 |
+
break
|
| 495 |
+
return is_abnormal
|
| 496 |
+
|
| 497 |
+
@staticmethod
|
| 498 |
+
def custom_abnormal(text_str, tag_text=NON_PROBLEM_MARK):
|
| 499 |
+
"""自定义类型 non_problem 检测
|
| 500 |
+
:param text_str: str, 待检测文本
|
| 501 |
+
:param tag_text: str, 自定义命中的标记文本
|
| 502 |
+
:return: over_frame, bool, 是否异常
|
| 503 |
+
"""
|
| 504 |
+
is_abnormal = False
|
| 505 |
+
if not text_str: # 标准数据未提供文本内容, 无从判断
|
| 506 |
+
return is_abnormal
|
| 507 |
+
if tag_text in text_str:
|
| 508 |
+
is_abnormal = True
|
| 509 |
+
return is_abnormal
|
| 510 |
+
|
| 511 |
+
@staticmethod
|
| 512 |
+
def error_trans(text_str, text_location, ocr_data, error_trans_marks, check_type='all'):
|
| 513 |
+
"""错误翻译检测
|
| 514 |
+
:param text_str: str, 待检测文本
|
| 515 |
+
:param text_location: list, 待检测文本位置 [ x_min, y_min, x_max, y_max]
|
| 516 |
+
:param ocr_data: ocr 识别结果数据
|
| 517 |
+
:param error_trans_marks: str, 错译标识
|
| 518 |
+
:param check_type: str, all 全局, single, 单文本框
|
| 519 |
+
:return: is_abnormal, bool, 是否异常
|
| 520 |
+
|
| 521 |
+
"""
|
| 522 |
+
is_abnormal = False
|
| 523 |
+
# 标注数据不存在错译, 可以直接返回, 无需检测
|
| 524 |
+
if not ErrorTrans.error_trans_mark(text_str, error_trans_marks):
|
| 525 |
+
return is_abnormal
|
| 526 |
+
if ocr_data and text_location and len(text_location) == 4:
|
| 527 |
+
if check_type == 'all' and text_location not in [[], None]: # 全局图像检测
|
| 528 |
+
is_abnormal = ErrorTrans.all_error_trans(text_location, ocr_data)
|
| 529 |
+
if check_type == 'single': # 单文本框检测
|
| 530 |
+
is_abnormal = ErrorTrans.single_error_trans(ocr_data, error_trans_marks)
|
| 531 |
+
return is_abnormal
|
| 532 |
+
|
| 533 |
+
@staticmethod
|
| 534 |
+
def text_overframe(ocr_location, text_location, t=(0, 0, 0, 0)):
|
| 535 |
+
"""文本超文本框
|
| 536 |
+
:param ocr_location: list, 识别的文本区域 [ x_min, y_min, x_max, y_max]
|
| 537 |
+
:param text_location: list, 待检测文本位置 [ x_min, y_min, x_max, y_max]
|
| 538 |
+
:param t: 上下左右阈值
|
| 539 |
+
:return: bool, 是否异常
|
| 540 |
+
"""
|
| 541 |
+
# 直接碰撞检测
|
| 542 |
+
return LqaProcessing.rect_collision_detection(ocr_location, text_location, t)
|
| 543 |
+
|
| 544 |
+
@staticmethod
|
| 545 |
+
def ocr_image_overlap(img, gt_image_info, ocr_location):
|
| 546 |
+
"""文本和图像重叠检测
|
| 547 |
+
:param img: ndarray, 图像
|
| 548 |
+
:param gt_image_info: dict, 标准图像框信息
|
| 549 |
+
:param ocr_location: dict, 文本框位置坐标 (x1, y1, x2, y2)
|
| 550 |
+
:return: collision, bool, 是否碰撞
|
| 551 |
+
image_location, 发生碰撞的图像框位置坐标 (x1, y1, x2, y2)
|
| 552 |
+
"""
|
| 553 |
+
collision = False
|
| 554 |
+
image_location = None
|
| 555 |
+
gt_image_locations = gt_image_info['gt_image_locations']
|
| 556 |
+
dirty_image_ids = gt_image_info['dirty_image_ids']
|
| 557 |
+
for i in range(len(gt_image_locations)):
|
| 558 |
+
if i in dirty_image_ids: # 脏图像框数据不检测
|
| 559 |
+
continue
|
| 560 |
+
image_location = gt_image_locations[i]
|
| 561 |
+
# 碰撞检测, 文本本身超过图像框
|
| 562 |
+
collision = LqaProcessing.rect_collision_detection(ocr_location, image_location, t=(5, 5, 5, 5))
|
| 563 |
+
if collision:
|
| 564 |
+
rectified_image_location = LqaProcessing.shrink_image_box(img, image_location)
|
| 565 |
+
collision = LqaProcessing.rect_collision_detection(ocr_location,
|
| 566 |
+
rectified_image_location,
|
| 567 |
+
t=(5, 5, 5, 5))
|
| 568 |
+
if collision:
|
| 569 |
+
break
|
| 570 |
+
return collision, image_location
|
| 571 |
+
|
| 572 |
+
@staticmethod
|
| 573 |
+
def judge_single_text(check_type, language, text_index, img, gt_image_info, gt_text_locations,
|
| 574 |
+
classify_text_location_res, all_ocr_dict, all_ocr_error_trans_dict,
|
| 575 |
+
no_trans_list, over_frame_text_text_list, over_frame_text_image_list,
|
| 576 |
+
no_key_list, error_trans_list, non_problem_list, non_rectangle_list,
|
| 577 |
+
text_location_list, lqa_img, rect_img, res, check_detail,
|
| 578 |
+
no_trans_marks, error_trans_marks, non_rectangle=False, project=None):
|
| 579 |
+
"""针对每一个文本框做判断和检查
|
| 580 |
+
:param check_type: list, 异常检测类型
|
| 581 |
+
:param language: int, 语种 id
|
| 582 |
+
:param text_index: int, 处理的第 text_index 个文本框
|
| 583 |
+
:param img: ndarray, 原图像
|
| 584 |
+
:param gt_image_info: dict, 标准图像框信息
|
| 585 |
+
:param gt_text_locations: list, 标准文本框位置信息
|
| 586 |
+
:param classify_text_location_res: dict, 文本框分类结果
|
| 587 |
+
:param all_ocr_dict: dict, 全图 ocr 识别结果
|
| 588 |
+
:param all_ocr_error_trans_dict, dict, 所有包含错误翻译标记的 ocr 识别结果
|
| 589 |
+
:param no_trans_list: list, 半监督漏译信息
|
| 590 |
+
:param over_frame_text_text_list: list, 半监督文本超框信息
|
| 591 |
+
:param over_frame_text_image_list: list, 半监督文本超图像框信息
|
| 592 |
+
:param no_key_list: list, 半监督漏 key 信息
|
| 593 |
+
:param error_trans_list: list, 半监督错译信息
|
| 594 |
+
:param non_problem_list: list, 半监督 non_problem 信息
|
| 595 |
+
:param non_rectangle_list: list, 半监督 non_rectangle 信息
|
| 596 |
+
:param text_location_list: list, 半监督预处理后的文本信息
|
| 597 |
+
:param lqa_img: ndarray, 结果图像
|
| 598 |
+
:param rect_img: ndarray, 标记图像
|
| 599 |
+
:param res: dict, 结果
|
| 600 |
+
:param check_detail: dict, 结果详情
|
| 601 |
+
:param no_trans_marks: str, 漏译标识
|
| 602 |
+
:param error_trans_marks: str, 错译标识
|
| 603 |
+
:param non_rectangle: bool, 非标框, 默认都是标准框, 非标框不做碰撞检测
|
| 604 |
+
:param project: str, 指定调用项目
|
| 605 |
+
:return: res, check_detail, rect_img, lqa_img
|
| 606 |
+
"""
|
| 607 |
+
# 判断每一个文本框
|
| 608 |
+
|
| 609 |
+
text_location_dict = text_location_list[text_index]
|
| 610 |
+
text_str = text_location_dict.get("textStr")
|
| 611 |
+
detail_data = [text_str, list(gt_text_locations[text_index])]
|
| 612 |
+
|
| 613 |
+
# 非标准框检测标记
|
| 614 |
+
check_type_id = LqaCheckType.NON_RECTANGLE.value
|
| 615 |
+
if check_type is None or str(check_type_id) in check_type:
|
| 616 |
+
if non_rectangle:
|
| 617 |
+
draw_style = DrawStyle.NON_RECTANGLE.value
|
| 618 |
+
res, check_detail, lqa_img = LqaAbnormal.update_check_res(res,
|
| 619 |
+
check_detail,
|
| 620 |
+
check_type_id,
|
| 621 |
+
detail_data,
|
| 622 |
+
non_rectangle_list,
|
| 623 |
+
lqa_img,
|
| 624 |
+
gt_text_locations[text_index],
|
| 625 |
+
draw_style)
|
| 626 |
+
|
| 627 |
+
# 自定义类型检测 non_problem 标记
|
| 628 |
+
check_type_id = LqaCheckType.NON_PROBLEM.value
|
| 629 |
+
if check_type is None or str(check_type_id) in check_type:
|
| 630 |
+
is_abnormal = LqaAbnormal.custom_abnormal(text_str, tag_text=NON_PROBLEM_MARK)
|
| 631 |
+
if is_abnormal:
|
| 632 |
+
draw_style = DrawStyle.NON_PROBLEM.value
|
| 633 |
+
res, check_detail, lqa_img = LqaAbnormal.update_check_res(res,
|
| 634 |
+
check_detail,
|
| 635 |
+
check_type_id,
|
| 636 |
+
detail_data,
|
| 637 |
+
non_problem_list,
|
| 638 |
+
lqa_img,
|
| 639 |
+
gt_text_locations[text_index],
|
| 640 |
+
draw_style)
|
| 641 |
+
|
| 642 |
+
# 漏译检测
|
| 643 |
+
check_type_id = LqaCheckType.NO_TRANS.value
|
| 644 |
+
if check_type is None or str(check_type_id) in check_type:
|
| 645 |
+
is_abnormal = LqaAbnormal.no_trans(text_str, no_trans_marks)
|
| 646 |
+
if is_abnormal:
|
| 647 |
+
draw_style = DrawStyle.NO_TRANS.value
|
| 648 |
+
res, check_detail, lqa_img = LqaAbnormal.update_check_res(res,
|
| 649 |
+
check_detail,
|
| 650 |
+
check_type_id,
|
| 651 |
+
detail_data,
|
| 652 |
+
no_trans_list,
|
| 653 |
+
lqa_img,
|
| 654 |
+
gt_text_locations[text_index],
|
| 655 |
+
draw_style)
|
| 656 |
+
# 漏key检测
|
| 657 |
+
check_type_id = LqaCheckType.NO_KEY.value
|
| 658 |
+
if check_type is None or str(check_type_id) in check_type:
|
| 659 |
+
is_abnormal = LqaAbnormal.no_key(text_str, language)
|
| 660 |
+
if is_abnormal:
|
| 661 |
+
draw_style = DrawStyle.NO_KEY.value
|
| 662 |
+
res, check_detail, lqa_img = LqaAbnormal.update_check_res(res,
|
| 663 |
+
check_detail,
|
| 664 |
+
check_type_id,
|
| 665 |
+
detail_data,
|
| 666 |
+
no_key_list,
|
| 667 |
+
lqa_img,
|
| 668 |
+
gt_text_locations[text_index],
|
| 669 |
+
draw_style)
|
| 670 |
+
|
| 671 |
+
# 错译-全局判断
|
| 672 |
+
check_type_id = LqaCheckType.ERROR_TRANS.value
|
| 673 |
+
if check_type is None or str(check_type_id) in check_type:
|
| 674 |
+
is_abnormal = LqaAbnormal.error_trans(text_str,
|
| 675 |
+
gt_text_locations[text_index],
|
| 676 |
+
all_ocr_error_trans_dict,
|
| 677 |
+
error_trans_marks,
|
| 678 |
+
check_type='all')
|
| 679 |
+
if is_abnormal:
|
| 680 |
+
draw_style = DrawStyle.ERROR_TRANS.value
|
| 681 |
+
res, check_detail, lqa_img = LqaAbnormal.update_check_res(res,
|
| 682 |
+
check_detail,
|
| 683 |
+
check_type_id,
|
| 684 |
+
detail_data,
|
| 685 |
+
error_trans_list,
|
| 686 |
+
lqa_img,
|
| 687 |
+
gt_text_locations[text_index],
|
| 688 |
+
draw_style)
|
| 689 |
+
|
| 690 |
+
# 独立无重叠的文本框 (排除非标框)
|
| 691 |
+
if not non_rectangle and text_index in classify_text_location_res['independent_id']:
|
| 692 |
+
x1, y1, x2, y2 = gt_text_locations[text_index]
|
| 693 |
+
text_location = (x1, y1, x2, y2)
|
| 694 |
+
res, check_detail, rect_img, lqa_img = LqaAbnormal.judge_single_independent_text(
|
| 695 |
+
check_type, text_index, text_location, text_str, img, gt_image_info, gt_text_locations, all_ocr_dict,
|
| 696 |
+
over_frame_text_text_list, over_frame_text_image_list, error_trans_list,
|
| 697 |
+
lqa_img, rect_img, res, check_detail, error_trans_marks, project=project)
|
| 698 |
+
return res, check_detail, rect_img, lqa_img
|
| 699 |
+
|
| 700 |
+
@staticmethod
|
| 701 |
+
def judge_single_independent_text(check_type, text_index, text_location, text_str,
|
| 702 |
+
img, gt_image_info, gt_text_locations, all_ocr_dict,
|
| 703 |
+
over_frame_text_text_list, over_frame_text_image_list, error_trans_list,
|
| 704 |
+
lqa_img, rect_img, res, check_detail, error_trans_marks, project=None):
|
| 705 |
+
"""检测每一个独立文本框
|
| 706 |
+
:param check_type: list, 异常检测类型
|
| 707 |
+
:param text_index: int, 处理的第 text_index 个文本框
|
| 708 |
+
:param text_location: 文本位置信息
|
| 709 |
+
:param text_str: str, 文本内容
|
| 710 |
+
:param img: ndarray, 原图像
|
| 711 |
+
:param gt_image_info: dict, 标准图像框信息
|
| 712 |
+
:param gt_text_locations: list, 标准文本框位置信息
|
| 713 |
+
:param all_ocr_dict: dict, 全图ocr识别结果
|
| 714 |
+
:param over_frame_text_text_list: list, 半监督文本超框信息
|
| 715 |
+
:param over_frame_text_image_list: list, 半监督文本超图像框信息
|
| 716 |
+
:param error_trans_list: list, 半监督错译信息
|
| 717 |
+
:param lqa_img: ndarray, 结果图像
|
| 718 |
+
:param rect_img: ndarray, 标记图像
|
| 719 |
+
:param res: dict, 结果
|
| 720 |
+
:param check_detail: dict, 结果详情
|
| 721 |
+
:param error_trans_marks: str, 错译标识
|
| 722 |
+
:param project: str, 指定调用项目
|
| 723 |
+
:return: res, check_detail, rect_img, lqa_img
|
| 724 |
+
"""
|
| 725 |
+
# 判断单个文本框
|
| 726 |
+
detail_data = [text_str, list(gt_text_locations[text_index])]
|
| 727 |
+
# 判断是否需要扩展
|
| 728 |
+
extend, img_location, text_data = LqaProcessing.judge_ocr_location_extend(img, text_location, text_str,
|
| 729 |
+
project=project)
|
| 730 |
+
if text_data is None or img_location is None:
|
| 731 |
+
return res, check_detail, rect_img, lqa_img
|
| 732 |
+
# 文本框 ocr 位置校准微调
|
| 733 |
+
align_res, _ = LqaProcessing.align_ocr_location(text_location, img_location, text_data, all_ocr_dict,
|
| 734 |
+
extend=extend)
|
| 735 |
+
if len(align_res) != 1:
|
| 736 |
+
return res, check_detail, rect_img, lqa_img
|
| 737 |
+
# 文本框 ocr 位置校准微调
|
| 738 |
+
ocr_x1, ocr_y1, ocr_x2, ocr_y2 = align_res[0]
|
| 739 |
+
rect_img = img_draw_rect(rect_img, align_res[0], draw_style=DrawStyle.OCR.value)
|
| 740 |
+
|
| 741 |
+
# 错译-单文本框检测
|
| 742 |
+
check_type_id = LqaCheckType.ERROR_TRANS.value
|
| 743 |
+
if check_type is None or str(check_type_id) in check_type:
|
| 744 |
+
is_abnormal = LqaAbnormal.error_trans(text_str,
|
| 745 |
+
gt_text_locations[text_index],
|
| 746 |
+
text_data,
|
| 747 |
+
error_trans_marks,
|
| 748 |
+
check_type='single')
|
| 749 |
+
if is_abnormal:
|
| 750 |
+
draw_style = DrawStyle.ERROR_TRANS.value
|
| 751 |
+
res, check_detail, lqa_img = LqaAbnormal.update_check_res(res,
|
| 752 |
+
check_detail,
|
| 753 |
+
check_type_id,
|
| 754 |
+
detail_data,
|
| 755 |
+
error_trans_list,
|
| 756 |
+
lqa_img,
|
| 757 |
+
gt_text_locations[text_index],
|
| 758 |
+
draw_style)
|
| 759 |
+
|
| 760 |
+
# 文本超文本框检测
|
| 761 |
+
type_id = LqaCheckType.OVER_FRAME.value
|
| 762 |
+
sub_type_id = LqaCheckSubType.OVER_FRAME_TEXT_TEXT.value
|
| 763 |
+
check_type_id = str(type_id) + "-" + str(sub_type_id)
|
| 764 |
+
if check_type is None or check_type_id in check_type:
|
| 765 |
+
is_abnormal = LqaAbnormal.text_overframe((ocr_x1, ocr_y1, ocr_x2, ocr_y2), text_location,
|
| 766 |
+
t=(5, 5, 5, 5))
|
| 767 |
+
if is_abnormal:
|
| 768 |
+
draw_style = DrawStyle.GT_TEXT.value
|
| 769 |
+
res, check_detail, lqa_img = LqaAbnormal.update_check_res(res,
|
| 770 |
+
check_detail,
|
| 771 |
+
type_id,
|
| 772 |
+
detail_data,
|
| 773 |
+
over_frame_text_text_list,
|
| 774 |
+
lqa_img,
|
| 775 |
+
gt_text_locations[text_index],
|
| 776 |
+
draw_style,
|
| 777 |
+
sub_type_id=sub_type_id)
|
| 778 |
+
# 文本框和图像框重叠
|
| 779 |
+
type_id = LqaCheckType.OVER_FRAME.value
|
| 780 |
+
sub_type_id = LqaCheckSubType.OVER_FRAME_TEXT_IMAGE.value
|
| 781 |
+
check_type_id = str(type_id) + "-" + str(sub_type_id)
|
| 782 |
+
if check_type is None or check_type_id in check_type:
|
| 783 |
+
ocr_location = (ocr_x1, ocr_y1, ocr_x2, ocr_y2)
|
| 784 |
+
collision, image_location = LqaAbnormal.ocr_image_overlap(img, gt_image_info, ocr_location)
|
| 785 |
+
if collision and image_location is not None:
|
| 786 |
+
detail_data = [text_str, list(gt_text_locations[text_index]), list(image_location)]
|
| 787 |
+
draw_style = DrawStyle.GT_TEXT.value
|
| 788 |
+
res, check_detail, lqa_img = LqaAbnormal.update_check_res(res,
|
| 789 |
+
check_detail,
|
| 790 |
+
type_id,
|
| 791 |
+
detail_data,
|
| 792 |
+
over_frame_text_image_list,
|
| 793 |
+
lqa_img,
|
| 794 |
+
ocr_location,
|
| 795 |
+
draw_style,
|
| 796 |
+
sub_type_id=sub_type_id)
|
| 797 |
+
return res, check_detail, rect_img, lqa_img
|
| 798 |
+
|
| 799 |
+
@staticmethod
|
| 800 |
+
def judge_single_group_overlap_text(check_type, group_index, overlap_group, overlap_group_id,
|
| 801 |
+
img, gt_text_locations, all_ocr_dict,
|
| 802 |
+
classify_text_location_res, text_location_list,
|
| 803 |
+
overlap_list, over_frame_text_text_list, error_trans_list,
|
| 804 |
+
lqa_img, rect_img, res, check_detail, error_trans_marks,
|
| 805 |
+
project=None):
|
| 806 |
+
"""检测每一组重叠文本框
|
| 807 |
+
:param check_type: list, 异常检测类型
|
| 808 |
+
:param group_index: int, 处理的第 group_index 组文本框
|
| 809 |
+
:param overlap_group: list, 重叠文本框信息
|
| 810 |
+
:param overlap_group_id: list, 重叠文本框分组信息 (记录文本框索引)
|
| 811 |
+
:param img: ndarray, 原图像
|
| 812 |
+
:param gt_text_locations: list, 标准文本框位置信息
|
| 813 |
+
:param all_ocr_dict: dict, 全图 ocr 识别结果
|
| 814 |
+
:param classify_text_location_res: dict, 文本框分类结果
|
| 815 |
+
:param text_location_list: dict, 预处理后文本框信息
|
| 816 |
+
:param overlap_list: list, 半监督文本框重叠信息
|
| 817 |
+
:param over_frame_text_text_list: list, 半监督文本超框信息
|
| 818 |
+
:param error_trans_list: list, 半监督错译信息
|
| 819 |
+
:param lqa_img: ndarray, 结果图像
|
| 820 |
+
:param rect_img: ndarray, 标记图像
|
| 821 |
+
:param res: dict, 结果
|
| 822 |
+
:param check_detail: dict, 结果详情
|
| 823 |
+
:param error_trans_marks: str, 错译标识
|
| 824 |
+
:param project: str, 指定调用项目
|
| 825 |
+
:return: res, check_detail, rect_img, lqa_img
|
| 826 |
+
"""
|
| 827 |
+
x1, y1, x2, y2 = overlap_group[group_index]
|
| 828 |
+
group_id = overlap_group_id[group_index]
|
| 829 |
+
img_location = img[y1:y2, x1: x2]
|
| 830 |
+
text_data = ocr(mat_to_base64(img_location), project=project)
|
| 831 |
+
if not text_data:
|
| 832 |
+
return res, check_detail, rect_img, lqa_img
|
| 833 |
+
text_location = (x1, y1, x2, y2)
|
| 834 |
+
align_res, align_ocr_res = LqaProcessing.align_ocr_location(text_location, img_location,
|
| 835 |
+
text_data, all_ocr_dict,
|
| 836 |
+
merge_location=False,
|
| 837 |
+
extend=False)
|
| 838 |
+
# 判断重叠文本框归属
|
| 839 |
+
overlap_info = OverlapText.judge_overlap_ocr_belong(align_res, align_ocr_res, group_id,
|
| 840 |
+
gt_text_locations)
|
| 841 |
+
# OCR 识别结果和重叠文本框数相同
|
| 842 |
+
if len(overlap_info) == len(group_id):
|
| 843 |
+
supervised_info = {'error_trans': error_trans_list,
|
| 844 |
+
'over_frame_text_text': over_frame_text_text_list
|
| 845 |
+
}
|
| 846 |
+
res, check_detail, rect_img, lqa_img = OverlapText.check_every_overlap_ocr(check_type,
|
| 847 |
+
rect_img,
|
| 848 |
+
lqa_img,
|
| 849 |
+
overlap_info,
|
| 850 |
+
text_location_list,
|
| 851 |
+
gt_text_locations,
|
| 852 |
+
res,
|
| 853 |
+
check_detail,
|
| 854 |
+
supervised_info,
|
| 855 |
+
error_trans_marks)
|
| 856 |
+
else:
|
| 857 |
+
group_text_id = classify_text_location_res['overlap_group_id'][group_index]
|
| 858 |
+
detail_data = OverlapText.sorted_detail_data(group_text_id, text_location_list, gt_text_locations)
|
| 859 |
+
supervised_info = {'overlap': overlap_list}
|
| 860 |
+
for g_id in overlap_info:
|
| 861 |
+
# 判断每个文本框
|
| 862 |
+
for overlap_item_i in overlap_info[g_id]:
|
| 863 |
+
res, check_detail, rect_img, lqa_img = OverlapText.recheck_every_overlap_ocr(
|
| 864 |
+
check_type, img, rect_img, lqa_img, overlap_item_i, group_id, gt_text_locations,
|
| 865 |
+
res, check_detail, detail_data, supervised_info)
|
| 866 |
+
return res, check_detail, rect_img, lqa_img
|
| 867 |
+
|
| 868 |
+
@staticmethod
|
| 869 |
+
def judge_single_text_no_ocr(check_type, language, text_index, img, gt_image_info, gt_text_locations, overlap_dict,
|
| 870 |
+
all_ocr_dict, all_ocr_error_trans_dict,
|
| 871 |
+
no_trans_list, error_trans_list, over_frame_text_text_list, over_frame_text_image_list,
|
| 872 |
+
no_key_list, non_problem_list, non_rectangle_list,
|
| 873 |
+
text_location_list, lqa_img, rect_img, res, check_detail,
|
| 874 |
+
no_trans_marks, error_trans_marks, non_rectangle=False, project=None):
|
| 875 |
+
"""针对每一个文本框做判断和检查 (精准位置, 无 ocr 检测)
|
| 876 |
+
:param check_type: list, 异常检测类型
|
| 877 |
+
:param language: int, 语种 id
|
| 878 |
+
:param text_index: int, 处理的第 text_index 个文本框
|
| 879 |
+
:param img: ndarray, 原图像
|
| 880 |
+
:param gt_image_info: dict, 标准图像框信息
|
| 881 |
+
:param gt_text_locations: list, 标准文本框位置信息
|
| 882 |
+
:param all_ocr_dict: dict, 全图ocr识别结果
|
| 883 |
+
:param all_ocr_error_trans_dict, dict, 所有包含错误翻译标记的 ocr 识别结果
|
| 884 |
+
:param no_trans_list: list, 半监督漏译信息
|
| 885 |
+
:param error_trans_list: list, 半监督错译信息
|
| 886 |
+
:param over_frame_text_text_list: list, 半监督文本超框信息
|
| 887 |
+
:param over_frame_text_image_list: list, 半监督文本超图像框信息
|
| 888 |
+
:param no_key_list: list, 半监督漏 key 信息
|
| 889 |
+
:param non_problem_list: list, 半监督 non_problem 信息
|
| 890 |
+
:param non_rectangle_list: list, 半监督 non_rectangle 信息
|
| 891 |
+
:param text_location_list: list, 半监督预处理后的文本信息
|
| 892 |
+
:param lqa_img: ndarray, 结果图像
|
| 893 |
+
:param rect_img: ndarray, 标记图像
|
| 894 |
+
:param res: dict, 结果
|
| 895 |
+
:param check_detail: dict, 结果详情
|
| 896 |
+
:param no_trans_marks: str, 漏译标识
|
| 897 |
+
:param error_trans_marks: str, 错译标识
|
| 898 |
+
:param non_rectangle: bool, 非标框, 默认都是标准框, 非标框不做碰撞检测
|
| 899 |
+
:param project: str, 指定调用项目
|
| 900 |
+
:return: res, check_detail, rect_img, lqa_img
|
| 901 |
+
"""
|
| 902 |
+
# 判断每一个文本框
|
| 903 |
+
|
| 904 |
+
text_location_dict = text_location_list[text_index]
|
| 905 |
+
text_str = text_location_dict.get("textStr")
|
| 906 |
+
detail_data = [text_str, list(gt_text_locations[text_index])]
|
| 907 |
+
|
| 908 |
+
# 非标准框检测标记
|
| 909 |
+
check_type_id = LqaCheckType.NON_RECTANGLE.value
|
| 910 |
+
if check_type is None or str(check_type_id) in check_type:
|
| 911 |
+
if non_rectangle:
|
| 912 |
+
draw_style = DrawStyle.NON_RECTANGLE.value
|
| 913 |
+
res, check_detail, lqa_img = LqaAbnormal.update_check_res(res,
|
| 914 |
+
check_detail,
|
| 915 |
+
check_type_id,
|
| 916 |
+
detail_data,
|
| 917 |
+
non_rectangle_list,
|
| 918 |
+
lqa_img,
|
| 919 |
+
gt_text_locations[text_index],
|
| 920 |
+
draw_style)
|
| 921 |
+
|
| 922 |
+
# 错译-全局判断
|
| 923 |
+
check_type_id = LqaCheckType.ERROR_TRANS.value
|
| 924 |
+
if check_type is None or str(check_type_id) in check_type:
|
| 925 |
+
is_abnormal = LqaAbnormal.error_trans(text_str,
|
| 926 |
+
gt_text_locations[text_index],
|
| 927 |
+
all_ocr_error_trans_dict,
|
| 928 |
+
error_trans_marks,
|
| 929 |
+
check_type='all')
|
| 930 |
+
if is_abnormal:
|
| 931 |
+
draw_style = DrawStyle.ERROR_TRANS.value
|
| 932 |
+
res, check_detail, lqa_img = LqaAbnormal.update_check_res(res,
|
| 933 |
+
check_detail,
|
| 934 |
+
check_type_id,
|
| 935 |
+
detail_data,
|
| 936 |
+
error_trans_list,
|
| 937 |
+
lqa_img,
|
| 938 |
+
gt_text_locations[text_index],
|
| 939 |
+
draw_style)
|
| 940 |
+
|
| 941 |
+
# 自定义类型检测 non_problem 标记
|
| 942 |
+
check_type_id = LqaCheckType.NON_PROBLEM.value
|
| 943 |
+
if check_type is None or str(check_type_id) in check_type:
|
| 944 |
+
is_abnormal = LqaAbnormal.custom_abnormal(text_str, tag_text=NON_PROBLEM_MARK)
|
| 945 |
+
if is_abnormal:
|
| 946 |
+
draw_style = DrawStyle.NON_PROBLEM.value
|
| 947 |
+
res, check_detail, lqa_img = LqaAbnormal.update_check_res(res,
|
| 948 |
+
check_detail,
|
| 949 |
+
check_type_id,
|
| 950 |
+
detail_data,
|
| 951 |
+
non_problem_list,
|
| 952 |
+
lqa_img,
|
| 953 |
+
gt_text_locations[text_index],
|
| 954 |
+
draw_style)
|
| 955 |
+
|
| 956 |
+
# 漏译检测
|
| 957 |
+
check_type_id = LqaCheckType.NO_TRANS.value
|
| 958 |
+
if check_type is None or str(check_type_id) in check_type:
|
| 959 |
+
is_abnormal = LqaAbnormal.no_trans(text_str, no_trans_marks)
|
| 960 |
+
if is_abnormal:
|
| 961 |
+
draw_style = DrawStyle.NO_TRANS.value
|
| 962 |
+
res, check_detail, lqa_img = LqaAbnormal.update_check_res(res,
|
| 963 |
+
check_detail,
|
| 964 |
+
check_type_id,
|
| 965 |
+
detail_data,
|
| 966 |
+
no_trans_list,
|
| 967 |
+
lqa_img,
|
| 968 |
+
gt_text_locations[text_index],
|
| 969 |
+
draw_style)
|
| 970 |
+
# 漏 key 检测
|
| 971 |
+
check_type_id = LqaCheckType.NO_KEY.value
|
| 972 |
+
if check_type is None or str(check_type_id) in check_type:
|
| 973 |
+
is_abnormal = LqaAbnormal.no_key(text_str, language)
|
| 974 |
+
if is_abnormal:
|
| 975 |
+
draw_style = DrawStyle.NO_KEY.value
|
| 976 |
+
res, check_detail, lqa_img = LqaAbnormal.update_check_res(res,
|
| 977 |
+
check_detail,
|
| 978 |
+
check_type_id,
|
| 979 |
+
detail_data,
|
| 980 |
+
no_key_list,
|
| 981 |
+
lqa_img,
|
| 982 |
+
gt_text_locations[text_index],
|
| 983 |
+
draw_style)
|
| 984 |
+
|
| 985 |
+
if not non_rectangle: # 标准文本框
|
| 986 |
+
x1, y1, x2, y2 = gt_text_locations[text_index]
|
| 987 |
+
|
| 988 |
+
# 文本框和文本框重叠
|
| 989 |
+
type_id = LqaCheckType.OVER_FRAME.value
|
| 990 |
+
sub_type_id = LqaCheckSubType.OVER_FRAME_TEXT_TEXT.value
|
| 991 |
+
check_type_id = str(type_id) + "-" + str(sub_type_id)
|
| 992 |
+
if check_type is None or check_type_id in check_type:
|
| 993 |
+
is_abnormal = True if len(overlap_dict[text_index]) > 1 else False
|
| 994 |
+
if is_abnormal:
|
| 995 |
+
draw_style = DrawStyle.GT_TEXT.value
|
| 996 |
+
res, check_detail, lqa_img = LqaAbnormal.update_check_res(res,
|
| 997 |
+
check_detail,
|
| 998 |
+
type_id,
|
| 999 |
+
detail_data,
|
| 1000 |
+
over_frame_text_text_list,
|
| 1001 |
+
lqa_img,
|
| 1002 |
+
gt_text_locations[text_index],
|
| 1003 |
+
draw_style,
|
| 1004 |
+
sub_type_id=sub_type_id)
|
| 1005 |
+
|
| 1006 |
+
# 文本框和图像框重叠
|
| 1007 |
+
type_id = LqaCheckType.OVER_FRAME.value
|
| 1008 |
+
sub_type_id = LqaCheckSubType.OVER_FRAME_TEXT_IMAGE.value
|
| 1009 |
+
check_type_id = str(type_id) + "-" + str(sub_type_id)
|
| 1010 |
+
if check_type is None or check_type_id in check_type:
|
| 1011 |
+
ocr_location = (x1, y1, x2, y2)
|
| 1012 |
+
collision, image_location = LqaAbnormal.ocr_image_overlap(img, gt_image_info, ocr_location)
|
| 1013 |
+
if collision and image_location is not None:
|
| 1014 |
+
detail_data = [text_str, list(gt_text_locations[text_index]), list(image_location)]
|
| 1015 |
+
draw_style = DrawStyle.GT_TEXT.value
|
| 1016 |
+
res, check_detail, lqa_img = LqaAbnormal.update_check_res(res,
|
| 1017 |
+
check_detail,
|
| 1018 |
+
type_id,
|
| 1019 |
+
detail_data,
|
| 1020 |
+
over_frame_text_image_list,
|
| 1021 |
+
lqa_img,
|
| 1022 |
+
ocr_location,
|
| 1023 |
+
draw_style,
|
| 1024 |
+
sub_type_id=sub_type_id)
|
| 1025 |
+
return res, check_detail, rect_img, lqa_img
|
| 1026 |
+
|
| 1027 |
+
|
| 1028 |
+
if __name__ == '__main__':
|
| 1029 |
+
pass
|
timi_hok_game_translator/LQA_WMP/lqa_service/task/lqa_config.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: lqa_config.py
|
| 4 |
+
# @desc: LQA 本地化检测相关配置, 定义以下枚举:
|
| 5 |
+
# - LqaCheckType: 检测问题类型 (漏译/超框/漏key/文本框重叠/错译/自定义non_problem/非标准框)
|
| 6 |
+
# - LqaCheckSubType: 超框问题的细分子类型 (文本超文本框/文本超图像框)
|
| 7 |
+
# - DrawStyle: 各类检测结果在图像上标注时使用的颜色 (RGB) 及线宽样式
|
| 8 |
+
# - Language: 支持检测的语言类型 (简体中文/繁体中文/英文/日文/泰文/越南文)
|
| 9 |
+
"""
|
| 10 |
+
from enum import Enum
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class LqaCheckType(Enum):
|
| 14 |
+
NO_TRANS = 1 # 漏译
|
| 15 |
+
OVER_FRAME = 2 # 超框
|
| 16 |
+
NO_KEY = 3 # 漏key
|
| 17 |
+
OVERLAP = 4 # 文本框重叠
|
| 18 |
+
ERROR_TRANS = 5 # 错译
|
| 19 |
+
NON_PROBLEM = 6 # non_problem 自定义
|
| 20 |
+
NON_RECTANGLE = 7 # 非标准框
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class LqaCheckSubType(Enum):
|
| 24 |
+
OVER_FRAME_TEXT_TEXT = 0 # 文本超文本框
|
| 25 |
+
OVER_FRAME_TEXT_IMAGE = 1 # 文本超图像框
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# 结果标记样式
|
| 29 |
+
class DrawStyle(Enum):
|
| 30 |
+
GT_IMG = ((255, 255, 255), 2)
|
| 31 |
+
GT_TEXT = ((0, 0, 255), 2)
|
| 32 |
+
OCR = ((0, 255, 0), 1)
|
| 33 |
+
NO_TRANS = ((0, 140, 255), 4)
|
| 34 |
+
OVER_FRAME = ((0, 0, 255), 2)
|
| 35 |
+
NO_KEY = ((0, 255, 255), 3)
|
| 36 |
+
OVERLAP = ((255, 0, 255), 1)
|
| 37 |
+
ERROR_TRANS = ((255, 255, 0), 5)
|
| 38 |
+
NON_PROBLEM = ((255, 0, 0), 4)
|
| 39 |
+
NON_RECTANGLE = ((255, 0, 255), 2)
|
| 40 |
+
PRE_ERR = ((255, 0, 255), 5)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class Language(Enum):
|
| 44 |
+
zh_CN = 0 # 简体中文
|
| 45 |
+
zh_TW = 1 # 繁体中文 (台湾)
|
| 46 |
+
en = 2 # 英文
|
| 47 |
+
ja_JP = 3 # 日文
|
| 48 |
+
th = 4 # 泰文
|
| 49 |
+
vn = 5 # 越南
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
if __name__ == '__main__':
|
| 53 |
+
pass
|
timi_hok_game_translator/LQA_WMP/lqa_service/task/lqa_processing.py
ADDED
|
@@ -0,0 +1,638 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: lqa_processing.py
|
| 4 |
+
# @desc: LQA 本地化检测相关数据预处理工具模块, 提供 LqaProcessing 类实现以下能力:
|
| 5 |
+
# - judge_rectangle/coordinate_trans: 判断四点坐标是否为标准矩形框, 并将左下角为原点的
|
| 6 |
+
# 坐标体系转换为图像坐标系 (x1,y1,x2,y2 或 四点坐标)
|
| 7 |
+
# - is_dirty_text/detect_gt_text_locations/detect_gt_image_locations: 提取标准文本框/
|
| 8 |
+
# 图像框位置信息,过滤尺寸异常、越界、空文本等脏数据,并标记非标准 (非矩形) 框
|
| 9 |
+
# - draw_gt_locations: 在图像上绘制标准文本框/图像框及非标准框的标注样式
|
| 10 |
+
# - detect_ocr_data/filter_text_data/get_join_ocr_result: 调用 OCR 识别图像文本,
|
| 11 |
+
# 并按标准文本框归属过滤、聚合 OCR 结果
|
| 12 |
+
# - overlap/rect_collision_detection: 矩形碰撞检测, 判断两个矩形是否存在重叠/碰撞关系
|
| 13 |
+
# - judge_overlap_with_text_i/merge_and_update_overlap/get_overlap_group_data/
|
| 14 |
+
# save_single_group_classify_res/classify_text_location_overlap: 对所有文本框两两判断
|
| 15 |
+
# 重叠关系并分组合并, 将文本框分类为独立文本框和重叠文本框组 (取最小外接矩形)
|
| 16 |
+
# - judge_ocr_location_extend/align_single_ocr_location/align_ocr_location: 根据 OCR
|
| 17 |
+
# 识别结果对文本框区域进行扩展判断和位置微调校准, 提升文本定位精度
|
| 18 |
+
# - shrink_image_box: 基于连通域分析, 将图像框收缩到实际前景内容的最小外接矩形
|
| 19 |
+
"""
|
| 20 |
+
import math
|
| 21 |
+
import cv2
|
| 22 |
+
import numpy as np
|
| 23 |
+
from common.interface_ocr import ocr
|
| 24 |
+
from common.tools import mat_to_base64
|
| 25 |
+
from task.lqa_config import DrawStyle
|
| 26 |
+
from common.tools import img_draw_rect
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class LqaProcessing:
|
| 30 |
+
"""lqa 数据预处理类"""
|
| 31 |
+
|
| 32 |
+
@staticmethod
|
| 33 |
+
def judge_rectangle(location_dict):
|
| 34 |
+
"""判断是否是标准文本框
|
| 35 |
+
:param location_dict: dict, 位置信息
|
| 36 |
+
:param height: int, 图像高度
|
| 37 |
+
:return: 判断是否是标准矩形框
|
| 38 |
+
"""
|
| 39 |
+
x1 = int(location_dict["corners"][0]["x"])
|
| 40 |
+
y1 = int(location_dict["corners"][0]["y"])
|
| 41 |
+
x2 = int(location_dict["corners"][1]["x"])
|
| 42 |
+
y2 = int(location_dict["corners"][1]["y"])
|
| 43 |
+
x3 = int(location_dict["corners"][2]["x"])
|
| 44 |
+
y3 = int(location_dict["corners"][2]["y"])
|
| 45 |
+
x4 = int(location_dict["corners"][3]["x"])
|
| 46 |
+
y4 = int(location_dict["corners"][3]["y"])
|
| 47 |
+
if x1 != x2 or x3 != x4 or y1 != y4 or y2 != y3:
|
| 48 |
+
return False
|
| 49 |
+
return True
|
| 50 |
+
|
| 51 |
+
@staticmethod
|
| 52 |
+
def coordinate_trans(location_dict, height, is_rectangle=True):
|
| 53 |
+
"""坐标变换, 提供的标准数据 text 和 image 的矩形框位置信息是以左下角为原点
|
| 54 |
+
:param location_dict: dict, 位置信息
|
| 55 |
+
:param height: int, 图像高度
|
| 56 |
+
:param is_rectangle: bool, 默认标准文本框, 返回思维向量, 否则保持原 4 个点坐标
|
| 57 |
+
:return: 转化后的位置坐标 (x1, y1, x2, y2)
|
| 58 |
+
"""
|
| 59 |
+
if is_rectangle:
|
| 60 |
+
x1 = int(location_dict["corners"][1]["x"])
|
| 61 |
+
y1 = height - int(location_dict["corners"][1]["y"])
|
| 62 |
+
x2 = int(location_dict["corners"][3]["x"])
|
| 63 |
+
y2 = height - int(location_dict["corners"][3]["y"])
|
| 64 |
+
trans_location = (x1, y1, x2, y2)
|
| 65 |
+
else:
|
| 66 |
+
x1 = int(location_dict["corners"][0]["x"])
|
| 67 |
+
y1 = height - int(location_dict["corners"][0]["y"])
|
| 68 |
+
x2 = int(location_dict["corners"][1]["x"])
|
| 69 |
+
y2 = height - int(location_dict["corners"][1]["y"])
|
| 70 |
+
x3 = int(location_dict["corners"][2]["x"])
|
| 71 |
+
y3 = height - int(location_dict["corners"][2]["y"])
|
| 72 |
+
x4 = int(location_dict["corners"][3]["x"])
|
| 73 |
+
y4 = height - int(location_dict["corners"][3]["y"])
|
| 74 |
+
trans_location = (x1, y1, x2, y2, x3, y3, x4, y4)
|
| 75 |
+
return trans_location
|
| 76 |
+
|
| 77 |
+
@staticmethod
|
| 78 |
+
def is_dirty_text(text_location, text_location_dict, height, width):
|
| 79 |
+
"""判断是否是脏文本框 (尺寸不合理、无文本等)
|
| 80 |
+
:param text_location: list, 文本位置
|
| 81 |
+
:param text_location_dict: dict, 文本对应信息
|
| 82 |
+
:param height: int, 图像高
|
| 83 |
+
:param width: int, 图像宽
|
| 84 |
+
:return: bool, 是否是脏数据
|
| 85 |
+
"""
|
| 86 |
+
w = text_location[2] - text_location[0]
|
| 87 |
+
h = text_location[3] - text_location[1]
|
| 88 |
+
# 尺度太小
|
| 89 |
+
if w < 13 or h < 13:
|
| 90 |
+
return True
|
| 91 |
+
# 位置不合理
|
| 92 |
+
for i in range(4):
|
| 93 |
+
if text_location[i] < 0:
|
| 94 |
+
return True
|
| 95 |
+
if text_location[0] > width or text_location[2] > width:
|
| 96 |
+
return True
|
| 97 |
+
if text_location[1] > height or text_location[3] > height:
|
| 98 |
+
return True
|
| 99 |
+
# 无文本内容
|
| 100 |
+
text_str = text_location_dict.get("textStr")
|
| 101 |
+
if not text_str or text_str == '':
|
| 102 |
+
return True
|
| 103 |
+
return False
|
| 104 |
+
|
| 105 |
+
@staticmethod
|
| 106 |
+
def detect_gt_text_locations(img, text_location_list, preprocessing=False):
|
| 107 |
+
""" 提取所有标准文本框的位置信息, 进行坐标转换
|
| 108 |
+
:param img: ndarray, 图像
|
| 109 |
+
:param text_location_list: list, 标准文本框信息
|
| 110 |
+
:return: gt_text_info, dict, {'gt_text_locations': 文本框信息, 'dirty_text_ids': 脏文本框id,
|
| 111 |
+
'non_rectangle_ids': 非标框, preprocessing_err 预检测异常 {index: [error类型id列表]}}
|
| 112 |
+
"""
|
| 113 |
+
# 所有标准文本信息
|
| 114 |
+
height, width = img.shape[:2]
|
| 115 |
+
gt_text_info = {'gt_text_locations': [], 'dirty_text_ids': [], 'non_rectangle_ids': [],
|
| 116 |
+
'preprocessing_errs': {}}
|
| 117 |
+
text_list_temp = []
|
| 118 |
+
for i in range(len(text_location_list)):
|
| 119 |
+
text_location_dict = text_location_list[i]
|
| 120 |
+
if text_location_dict not in text_list_temp:
|
| 121 |
+
text_list_temp.append(text_location_dict)
|
| 122 |
+
else:
|
| 123 |
+
gt_text_info['dirty_text_ids'].append(i) # 去重
|
| 124 |
+
is_rectangle = LqaProcessing.judge_rectangle(text_location_dict)
|
| 125 |
+
text_location = LqaProcessing.coordinate_trans(text_location_dict, height, is_rectangle)
|
| 126 |
+
if is_rectangle:
|
| 127 |
+
# 过滤脏数据
|
| 128 |
+
is_dirty = LqaProcessing.is_dirty_text(text_location, text_location_dict, height, width)
|
| 129 |
+
if is_dirty and i not in gt_text_info['dirty_text_ids']:
|
| 130 |
+
gt_text_info['dirty_text_ids'].append(i)
|
| 131 |
+
else:
|
| 132 |
+
# 过滤非标框
|
| 133 |
+
gt_text_info['non_rectangle_ids'].append(i)
|
| 134 |
+
gt_text_info['gt_text_locations'].append(text_location)
|
| 135 |
+
|
| 136 |
+
# 预检测异常
|
| 137 |
+
if preprocessing and text_location_dict.get('preprocessing_err'):
|
| 138 |
+
gt_text_info['preprocessing_errs'].update({i: text_location_dict['preprocessing_err']})
|
| 139 |
+
return gt_text_info
|
| 140 |
+
|
| 141 |
+
@staticmethod
|
| 142 |
+
def detect_gt_image_locations(img, image_location_list):
|
| 143 |
+
"""提取所有标准图像框的位置信息, 进行坐标转换
|
| 144 |
+
:param img: ndarray, 图像
|
| 145 |
+
:param image_location_list: list, 标准图像框信息
|
| 146 |
+
:return: gt_image_info, dict, {'gt_image_locations': 图像框信息, 'dirty_text_ids': 脏图像框 id}
|
| 147 |
+
"""
|
| 148 |
+
height, width = img.shape[:2]
|
| 149 |
+
gt_image_info = {'gt_image_locations': [], 'dirty_image_ids': []}
|
| 150 |
+
image_list_temp = []
|
| 151 |
+
for i in range(len(image_location_list)):
|
| 152 |
+
# image 框
|
| 153 |
+
image_location_dict = image_location_list[i]
|
| 154 |
+
if image_location_dict not in image_list_temp:
|
| 155 |
+
image_list_temp.append(image_location_dict)
|
| 156 |
+
else:
|
| 157 |
+
gt_image_info['dirty_image_ids'].append(i) # 去重
|
| 158 |
+
image_location = LqaProcessing.coordinate_trans(image_location_dict, height)
|
| 159 |
+
if image_location[2] - image_location[0] < 13 or image_location[3] - image_location[1] < 13 \
|
| 160 |
+
or image_location[2] < 0 or image_location[3] < 0 \
|
| 161 |
+
or image_location[0] > width or image_location[1] > height:
|
| 162 |
+
gt_image_info['dirty_image_ids'].append(i)
|
| 163 |
+
gt_image_info['gt_image_locations'].append(image_location)
|
| 164 |
+
return gt_image_info
|
| 165 |
+
|
| 166 |
+
@staticmethod
|
| 167 |
+
def draw_gt_locations(rect_img, gt_text_info, gt_image_info):
|
| 168 |
+
"""绘制标记标准信息, 包括文本框和图像框
|
| 169 |
+
:param rect_img: ndarray, 图像
|
| 170 |
+
:param gt_text_info: dict, 标准文本框信息
|
| 171 |
+
:param gt_image_info: dict, 标准图像框信息
|
| 172 |
+
:return: 标记后的 rect_img
|
| 173 |
+
"""
|
| 174 |
+
gt_text_locations = gt_text_info['gt_text_locations']
|
| 175 |
+
dirty_text_ids = gt_text_info['dirty_text_ids']
|
| 176 |
+
non_rectangle_ids = gt_text_info['non_rectangle_ids']
|
| 177 |
+
for i in range(len(gt_text_locations)):
|
| 178 |
+
if i not in dirty_text_ids and i not in non_rectangle_ids: # 矩形
|
| 179 |
+
rect_img = img_draw_rect(rect_img, gt_text_locations[i], DrawStyle.GT_TEXT.value)
|
| 180 |
+
if i in non_rectangle_ids: # 非矩形
|
| 181 |
+
rect_img = img_draw_rect(rect_img, gt_text_locations[i], DrawStyle.NON_RECTANGLE.value)
|
| 182 |
+
gt_image_locations = gt_image_info['gt_image_locations']
|
| 183 |
+
dirty_image_ids = gt_image_info['dirty_image_ids']
|
| 184 |
+
for i in range(len(gt_image_locations)):
|
| 185 |
+
if i not in dirty_image_ids:
|
| 186 |
+
rect_img = img_draw_rect(rect_img, gt_image_locations[i], DrawStyle.GT_IMG.value)
|
| 187 |
+
return rect_img
|
| 188 |
+
|
| 189 |
+
@staticmethod
|
| 190 |
+
def detect_ocr_data(img, gt_text_info, project=None):
|
| 191 |
+
"""检测图像中所有 ocr, 同时过滤不属于标准框内的结果
|
| 192 |
+
:param img: ndarray, 图像
|
| 193 |
+
:param gt_text_info: dict, 标准文本框信息
|
| 194 |
+
:param project: str, 指定调用项目
|
| 195 |
+
:return: all_ocr_dict, 全图 OCR 识别结果
|
| 196 |
+
"""
|
| 197 |
+
# 标准信息
|
| 198 |
+
gt_text_locations = gt_text_info['gt_text_locations']
|
| 199 |
+
dirty_text_ids = gt_text_info['dirty_text_ids']
|
| 200 |
+
non_rectangle_ids = gt_text_info['non_rectangle_ids']
|
| 201 |
+
# 所有检测文本信息
|
| 202 |
+
all_ocr_dict = {}
|
| 203 |
+
text_data = ocr(mat_to_base64(img), project=project)
|
| 204 |
+
if not text_data: # OCR 未配置/不可用: 返回空结果, 由调用方跳过相关检测
|
| 205 |
+
return all_ocr_dict
|
| 206 |
+
for text_one in text_data:
|
| 207 |
+
ocr_result = text_one["result"]
|
| 208 |
+
if ocr_result and len(ocr_result) <= 0:
|
| 209 |
+
continue
|
| 210 |
+
ocr_x1, ocr_y1, ocr_x2, ocr_y2 = text_one["area"]
|
| 211 |
+
center_x = (ocr_x1 + ocr_x2) / 2
|
| 212 |
+
center_y = (ocr_y1 + ocr_y2) / 2
|
| 213 |
+
for i in range(len(gt_text_locations)):
|
| 214 |
+
if i in dirty_text_ids or i in non_rectangle_ids: # 脏标准框直接跳过
|
| 215 |
+
continue
|
| 216 |
+
x1, y1, x2, y2 = gt_text_locations[i]
|
| 217 |
+
if x1 < center_x < x2 and y1 < center_y < y2:
|
| 218 |
+
if ocr_result not in all_ocr_dict:
|
| 219 |
+
all_ocr_dict[ocr_result] = []
|
| 220 |
+
all_ocr_dict[ocr_result].append((ocr_x1, ocr_y1, ocr_x2, ocr_y2))
|
| 221 |
+
break
|
| 222 |
+
return all_ocr_dict
|
| 223 |
+
|
| 224 |
+
@staticmethod
|
| 225 |
+
def filter_text_data(gt_text_info, text_location_list):
|
| 226 |
+
"""直接从检测文件中提取 ocr 相关信息, 不需要检测
|
| 227 |
+
:param gt_text_info: 预处理的标准数据, 包括位置信息, 过滤脏数据的索引
|
| 228 |
+
:param text_location_list: list, 半监督预处理后的文本信息
|
| 229 |
+
:return: all_ocr_dict, 全图文本内容
|
| 230 |
+
"""
|
| 231 |
+
all_ocr_dict = {}
|
| 232 |
+
gt_text_locations = gt_text_info['gt_text_locations']
|
| 233 |
+
for text_index in range(len(gt_text_locations)):
|
| 234 |
+
if text_index in gt_text_info['dirty_text_ids']: # 脏标准框数据跳过
|
| 235 |
+
continue
|
| 236 |
+
x1, y1, x2, y2 = gt_text_locations[text_index]
|
| 237 |
+
text_location_dict = text_location_list[text_index]
|
| 238 |
+
text_str = text_location_dict.get("textStr")
|
| 239 |
+
all_ocr_dict[text_str].append((x1, y1, x2, y2))
|
| 240 |
+
return all_ocr_dict
|
| 241 |
+
|
| 242 |
+
@staticmethod
|
| 243 |
+
def overlap(rect1, rect2, x_t=10, y_t=5):
|
| 244 |
+
"""矩形碰撞检测, 有重叠交集为 True
|
| 245 |
+
:param rect1: 矩形框1位置, x1,y1,x2,y2 格式
|
| 246 |
+
:param rect2: 矩形框2位置, x1,y1,x2,y2 格式
|
| 247 |
+
:param x_t: int, 重叠区域 x方向阈值
|
| 248 |
+
:param y_t: int, 重叠区域 y方向阈值
|
| 249 |
+
:return: bool,是否重叠
|
| 250 |
+
ratio, str: 和 rect2 的重叠比率
|
| 251 |
+
(sub_x, sub_y): 和 rect2 的重叠比率
|
| 252 |
+
"""
|
| 253 |
+
# 重叠区域
|
| 254 |
+
x_min = max(rect1[0], rect2[0])
|
| 255 |
+
y_min = max(rect1[1], rect2[1])
|
| 256 |
+
x_max = min(rect1[2], rect2[2])
|
| 257 |
+
y_max = min(rect1[3], rect2[3])
|
| 258 |
+
ratio = 0
|
| 259 |
+
sub_x = 0
|
| 260 |
+
sub_y = 0
|
| 261 |
+
if x_max - x_min > x_t and y_max - y_min > y_t:
|
| 262 |
+
ratio = (x_max - x_min) * (y_max - y_min) / (rect2[2] - rect2[0]) / (rect2[3] - rect2[1])
|
| 263 |
+
sub_x = abs((x_max - x_min) - (rect2[2] - rect2[0]))
|
| 264 |
+
sub_y = abs((y_max - y_min) - (rect2[3] - rect2[1]))
|
| 265 |
+
return True, ratio, (sub_x, sub_y)
|
| 266 |
+
else:
|
| 267 |
+
return False, ratio, (sub_x, sub_y)
|
| 268 |
+
|
| 269 |
+
@staticmethod
|
| 270 |
+
def judge_overlap_with_text_i(overlap_dict, text_i, text_location_list, dirty_text_ids):
|
| 271 |
+
"""判断与 text_i 重叠的文本框, 保存在字典里 (只判断索引大于text_i, 减少重复计算)
|
| 272 |
+
:param overlap_dict: dict, 保存的重叠关系结果
|
| 273 |
+
:param text_i: int, 当前处理的文本框索引
|
| 274 |
+
:param text_location_list: list, 文本位置信息
|
| 275 |
+
:param dirty_text_ids: list, 脏文本框索引列表
|
| 276 |
+
:return: 更新的overlap_dict
|
| 277 |
+
"""
|
| 278 |
+
|
| 279 |
+
# 存储分类结果: 分别标记独立文本框和重叠文本框位置、索引
|
| 280 |
+
cnt = len(text_location_list)
|
| 281 |
+
overlap_dict[text_i] = [text_i]
|
| 282 |
+
for j in range(cnt):
|
| 283 |
+
if j > text_i and j not in dirty_text_ids:
|
| 284 |
+
# 重叠判断
|
| 285 |
+
is_overlap, _, _ = LqaProcessing.overlap(text_location_list[text_i], text_location_list[j])
|
| 286 |
+
if is_overlap and j not in overlap_dict[text_i]:
|
| 287 |
+
overlap_dict[text_i].append(j)
|
| 288 |
+
return overlap_dict
|
| 289 |
+
|
| 290 |
+
@staticmethod
|
| 291 |
+
def merge_and_update_overlap(temp_overlap_list, i_overlaps):
|
| 292 |
+
"""判断是否是一组重叠文本框, 合并更新分组 id
|
| 293 |
+
:param temp_overlap_list: list, 存储分组结果
|
| 294 |
+
:param i_overlaps: list, 第 i 个文本框判断的结果
|
| 295 |
+
:return: 更新后的 temp_overlap_list
|
| 296 |
+
"""
|
| 297 |
+
in_others = False
|
| 298 |
+
for k in i_overlaps:
|
| 299 |
+
for j in range(len(temp_overlap_list)):
|
| 300 |
+
if k in temp_overlap_list[j]:
|
| 301 |
+
in_others = True
|
| 302 |
+
temp_overlap_list[j].extend(i_overlaps)
|
| 303 |
+
break
|
| 304 |
+
if in_others:
|
| 305 |
+
break
|
| 306 |
+
if in_others:
|
| 307 |
+
i_overlaps = []
|
| 308 |
+
temp_overlap_list.append(i_overlaps)
|
| 309 |
+
return temp_overlap_list
|
| 310 |
+
|
| 311 |
+
@staticmethod
|
| 312 |
+
def get_overlap_group_data(gt_text_info):
|
| 313 |
+
"""获得分组的重叠文本框数据
|
| 314 |
+
:param gt_text_info: dict, 标准文本信息
|
| 315 |
+
:return: temp_overlap_dict, dict, 重叠文本框分组数据
|
| 316 |
+
"""
|
| 317 |
+
text_location_list = gt_text_info['gt_text_locations']
|
| 318 |
+
dirty_text_ids = gt_text_info['dirty_text_ids']
|
| 319 |
+
non_rectangle_ids = gt_text_info['non_rectangle_ids']
|
| 320 |
+
cnt = len(text_location_list)
|
| 321 |
+
|
| 322 |
+
# 判断文本框与后面文本框的重叠关系
|
| 323 |
+
overlap_dict = {}
|
| 324 |
+
for i in range(cnt):
|
| 325 |
+
if i in dirty_text_ids or i in non_rectangle_ids: # 脏数据过滤, 便于后续检测, 无需处理
|
| 326 |
+
continue
|
| 327 |
+
overlap_dict = LqaProcessing.judge_overlap_with_text_i(overlap_dict, i, text_location_list, dirty_text_ids)
|
| 328 |
+
|
| 329 |
+
# 合并文本框结果
|
| 330 |
+
temp_overlap_list = []
|
| 331 |
+
for i in range(cnt):
|
| 332 |
+
if i not in overlap_dict:
|
| 333 |
+
temp_overlap_list.append([]) # 脏数据占位, 保留索引
|
| 334 |
+
continue
|
| 335 |
+
i_overlaps = overlap_dict[i]
|
| 336 |
+
if len(temp_overlap_list) == 0:
|
| 337 |
+
temp_overlap_list.append(i_overlaps)
|
| 338 |
+
else:
|
| 339 |
+
# 判断、合并同组文本框
|
| 340 |
+
temp_overlap_list = LqaProcessing.merge_and_update_overlap(temp_overlap_list, i_overlaps)
|
| 341 |
+
|
| 342 |
+
temp_overlap_dict = {}
|
| 343 |
+
for i in range(cnt):
|
| 344 |
+
if len(temp_overlap_list[i]) > 0:
|
| 345 |
+
temp_overlap_dict[i] = list(set(temp_overlap_list[i]))
|
| 346 |
+
return temp_overlap_dict
|
| 347 |
+
|
| 348 |
+
@staticmethod
|
| 349 |
+
def save_single_group_classify_res(single_group_overlap, current_index, text_location_list,
|
| 350 |
+
classify_text_location_res):
|
| 351 |
+
"""根据一组文本框分类结果, 结果格式化和保存
|
| 352 |
+
:param single_group_overlap: dict, 单组重叠文本框 (保存的是对应文本框 index)
|
| 353 |
+
:param current_index: int, 当前处理的文本索引
|
| 354 |
+
:param text_location_list: list, 文本位置信息
|
| 355 |
+
:param classify_text_location_res: dict, 分类结果
|
| 356 |
+
:return:
|
| 357 |
+
"""
|
| 358 |
+
x_min_list = []
|
| 359 |
+
y_min_list = []
|
| 360 |
+
x_max_list = []
|
| 361 |
+
y_max_list = []
|
| 362 |
+
for item in single_group_overlap:
|
| 363 |
+
x1, y1, x2, y2 = text_location_list[item]
|
| 364 |
+
x_min_list.append(x1)
|
| 365 |
+
y_min_list.append(y1)
|
| 366 |
+
x_max_list.append(x2)
|
| 367 |
+
y_max_list.append(y2)
|
| 368 |
+
|
| 369 |
+
# 独立文本框
|
| 370 |
+
if len(x_min_list) == 1:
|
| 371 |
+
classify_text_location_res['independent'].append((x_min_list[0], y_min_list[0], x_max_list[0],
|
| 372 |
+
y_max_list[0]))
|
| 373 |
+
classify_text_location_res['independent_id'].append(current_index)
|
| 374 |
+
# 有重叠的文本框合并, 最小外接矩形
|
| 375 |
+
elif len(x_min_list) > 1:
|
| 376 |
+
group_x1 = np.min(x_min_list)
|
| 377 |
+
group_y1 = np.min(y_min_list)
|
| 378 |
+
group_x2 = np.max(x_max_list)
|
| 379 |
+
group_y2 = np.max(y_max_list)
|
| 380 |
+
classify_text_location_res['overlap_group'].append((group_x1, group_y1, group_x2, group_y2))
|
| 381 |
+
classify_text_location_res['overlap_group_id'].append(single_group_overlap)
|
| 382 |
+
return classify_text_location_res
|
| 383 |
+
|
| 384 |
+
@staticmethod
|
| 385 |
+
def classify_text_location_overlap(gt_text_info):
|
| 386 |
+
"""根据文本框是否有重叠进行分类
|
| 387 |
+
:param gt_text_info: dict, 提取的标准文本框信息
|
| 388 |
+
:return: dict, classify_text_location_res, 文本框分类结果信息
|
| 389 |
+
"""
|
| 390 |
+
# 存储分类结果: 分别标记独立文本框和重叠文本框位置、索引
|
| 391 |
+
classify_text_location_res = {'independent': [], 'independent_id': [],
|
| 392 |
+
'overlap_group': [], 'overlap_group_id': []}
|
| 393 |
+
text_location_list = gt_text_info['gt_text_locations']
|
| 394 |
+
dirty_text_ids = gt_text_info['dirty_text_ids']
|
| 395 |
+
|
| 396 |
+
# 是否有文本框需要判断
|
| 397 |
+
cnt = len(text_location_list)
|
| 398 |
+
if cnt - len(dirty_text_ids) <= 0:
|
| 399 |
+
return classify_text_location_res
|
| 400 |
+
# 获得分组的重叠文本框数据
|
| 401 |
+
temp_overlap_dict = LqaProcessing.get_overlap_group_data(gt_text_info)
|
| 402 |
+
|
| 403 |
+
# 按照分组的文本框结果, 保存格式化分类结果 (重叠文本框合并处理)
|
| 404 |
+
for i in temp_overlap_dict:
|
| 405 |
+
single_group_overlap = temp_overlap_dict[i]
|
| 406 |
+
if len(single_group_overlap) <= 0:
|
| 407 |
+
continue
|
| 408 |
+
classify_text_location_res = LqaProcessing.save_single_group_classify_res(single_group_overlap,
|
| 409 |
+
i,
|
| 410 |
+
text_location_list,
|
| 411 |
+
classify_text_location_res)
|
| 412 |
+
return classify_text_location_res
|
| 413 |
+
|
| 414 |
+
@staticmethod
|
| 415 |
+
def rect_collision_detection(rect1, rect2, t=(0, 0, 0, 0)):
|
| 416 |
+
"""矩形碰撞检测, 有交集且不包含为 True
|
| 417 |
+
:param rect1: 矩形框1位置, x1,y1,x2,y2 格式
|
| 418 |
+
:param rect2: 矩形框2位置, x1,y1,x2,y2 格式
|
| 419 |
+
:param t: 上下左右阈值
|
| 420 |
+
:return: bool, 是否存在碰撞
|
| 421 |
+
"""
|
| 422 |
+
# 无交集
|
| 423 |
+
if rect1[0] + t[0] > rect2[2] or rect1[2] < rect2[0] + t[1] \
|
| 424 |
+
or rect1[1] + t[2] > rect2[3] or rect1[3] < rect2[1] + t[3]:
|
| 425 |
+
return False
|
| 426 |
+
# 全包含
|
| 427 |
+
if rect2[0] - t[1] <= rect1[0] < rect1[2] <= rect2[2] + t[0] \
|
| 428 |
+
and rect2[1] - t[3] <= rect1[1] < rect1[3] <= rect2[3] + t[2]:
|
| 429 |
+
return False
|
| 430 |
+
return True
|
| 431 |
+
|
| 432 |
+
@staticmethod
|
| 433 |
+
def get_join_ocr_result(img, project=None):
|
| 434 |
+
"""识别图像的 ocr 结果, 并将结果聚合起来
|
| 435 |
+
:param img: ndarray, 图像数据
|
| 436 |
+
:param project: str, 指定调用项目
|
| 437 |
+
:return: text_data: ocr 识别结果
|
| 438 |
+
text_str: 聚合文本
|
| 439 |
+
"""
|
| 440 |
+
text_str = ''
|
| 441 |
+
text_data = ocr(mat_to_base64(img), project=project)
|
| 442 |
+
if not text_data:
|
| 443 |
+
return None, None
|
| 444 |
+
for text_one in text_data:
|
| 445 |
+
ocr_result = text_one["result"]
|
| 446 |
+
if ocr_result and len(ocr_result) <= 0:
|
| 447 |
+
continue
|
| 448 |
+
text_str += ocr_result
|
| 449 |
+
return text_data, text_str
|
| 450 |
+
|
| 451 |
+
@staticmethod
|
| 452 |
+
def judge_ocr_location_extend(img, text_location, text_str, project=None):
|
| 453 |
+
"""根据文本框信息和 ocr 识别结果判断文本框是否需要进行扩展
|
| 454 |
+
:param img: ndarray, 图像数据
|
| 455 |
+
:param text_location: 文本位置, x1,y1,x2,y2 格式
|
| 456 |
+
:param text_str: str, 文本内容
|
| 457 |
+
:param project: str, 指定调用项目
|
| 458 |
+
:return: bool, 是否扩展
|
| 459 |
+
img_location_extend, ndarray, 文本区域图像数据
|
| 460 |
+
text_data_ext, dict, 文本区域对应的OCR识别结果
|
| 461 |
+
"""
|
| 462 |
+
# 原区域提取和识别
|
| 463 |
+
height, width = img.shape[:2]
|
| 464 |
+
x1, y1, x2, y2 = text_location
|
| 465 |
+
img_location = img[y1: y2, x1: x2]
|
| 466 |
+
text_data, text_s = LqaProcessing.get_join_ocr_result(img_location, project=project)
|
| 467 |
+
if not text_data:
|
| 468 |
+
return False, None, None
|
| 469 |
+
# 区域扩展和识别
|
| 470 |
+
img_location_extend = img[max(0, y1 - 5): min(height, y2 + 5), max(0, x1 - 10): min(width, x2 + 10)]
|
| 471 |
+
text_data_ext, text_s_ext = LqaProcessing.get_join_ocr_result(img_location_extend, project=project)
|
| 472 |
+
if not text_data_ext:
|
| 473 |
+
return False, None, None
|
| 474 |
+
# 判断是否扩展 (扩展后是否包含非文本框信息)
|
| 475 |
+
if text_s == text_s_ext or len(text_s_ext) > len(text_str or ''):
|
| 476 |
+
return False, img_location, text_data
|
| 477 |
+
else:
|
| 478 |
+
return True, img_location_extend, text_data_ext
|
| 479 |
+
|
| 480 |
+
@staticmethod
|
| 481 |
+
def align_single_ocr_location(text_one, text_data, x1, y1, img_location, all_ocr_dict, align_location_list,
|
| 482 |
+
align_ocr_res, extend=False):
|
| 483 |
+
"""ocr 识别单个结果微调校准
|
| 484 |
+
:param text_one: dict, 单 ocr 识别结果
|
| 485 |
+
:param text_data: list, ocr 识别结果
|
| 486 |
+
:param x1: int, 文本位置坐标 x_min
|
| 487 |
+
:param y1: int, 文本位置坐标 y_min
|
| 488 |
+
:param img_location: ndarray, 文本区域的图像
|
| 489 |
+
:param all_ocr_dict: dict, 全局 ocr 识别结果
|
| 490 |
+
:param align_location_list: list, 校准的位置信息
|
| 491 |
+
:param align_ocr_res: list, 校准的文本信息
|
| 492 |
+
:param extend: bool, 是否扩展文本区域
|
| 493 |
+
:return: align_location_list, list, 校准的位置信息
|
| 494 |
+
align_ocr_res, list, 校准的文本信息
|
| 495 |
+
"""
|
| 496 |
+
|
| 497 |
+
ocr_result = text_one["result"]
|
| 498 |
+
if ocr_result and len(ocr_result) <= 0:
|
| 499 |
+
return align_location_list, align_ocr_res
|
| 500 |
+
ocr_area = text_one["area"]
|
| 501 |
+
ocr_x1, ocr_y1, ocr_x2, ocr_y2 = text_one["area"]
|
| 502 |
+
img = img_location[ocr_y1:ocr_y2, ocr_x1:ocr_x2]
|
| 503 |
+
if 0 in img.shape:
|
| 504 |
+
return align_location_list, align_ocr_res
|
| 505 |
+
# 灰度值判断, 过滤背景区域
|
| 506 |
+
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
| 507 |
+
if np.max(gray_img) < 120 and len(text_data) > 1:
|
| 508 |
+
return align_location_list, align_ocr_res
|
| 509 |
+
# 二值化提取前景, 文本区域微调
|
| 510 |
+
binary_threshold = np.mean(gray_img)
|
| 511 |
+
_, th = cv2.threshold(gray_img, binary_threshold, 255, cv2.THRESH_BINARY)
|
| 512 |
+
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (2, 2))
|
| 513 |
+
binary_query = cv2.erode(th, kernel)
|
| 514 |
+
h, w = binary_query.shape
|
| 515 |
+
h_list = []
|
| 516 |
+
w_list = []
|
| 517 |
+
for j in range(h):
|
| 518 |
+
for i in range(w):
|
| 519 |
+
if binary_query[j, i] == 255:
|
| 520 |
+
h_list.append(j)
|
| 521 |
+
w_list.append(i)
|
| 522 |
+
if not extend:
|
| 523 |
+
ocr_x1 = ocr_area[0] + max(0, x1)
|
| 524 |
+
ocr_y1 = ocr_area[1] + max(0, y1)
|
| 525 |
+
ocr_x2 = ocr_area[0] + max(0, x1)
|
| 526 |
+
ocr_y2 = ocr_area[1] + max(0, y1)
|
| 527 |
+
else:
|
| 528 |
+
ocr_x1 = ocr_area[0] + max(0, x1 - 10)
|
| 529 |
+
ocr_y1 = ocr_area[1] + max(0, y1 - 5)
|
| 530 |
+
ocr_x2 = ocr_area[0] + max(0, x1 - 10)
|
| 531 |
+
ocr_y2 = ocr_area[1] + max(0, y1 - 5)
|
| 532 |
+
if len(w_list) > 0 :
|
| 533 |
+
ocr_x1 = ocr_x1 + np.min(w_list)
|
| 534 |
+
ocr_y1 = ocr_y1 + np.min(h_list)
|
| 535 |
+
ocr_x2 = ocr_x2 + np.max(w_list)
|
| 536 |
+
ocr_y2 = ocr_y2 + np.max(h_list)
|
| 537 |
+
# 局部识别和全局识别共同校准
|
| 538 |
+
center_x = (ocr_x1 + ocr_x2) / 2
|
| 539 |
+
center_y = (ocr_y1 + ocr_y2) / 2
|
| 540 |
+
align_location = (ocr_x1, ocr_y1, ocr_x2, ocr_y2)
|
| 541 |
+
if ocr_result in all_ocr_dict:
|
| 542 |
+
for item in all_ocr_dict[ocr_result]:
|
| 543 |
+
item_x1, item_y1, item_x2, item_y2 = item
|
| 544 |
+
if item_x1 < center_x < item_x2 and item_y1 < center_y < item_y2:
|
| 545 |
+
align_ocr_x1 = max(ocr_x1, item_x1)
|
| 546 |
+
align_ocr_y1 = max(ocr_y1, item_y1)
|
| 547 |
+
align_ocr_x2 = min(ocr_x2, item_x2)
|
| 548 |
+
align_ocr_y2 = min(ocr_y2, item_y2)
|
| 549 |
+
align_location = (align_ocr_x1, align_ocr_y1, align_ocr_x2, align_ocr_y2)
|
| 550 |
+
break
|
| 551 |
+
if align_location:
|
| 552 |
+
align_location_list.append(align_location)
|
| 553 |
+
align_ocr_res.append(text_one)
|
| 554 |
+
return align_location_list, align_ocr_res
|
| 555 |
+
|
| 556 |
+
@staticmethod
|
| 557 |
+
def align_ocr_location(text_location, img_location, text_data, all_ocr_dict, merge_location=True, extend=False):
|
| 558 |
+
"""ocr 识别结果微调校准
|
| 559 |
+
:param text_location: 文本位置, x1,y1,x2,y2 格式
|
| 560 |
+
:param img_location: ndarray, 文本区域的图像
|
| 561 |
+
:param text_data: list, ocr 识别结果
|
| 562 |
+
:param all_ocr_dict: dict, 全图像 ocr 识别结果
|
| 563 |
+
:param merge_location: bool, 是否合并检测出来的 ocr 文本区域
|
| 564 |
+
:param extend: bool, 是否扩展文本区域
|
| 565 |
+
:return: align_res, list, 校准的位置信息
|
| 566 |
+
align_ocr_res, list, 校准的文本信息
|
| 567 |
+
"""
|
| 568 |
+
align_location_list = []
|
| 569 |
+
align_ocr_res = []
|
| 570 |
+
x1, y1, _, _ = text_location
|
| 571 |
+
for text_one in text_data:
|
| 572 |
+
align_location_list, align_ocr_res = LqaProcessing.align_single_ocr_location(text_one,
|
| 573 |
+
text_data,
|
| 574 |
+
x1,
|
| 575 |
+
y1,
|
| 576 |
+
img_location,
|
| 577 |
+
all_ocr_dict,
|
| 578 |
+
align_location_list,
|
| 579 |
+
align_ocr_res,
|
| 580 |
+
extend=extend)
|
| 581 |
+
# 根据 merge_location 判断是否对文本框进行聚合处理
|
| 582 |
+
align_res = []
|
| 583 |
+
if len(align_location_list) > 0:
|
| 584 |
+
if merge_location:
|
| 585 |
+
x1_list = []
|
| 586 |
+
x2_list = []
|
| 587 |
+
y1_list = []
|
| 588 |
+
y2_list = []
|
| 589 |
+
for item in align_location_list:
|
| 590 |
+
x1_list.append(item[0])
|
| 591 |
+
y1_list.append(item[1])
|
| 592 |
+
x2_list.append(item[2])
|
| 593 |
+
y2_list.append(item[3])
|
| 594 |
+
|
| 595 |
+
align_loc = (np.min(x1_list), np.min(y1_list), np.max(x2_list), np.max(y2_list))
|
| 596 |
+
align_res.append(align_loc)
|
| 597 |
+
else:
|
| 598 |
+
align_res = align_location_list
|
| 599 |
+
return align_res, align_ocr_res
|
| 600 |
+
|
| 601 |
+
@staticmethod
|
| 602 |
+
def shrink_image_box(img, image_location):
|
| 603 |
+
"""缩小图像框
|
| 604 |
+
:param img: ndarray, 图像
|
| 605 |
+
:param image_location: 图像框位置, x1,y1,x2,y2 格式
|
| 606 |
+
:return: 调整后的图像框位置
|
| 607 |
+
"""
|
| 608 |
+
h, w = img.shape[:2]
|
| 609 |
+
img_roi_area = img[
|
| 610 |
+
max(0, image_location[1]): min(h, image_location[3]),
|
| 611 |
+
max(0, image_location[0]): min(w, image_location[2])
|
| 612 |
+
]
|
| 613 |
+
img_roi_area_gray = cv2.cvtColor(img_roi_area, cv2.COLOR_BGR2GRAY)
|
| 614 |
+
_, th = cv2.threshold(img_roi_area_gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
|
| 615 |
+
_, _, stats, _ = cv2.connectedComponentsWithStats(th, connectivity=4)
|
| 616 |
+
hh, ww = img_roi_area.shape[:2]
|
| 617 |
+
sss = hh * ww
|
| 618 |
+
distance = 10000000
|
| 619 |
+
min_index = -1
|
| 620 |
+
if stats.shape[0] < 100:
|
| 621 |
+
for i, stat in enumerate(stats):
|
| 622 |
+
s = stat[2] * stat[3]
|
| 623 |
+
if sss * 0.95 > s > 10:
|
| 624 |
+
stat_center_x, stat_center_y = stat[0] + stat[2] / 2, stat[1] + stat[3] / 2
|
| 625 |
+
dis = math.sqrt(((stat_center_x - ww / 2) ** 2) + ((stat_center_y - hh / 2) ** 2))
|
| 626 |
+
if dis < distance:
|
| 627 |
+
distance = dis
|
| 628 |
+
min_index = i
|
| 629 |
+
if min_index != -1:
|
| 630 |
+
return stats[min_index][0] + max(0, image_location[0]), \
|
| 631 |
+
stats[min_index][1] + max(0, image_location[1]), \
|
| 632 |
+
stats[min_index][0] + stats[min_index][2] + max(0, image_location[0]), \
|
| 633 |
+
stats[min_index][1] + stats[min_index][3] + max(0, image_location[1])
|
| 634 |
+
return image_location
|
| 635 |
+
|
| 636 |
+
|
| 637 |
+
if __name__ == '__main__':
|
| 638 |
+
pass
|
timi_hok_game_translator/LQA_WMP/lqa_service/task/lqa_supervised.py
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: lqa_supervised.py
|
| 4 |
+
# @desc: LQA 本地化文本异常检测——半监督处理模块, 提供 Supervised 类实现以下能力:
|
| 5 |
+
# - get_supervised_data/get_over_frame_supervised_data: 解析人工审核的监督数据 (supervised),
|
| 6 |
+
# 按漏译/超框 (文本超文本框、文本超图像框)/漏key/文本框重叠/错译/
|
| 7 |
+
# non_problem/非标准框等类型分类提取
|
| 8 |
+
# - judge_location_change: 对比当前图像与历史图像的差异区域, 过滤出发生变化的检测区域,
|
| 9 |
+
# 未变化区域可直接复用历史检测结果
|
| 10 |
+
# - extract_history_result_by_other_type/extract_history_result_by_over_frame_type/
|
| 11 |
+
# extract_history_result: 根据历史检测结果 (history_result), 在两次检测图像的相同 (未变化)
|
| 12 |
+
# 区域上保留历史异常标记, 并在结果图上绘制对应的标注框
|
| 13 |
+
# - preprocessing: 结合历史图像和历史检测结果, 预处理待检测的文本框/图像框列表,
|
| 14 |
+
# 过滤掉未发生变化的区域, 减少重复检测
|
| 15 |
+
# - preprocessing_errs: 处理预处理阶段直接产生的异常 (如脏数据/非标准框等),
|
| 16 |
+
# 直接绘制标注并写入检测结果详情, 无需进入后续常规检测流程
|
| 17 |
+
"""
|
| 18 |
+
import cv2
|
| 19 |
+
import numpy as np
|
| 20 |
+
from task.lqa_config import LqaCheckType, LqaCheckSubType, DrawStyle
|
| 21 |
+
from task.lqa_processing import LqaProcessing
|
| 22 |
+
from task.lqa_abnormal import LqaAbnormal
|
| 23 |
+
from common.tools import img_draw_rect
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class Supervised:
|
| 27 |
+
"""监督处理 (历史测试数据)"""
|
| 28 |
+
|
| 29 |
+
@staticmethod
|
| 30 |
+
def get_supervised_data(data):
|
| 31 |
+
""" 获取各类监督数据
|
| 32 |
+
:param data: dict, 监督数据
|
| 33 |
+
:return: 各类监督数据列表
|
| 34 |
+
"""
|
| 35 |
+
no_trans_list = [] # 漏译
|
| 36 |
+
over_frame_text_text_list = [] # 文本超文本框
|
| 37 |
+
over_frame_text_image_list = [] # 文本超图像框
|
| 38 |
+
no_key_list = [] # 漏 key
|
| 39 |
+
overlap_list = [] # 文本框重叠
|
| 40 |
+
error_trans_list = [] # 错译
|
| 41 |
+
non_problem_list = [] # non_problem
|
| 42 |
+
non_rectangle_list = [] # non_problem
|
| 43 |
+
if data:
|
| 44 |
+
if str(LqaCheckType.NO_TRANS.value) in data:
|
| 45 |
+
no_trans_list = data[str(LqaCheckType.NO_TRANS.value)]
|
| 46 |
+
if str(LqaCheckType.NO_KEY.value) in data:
|
| 47 |
+
no_key_list = data[str(LqaCheckType.NO_KEY.value)]
|
| 48 |
+
if str(LqaCheckType.OVERLAP.value) in data:
|
| 49 |
+
overlap_list = data[str(LqaCheckType.OVERLAP.value)]
|
| 50 |
+
if str(LqaCheckType.OVER_FRAME.value) in data:
|
| 51 |
+
over_frame_text_text_list, over_frame_text_image_list = Supervised.get_over_frame_supervised_data(data)
|
| 52 |
+
if str(LqaCheckType.ERROR_TRANS.value) in data:
|
| 53 |
+
error_trans_list = data[str(LqaCheckType.ERROR_TRANS.value)]
|
| 54 |
+
if str(LqaCheckType.NON_PROBLEM.value) in data:
|
| 55 |
+
non_problem_list = data[str(LqaCheckType.NON_PROBLEM.value)]
|
| 56 |
+
if str(LqaCheckType.NON_RECTANGLE.value) in data:
|
| 57 |
+
non_rectangle_list = data[str(LqaCheckType.NON_RECTANGLE.value)]
|
| 58 |
+
return no_trans_list, over_frame_text_text_list, over_frame_text_image_list, no_key_list, overlap_list,\
|
| 59 |
+
error_trans_list, non_problem_list, non_rectangle_list
|
| 60 |
+
|
| 61 |
+
@staticmethod
|
| 62 |
+
def get_over_frame_supervised_data(data):
|
| 63 |
+
""" 获取超框类型监督数据
|
| 64 |
+
:param data: dict, 监督数据
|
| 65 |
+
:return: 各类监督数据列表
|
| 66 |
+
"""
|
| 67 |
+
over_frame_text_text_list = [] # 文本超文本框
|
| 68 |
+
over_frame_text_image_list = [] # 文本超图像框
|
| 69 |
+
if str(LqaCheckSubType.OVER_FRAME_TEXT_TEXT.value) in data[str(LqaCheckType.OVER_FRAME.value)]:
|
| 70 |
+
over_frame_text_text_list = data[str(LqaCheckType.OVER_FRAME.value)][
|
| 71 |
+
str(LqaCheckSubType.OVER_FRAME_TEXT_TEXT.value)]
|
| 72 |
+
if str(LqaCheckSubType.OVER_FRAME_TEXT_IMAGE.value) in data[str(LqaCheckType.OVER_FRAME.value)]:
|
| 73 |
+
over_frame_text_image_list = data[str(LqaCheckType.OVER_FRAME.value)][
|
| 74 |
+
str(LqaCheckSubType.OVER_FRAME_TEXT_IMAGE.value)]
|
| 75 |
+
return over_frame_text_text_list, over_frame_text_image_list
|
| 76 |
+
|
| 77 |
+
@staticmethod
|
| 78 |
+
def judge_location_change(sub_img, location_list, need_coordinate_trans=True, need_judge_rectangle=False):
|
| 79 |
+
""" 对比和提取历史先验数据的图像变更区域
|
| 80 |
+
:param sub_img: ndarray, 两次测试图像的差图
|
| 81 |
+
:param location_list: list, 原始检测区域信息
|
| 82 |
+
:param need_coordinate_trans: bool, 是否需要进行单位转换
|
| 83 |
+
:param need_judge_rectangle: bool, 是否需要进行标准框检查
|
| 84 |
+
:return: res_location_list, list, 过滤发生变化的检测区域
|
| 85 |
+
"""
|
| 86 |
+
h, _ = sub_img.shape[:2]
|
| 87 |
+
res_location_list = []
|
| 88 |
+
for item in location_list:
|
| 89 |
+
if need_coordinate_trans: # 坐标转换
|
| 90 |
+
if need_judge_rectangle:
|
| 91 |
+
is_rectangle = LqaProcessing.judge_rectangle(item)
|
| 92 |
+
location = LqaProcessing.coordinate_trans(item, h, is_rectangle)
|
| 93 |
+
else:
|
| 94 |
+
location = LqaProcessing.coordinate_trans(item, h)
|
| 95 |
+
|
| 96 |
+
else:
|
| 97 |
+
location = item
|
| 98 |
+
|
| 99 |
+
if len(location) != 4: # 非标区域直接当作变更区域
|
| 100 |
+
res_location_list.append(item)
|
| 101 |
+
else:
|
| 102 |
+
x1, y1, x2, y2 = location
|
| 103 |
+
location_img = sub_img[y1:y2, x1:x2]
|
| 104 |
+
if location_img.any() and np.max(location_img) > 0:
|
| 105 |
+
res_location_list.append(item)
|
| 106 |
+
return res_location_list
|
| 107 |
+
|
| 108 |
+
@staticmethod
|
| 109 |
+
def extract_history_result_by_other_type(type_id, diff_img, sub_img, history_result, check_detail):
|
| 110 |
+
""" 提取历史非超框类型数据
|
| 111 |
+
:param type_id: int, 异常类型 id
|
| 112 |
+
:param diff_img: ndarray, 结果绘制图
|
| 113 |
+
:param sub_img: ndarray, 两次测试图像的差图
|
| 114 |
+
:param history_result: dict, 历史检测结果
|
| 115 |
+
:param check_detail: dict, 检测结果详细信息
|
| 116 |
+
:return: diff_img, 结果绘制图
|
| 117 |
+
check_detail, 检测结果详细信息
|
| 118 |
+
"""
|
| 119 |
+
draw_style = None
|
| 120 |
+
# 非超框异常
|
| 121 |
+
for item in history_result[type_id]:
|
| 122 |
+
if len(item[1]) == 4: # 非标框不处理了, 重新检测
|
| 123 |
+
x1, y1, x2, y2 = item[1]
|
| 124 |
+
location_list = [item[1]]
|
| 125 |
+
judge_res = Supervised.judge_location_change(sub_img, location_list,
|
| 126 |
+
need_coordinate_trans=False)
|
| 127 |
+
if len(judge_res) <= 0: # 对比历史检测结果的相同区域, 结果进行保留
|
| 128 |
+
check_detail = LqaAbnormal.update_check_type_detail(check_detail, int(type_id), item)
|
| 129 |
+
if int(type_id) == LqaCheckType.NO_TRANS.value:
|
| 130 |
+
draw_style = DrawStyle.NO_TRANS.value
|
| 131 |
+
if int(type_id) == LqaCheckType.NO_KEY.value:
|
| 132 |
+
draw_style = DrawStyle.NO_KEY.value
|
| 133 |
+
if int(type_id) == LqaCheckType.OVERLAP.value:
|
| 134 |
+
draw_style = DrawStyle.OVERLAP.value
|
| 135 |
+
if draw_style:
|
| 136 |
+
cv2.rectangle(diff_img, (x1, y1), (x2, y2), draw_style[0], draw_style[1])
|
| 137 |
+
return diff_img, check_detail
|
| 138 |
+
|
| 139 |
+
@staticmethod
|
| 140 |
+
def extract_history_result_by_over_frame_type(type_id, diff_img, sub_img, history_result, check_detail):
|
| 141 |
+
""" 提取历史超框数据
|
| 142 |
+
:param type_id: int, 异常类型 id
|
| 143 |
+
:param diff_img: ndarray, 结果绘制图
|
| 144 |
+
:param sub_img: ndarray, 两次测试图像的差图
|
| 145 |
+
:param history_result: dict, 历史检测结果
|
| 146 |
+
:param check_detail: dict, 检测结果详细信息
|
| 147 |
+
:return: diff_img, 结果绘制图
|
| 148 |
+
check_detail, 检测结果详细信息
|
| 149 |
+
"""
|
| 150 |
+
# 超框异常: 分为文本超文本框, 文本超图像框
|
| 151 |
+
frame_data = history_result[type_id]
|
| 152 |
+
for sub_type_id in frame_data:
|
| 153 |
+
for item in frame_data[sub_type_id]:
|
| 154 |
+
x1, y1, x2, y2 = item[1]
|
| 155 |
+
location_list = [item[1]]
|
| 156 |
+
if len(item) > 2:
|
| 157 |
+
location_list.append([item[2]])
|
| 158 |
+
judge_res = Supervised.judge_location_change(sub_img, location_list,
|
| 159 |
+
need_coordinate_trans=False)
|
| 160 |
+
if len(judge_res) <= 0: # 对比历史检测结果的相同区域, 结果进行保留
|
| 161 |
+
check_detail = LqaAbnormal.update_check_type_detail(check_detail,
|
| 162 |
+
int(type_id),
|
| 163 |
+
item,
|
| 164 |
+
int(sub_type_id))
|
| 165 |
+
draw_style = DrawStyle.OVER_FRAME.value
|
| 166 |
+
if draw_style:
|
| 167 |
+
cv2.rectangle(diff_img, (x1, y1), (x2, y2), draw_style[0], draw_style[1])
|
| 168 |
+
return diff_img, check_detail
|
| 169 |
+
|
| 170 |
+
@staticmethod
|
| 171 |
+
def extract_history_result(diff_img, sub_img, history_result, check_detail):
|
| 172 |
+
""" 根据历史检测结果, 提取并保留 2 次检测图像相同区域的结果
|
| 173 |
+
:param diff_img: ndarray, 结果绘制图
|
| 174 |
+
:param sub_img: ndarray, 两次测试图像的差图
|
| 175 |
+
:param history_result: dict, 历史检测结果
|
| 176 |
+
:param check_detail: dict, 检测结果详细信息
|
| 177 |
+
:return: diff_img, 结果绘制图
|
| 178 |
+
check_detail, 检测结果详细信息
|
| 179 |
+
"""
|
| 180 |
+
if history_result:
|
| 181 |
+
# 逐类处理结果数据
|
| 182 |
+
for type_id in history_result:
|
| 183 |
+
# 非超框异常
|
| 184 |
+
if type_id != str(LqaCheckType.OVER_FRAME.value):
|
| 185 |
+
diff_img, check_detail = Supervised.extract_history_result_by_other_type(type_id,
|
| 186 |
+
diff_img,
|
| 187 |
+
sub_img,
|
| 188 |
+
history_result,
|
| 189 |
+
check_detail)
|
| 190 |
+
else: # 超框异常
|
| 191 |
+
diff_img, check_detail = Supervised.extract_history_result_by_over_frame_type(type_id,
|
| 192 |
+
diff_img,
|
| 193 |
+
sub_img,
|
| 194 |
+
history_result,
|
| 195 |
+
check_detail)
|
| 196 |
+
return diff_img, check_detail
|
| 197 |
+
|
| 198 |
+
@staticmethod
|
| 199 |
+
def preprocessing(img, diff_img, rect_locations, history_img, history_result):
|
| 200 |
+
""" 半监督数据预处理
|
| 201 |
+
:param img: ndarray, 待检测图像
|
| 202 |
+
:param diff_img: ndarray, 结果绘制图
|
| 203 |
+
:param rect_locations: list, 待检测图像文本、图像框信息
|
| 204 |
+
:param history_img: ndarray, 历史检测图像
|
| 205 |
+
:param history_result: dict, 历史检测结果
|
| 206 |
+
:return: text_location_list, 预处理后需要检测的文本框信息
|
| 207 |
+
image_location_list, 预处理后需要检测的图像框信息
|
| 208 |
+
diff_img, 结果绘制图
|
| 209 |
+
check_detail, 检测结果详细信息
|
| 210 |
+
"""
|
| 211 |
+
check_detail = {}
|
| 212 |
+
text_location_list_temp = rect_locations.get("text", [])
|
| 213 |
+
image_location_list_temp = rect_locations.get("image", [])
|
| 214 |
+
if history_img is None or img.shape != history_img.shape:
|
| 215 |
+
return text_location_list_temp, image_location_list_temp, diff_img, check_detail
|
| 216 |
+
else:
|
| 217 |
+
sub = img - history_img
|
| 218 |
+
text_location_list = Supervised.judge_location_change(sub, text_location_list_temp,
|
| 219 |
+
need_judge_rectangle=True)
|
| 220 |
+
image_location_list = Supervised.judge_location_change(sub, image_location_list_temp)
|
| 221 |
+
diff_img, check_detail = Supervised.extract_history_result(diff_img, sub, history_result, check_detail)
|
| 222 |
+
return text_location_list, image_location_list, diff_img, check_detail
|
| 223 |
+
|
| 224 |
+
@staticmethod
|
| 225 |
+
def preprocessing_errs(lqa_img, rect_locations, gt_text_info, check_detail):
|
| 226 |
+
""" 预处理的异常 ———— 只需要直接绘制结果和返回错误
|
| 227 |
+
:param lqa_img: ndarray, 结果绘制图
|
| 228 |
+
:param rect_locations: list, 待检测图像文本、图像框信息
|
| 229 |
+
:param gt_text_info: dict, 处理的上报文本信息
|
| 230 |
+
:param check_detail: dict, 检测结果
|
| 231 |
+
:return: lqa_img, 预处理后的 lqa_img
|
| 232 |
+
check_detail, 预处理后的检测结果详细信息
|
| 233 |
+
"""
|
| 234 |
+
gt_text_locations = gt_text_info['gt_text_locations']
|
| 235 |
+
dirty_text_ids = gt_text_info['dirty_text_ids']
|
| 236 |
+
non_rectangle_ids = gt_text_info['non_rectangle_ids']
|
| 237 |
+
pre_errs = gt_text_info['preprocessing_errs']
|
| 238 |
+
for i in range(len(gt_text_locations)):
|
| 239 |
+
if i in pre_errs: # 有预检测异常
|
| 240 |
+
errs = pre_errs[i]
|
| 241 |
+
text_str = rect_locations['text'][i].get("textStr")
|
| 242 |
+
err_rect = gt_text_locations[i]
|
| 243 |
+
detail_data = [text_str, list(err_rect)]
|
| 244 |
+
if i not in dirty_text_ids and i not in non_rectangle_ids: # 矩形
|
| 245 |
+
lqa_img = img_draw_rect(lqa_img, err_rect, DrawStyle.PRE_ERR.value)
|
| 246 |
+
if i in non_rectangle_ids: # 非矩形
|
| 247 |
+
lqa_img = img_draw_rect(lqa_img, err_rect, DrawStyle.PRE_ERR.value)
|
| 248 |
+
for item_err in errs:
|
| 249 |
+
if item_err not in check_detail:
|
| 250 |
+
check_detail[item_err] = []
|
| 251 |
+
if detail_data not in check_detail[item_err]:
|
| 252 |
+
check_detail[item_err].append(detail_data)
|
| 253 |
+
|
| 254 |
+
return lqa_img, check_detail
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
if __name__ == '__main__':
|
| 258 |
+
pass
|
timi_hok_game_translator/LQA_WMP/lqa_service/tests/batch_test_lqa.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: batch_test_lqa.py
|
| 4 |
+
# @desc: LQA 本地化异常检测批量测试脚本 (用于调参、优化算法时批量查看效果), 提供:
|
| 5 |
+
# - test: 单个样例测试, 读取指定目录下的 screenShot.png(截图) + result.json(标准框标注)
|
| 6 |
+
# + 可选 supervised.json(半监督数据), 调用 /image/lqa_check/ 接口,
|
| 7 |
+
# 并支持将返回的 mark_img(检测标记图)/rect_img(标准框标注图)
|
| 8 |
+
# 本地弹窗展示(show_img)和/或保存到磁盘(save_img)
|
| 9 |
+
# - batch_test: 批量测试入口, 遍历 data_dir 下所有子目录, 对每个包含完整
|
| 10 |
+
# screenShot.png + result.json 的子目录调用 test 执行检测,
|
| 11 |
+
# 并在每次请求间 sleep(1) 避免过快请求
|
| 12 |
+
# - 服务地址可通过环境变量 LQA_TEST_HOST / LQA_TEST_PORT 覆盖 (默认 127.0.0.1:8086),
|
| 13 |
+
# 测试数据目录可通过 LQA_TEST_DATA_DIR 指定 (默认 tests/test/)
|
| 14 |
+
"""
|
| 15 |
+
import os
|
| 16 |
+
import json
|
| 17 |
+
import base64
|
| 18 |
+
import time
|
| 19 |
+
import requests
|
| 20 |
+
import cv2
|
| 21 |
+
from common.tools import base64_to_mat
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def test(data_dir, img_dir, img_path, json_file_path, show_img=True, save_img=False, language=None,
|
| 25 |
+
supervised_file_path=None):
|
| 26 |
+
"""lqa 本地化异常检测
|
| 27 |
+
:param data_dir: str, 测试数据目录
|
| 28 |
+
:param img_dir: str, 数据子文件夹
|
| 29 |
+
:param img_path: str, 图片路径
|
| 30 |
+
:param json_file_path: str, 标准信息文件路径
|
| 31 |
+
:param show_img: bool, 是否显示结果图像
|
| 32 |
+
:param save_img: bool, 是否保存结果图像
|
| 33 |
+
:param language: 测试语种
|
| 34 |
+
:param supervised_file_path: str, 半监督信息文件路径
|
| 35 |
+
:return:
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
host = os.getenv("LQA_TEST_HOST", "127.0.0.1")
|
| 39 |
+
port = int(os.getenv("LQA_TEST_PORT", "8086"))
|
| 40 |
+
|
| 41 |
+
fd = open(img_path, "rb")
|
| 42 |
+
img_base64 = base64.b64encode(fd.read()).decode("ascii")
|
| 43 |
+
load_f = open(json_file_path, 'rb')
|
| 44 |
+
rect_locations = json.load(load_f)
|
| 45 |
+
supervised_data = None
|
| 46 |
+
if supervised_file_path:
|
| 47 |
+
supervised_f = open(supervised_file_path, 'rb')
|
| 48 |
+
supervised_data = json.load(supervised_f)
|
| 49 |
+
|
| 50 |
+
path = "/image/lqa_check/"
|
| 51 |
+
body = {
|
| 52 |
+
"img_base64": img_base64,
|
| 53 |
+
"rect_locations": rect_locations,
|
| 54 |
+
"language": language,
|
| 55 |
+
"supervised": supervised_data
|
| 56 |
+
|
| 57 |
+
}
|
| 58 |
+
url = f"http://{host}:{port}{path}"
|
| 59 |
+
res = requests.post(url, json=body)
|
| 60 |
+
if res.status_code == 200:
|
| 61 |
+
res_dict = res.json()
|
| 62 |
+
if res_dict["success"]:
|
| 63 |
+
result = res_dict["result"]
|
| 64 |
+
mark_img = base64_to_mat(result["mark_img"])
|
| 65 |
+
rect_img = base64_to_mat(result["rect_img"])
|
| 66 |
+
if save_img:
|
| 67 |
+
mark_img_save_path = os.path.join(data_dir, img_dir, 'mark_img_ocr_finetuning_overlap.png')
|
| 68 |
+
rect_img_save_path = os.path.join(data_dir, img_dir, 'rect_img_ocr_finetuning_overlap.png')
|
| 69 |
+
cv2.imwrite(mark_img_save_path, mark_img, [cv2.IMWRITE_PNG_COMPRESSION, 0])
|
| 70 |
+
cv2.imwrite(rect_img_save_path, rect_img, [cv2.IMWRITE_PNG_COMPRESSION, 0])
|
| 71 |
+
if show_img:
|
| 72 |
+
cv2.namedWindow("mark_img", cv2.WINDOW_NORMAL)
|
| 73 |
+
cv2.imshow("mark_img", mark_img)
|
| 74 |
+
cv2.namedWindow("rect_img", cv2.WINDOW_NORMAL)
|
| 75 |
+
cv2.imshow("rect_img", rect_img)
|
| 76 |
+
cv2.waitKey()
|
| 77 |
+
else:
|
| 78 |
+
print(res_dict["err_msg"])
|
| 79 |
+
else:
|
| 80 |
+
print(res.status_code)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def batch_test(data_dir, show_img=True, save_img=False, language=None):
|
| 84 |
+
""" 批量测试
|
| 85 |
+
:param data_dir: str, 测试数据路径
|
| 86 |
+
:param show_img: bool, 是否显示结果图像
|
| 87 |
+
:param save_img: bool, 是否保存结果图像
|
| 88 |
+
:param language: 测试语种
|
| 89 |
+
:return:
|
| 90 |
+
"""
|
| 91 |
+
supervised_file_path = os.path.join(data_dir, 'supervised.json')
|
| 92 |
+
for path, dirs, _ in os.walk(data_dir):
|
| 93 |
+
for img_dir in dirs:
|
| 94 |
+
img_path = os.path.join(path, img_dir, 'screenShot.png')
|
| 95 |
+
json_file_path = os.path.join(path, img_dir, 'result.json')
|
| 96 |
+
if os.path.exists(img_path) and os.path.exists(json_file_path):
|
| 97 |
+
if supervised_file_path is None or not os.path.exists(supervised_file_path):
|
| 98 |
+
supervised_file_path = None
|
| 99 |
+
test(data_dir, img_dir, img_path, json_file_path, show_img=show_img, save_img=save_img,
|
| 100 |
+
language=language, supervised_file_path=supervised_file_path)
|
| 101 |
+
time.sleep(1)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
if __name__ == '__main__':
|
| 105 |
+
default_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test')
|
| 106 |
+
batch_test(os.getenv('LQA_TEST_DATA_DIR', default_dir),
|
| 107 |
+
show_img=False, save_img=True, language=None)
|
timi_hok_game_translator/LQA_WMP/lqa_service/tests/check_ocr.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
# @file: check_ocr.py
|
| 4 |
+
# @desc: OCR provider 自检工具
|
| 5 |
+
|
| 6 |
+
独立于 LQA 业务逻辑, 用于快速验证某个 OCR provider 是否能正常工作,
|
| 7 |
+
依次检测以下几个层面:
|
| 8 |
+
1. provider 能否成功初始化 (依赖库是否安装、必要配置是否齐全,
|
| 9 |
+
如密钥/服务地址等缺失会在此阶段报错)
|
| 10 |
+
2. 该 provider 是否为 "空实现" (capable=False, 即 OCR_PROVIDER=none),
|
| 11 |
+
是则提示 OCR 为可选能力, 服务仍可启动, 仅错译/文本超框检测会被跳过
|
| 12 |
+
3. 真实端到端识别连通性: 构造一张内置测试图 (写有 "LQA123") 调用
|
| 13 |
+
recognize() 做一次真实识别, 验证本地模型推理 或 远程服务的
|
| 14 |
+
网络连通性/鉴权/返回格式是否正常
|
| 15 |
+
|
| 16 |
+
用法:
|
| 17 |
+
python tests/check_ocr.py # 检测当前 OCR_PROVIDER 配置
|
| 18 |
+
python tests/check_ocr.py paddleocr # 指定 provider (不受环境变量/缓存影响)
|
| 19 |
+
python tests/check_ocr.py --list # 列出 common/ocr_provider 中已注册的全部 provider
|
| 20 |
+
|
| 21 |
+
退出码: 0 表示检测通过 (含 [SKIP] 空实现的情况), 1 表示初始化失败或识别调用失败
|
| 22 |
+
"""
|
| 23 |
+
import os
|
| 24 |
+
import sys
|
| 25 |
+
|
| 26 |
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 27 |
+
|
| 28 |
+
from common.ocr_provider import PROVIDERS, get_provider, OcrError # noqa: E402
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def main():
|
| 32 |
+
args = sys.argv[1:]
|
| 33 |
+
if args and args[0] in ('--list', '-l'):
|
| 34 |
+
print('可选 OCR_PROVIDER:')
|
| 35 |
+
for name in sorted(PROVIDERS):
|
| 36 |
+
print(' -', name)
|
| 37 |
+
return 0
|
| 38 |
+
|
| 39 |
+
name = args[0] if args else None
|
| 40 |
+
try:
|
| 41 |
+
provider = get_provider(name=name, cache=False)
|
| 42 |
+
except OcrError as err:
|
| 43 |
+
print('[FAIL] 初始化失败: %s' % err)
|
| 44 |
+
return 1
|
| 45 |
+
|
| 46 |
+
print('provider = %s (远程服务: %s)' % (provider.name, provider.remote))
|
| 47 |
+
if not getattr(provider, 'capable', True):
|
| 48 |
+
print('[SKIP] %s' % provider.test_connection())
|
| 49 |
+
print(' OCR 为可选能力, 当前不影响服务启动;'
|
| 50 |
+
'仅「错译」与「文本超文本框」检测会被跳过')
|
| 51 |
+
return 0
|
| 52 |
+
try:
|
| 53 |
+
print('[OK]', provider.test_connection())
|
| 54 |
+
return 0
|
| 55 |
+
except OcrError as err:
|
| 56 |
+
print('[FAIL] %s' % err)
|
| 57 |
+
print(' OCR 为可选能力: 服务仍可启动, 但「错译」与'
|
| 58 |
+
'「文本超文本框」检测将被跳过')
|
| 59 |
+
return 1
|
| 60 |
+
except Exception as err: # pylint: disable=broad-except
|
| 61 |
+
print('[FAIL] %s: %s' % (type(err).__name__, err))
|
| 62 |
+
return 1
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
if __name__ == '__main__':
|
| 66 |
+
sys.exit(main())
|