pyxllib 0.3.96__py3-none-any.whl → 0.3.197__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyxllib/algo/geo.py +12 -0
- pyxllib/algo/intervals.py +1 -1
- pyxllib/algo/matcher.py +78 -0
- pyxllib/algo/pupil.py +187 -19
- pyxllib/algo/specialist.py +2 -1
- pyxllib/algo/stat.py +38 -2
- {pyxlpr → pyxllib/autogui}/__init__.py +1 -1
- pyxllib/autogui/activewin.py +246 -0
- pyxllib/autogui/all.py +9 -0
- pyxllib/{ext/autogui → autogui}/autogui.py +40 -11
- pyxllib/autogui/uiautolib.py +362 -0
- pyxllib/autogui/wechat.py +827 -0
- pyxllib/autogui/wechat_msg.py +421 -0
- pyxllib/autogui/wxautolib.py +84 -0
- pyxllib/cv/slidercaptcha.py +137 -0
- pyxllib/data/echarts.py +123 -12
- pyxllib/data/jsonlib.py +89 -0
- pyxllib/data/pglib.py +514 -30
- pyxllib/data/sqlite.py +231 -4
- pyxllib/ext/JLineViewer.py +14 -1
- pyxllib/ext/drissionlib.py +277 -0
- pyxllib/ext/kq5034lib.py +0 -1594
- pyxllib/ext/robustprocfile.py +497 -0
- pyxllib/ext/unixlib.py +6 -5
- pyxllib/ext/utools.py +108 -95
- pyxllib/ext/webhook.py +32 -14
- pyxllib/ext/wjxlib.py +88 -0
- pyxllib/ext/wpsapi.py +124 -0
- pyxllib/ext/xlwork.py +9 -0
- pyxllib/ext/yuquelib.py +1003 -71
- pyxllib/file/docxlib.py +1 -1
- pyxllib/file/libreoffice.py +165 -0
- pyxllib/file/movielib.py +9 -0
- pyxllib/file/packlib/__init__.py +112 -75
- pyxllib/file/pdflib.py +1 -1
- pyxllib/file/pupil.py +1 -1
- pyxllib/file/specialist/dirlib.py +1 -1
- pyxllib/file/specialist/download.py +10 -3
- pyxllib/file/specialist/filelib.py +266 -55
- pyxllib/file/xlsxlib.py +205 -50
- pyxllib/file/xlsyncfile.py +341 -0
- pyxllib/prog/cachetools.py +64 -0
- pyxllib/prog/filelock.py +42 -0
- pyxllib/prog/multiprogs.py +940 -0
- pyxllib/prog/newbie.py +9 -2
- pyxllib/prog/pupil.py +129 -60
- pyxllib/prog/specialist/__init__.py +176 -2
- pyxllib/prog/specialist/bc.py +5 -2
- pyxllib/prog/specialist/browser.py +11 -2
- pyxllib/prog/specialist/datetime.py +68 -0
- pyxllib/prog/specialist/tictoc.py +12 -13
- pyxllib/prog/specialist/xllog.py +5 -5
- pyxllib/prog/xlosenv.py +7 -0
- pyxllib/text/airscript.js +744 -0
- pyxllib/text/charclasslib.py +17 -5
- pyxllib/text/jiebalib.py +6 -3
- pyxllib/text/jinjalib.py +32 -0
- pyxllib/text/jsa_ai_prompt.md +271 -0
- pyxllib/text/jscode.py +159 -4
- pyxllib/text/nestenv.py +1 -1
- pyxllib/text/newbie.py +12 -0
- pyxllib/text/pupil/common.py +26 -0
- pyxllib/text/specialist/ptag.py +2 -2
- pyxllib/text/templates/echart_base.html +11 -0
- pyxllib/text/templates/highlight_code.html +17 -0
- pyxllib/text/templates/latex_editor.html +103 -0
- pyxllib/text/xmllib.py +76 -14
- pyxllib/xl.py +2 -1
- pyxllib-0.3.197.dist-info/METADATA +48 -0
- pyxllib-0.3.197.dist-info/RECORD +126 -0
- {pyxllib-0.3.96.dist-info → pyxllib-0.3.197.dist-info}/WHEEL +1 -2
- pyxllib/ext/autogui/__init__.py +0 -8
- pyxllib-0.3.96.dist-info/METADATA +0 -51
- pyxllib-0.3.96.dist-info/RECORD +0 -333
- pyxllib-0.3.96.dist-info/top_level.txt +0 -2
- pyxlpr/ai/__init__.py +0 -5
- pyxlpr/ai/clientlib.py +0 -1281
- pyxlpr/ai/specialist.py +0 -286
- pyxlpr/ai/torch_app.py +0 -172
- pyxlpr/ai/xlpaddle.py +0 -655
- pyxlpr/ai/xltorch.py +0 -705
- pyxlpr/data/__init__.py +0 -11
- pyxlpr/data/coco.py +0 -1325
- pyxlpr/data/datacls.py +0 -365
- pyxlpr/data/datasets.py +0 -200
- pyxlpr/data/gptlib.py +0 -1291
- pyxlpr/data/icdar/__init__.py +0 -96
- pyxlpr/data/icdar/deteval.py +0 -377
- pyxlpr/data/icdar/icdar2013.py +0 -341
- pyxlpr/data/icdar/iou.py +0 -340
- pyxlpr/data/icdar/rrc_evaluation_funcs_1_1.py +0 -463
- pyxlpr/data/imtextline.py +0 -473
- pyxlpr/data/labelme.py +0 -866
- pyxlpr/data/removeline.py +0 -179
- pyxlpr/data/specialist.py +0 -57
- pyxlpr/eval/__init__.py +0 -85
- pyxlpr/paddleocr.py +0 -776
- pyxlpr/ppocr/__init__.py +0 -15
- pyxlpr/ppocr/configs/rec/multi_language/generate_multi_language_configs.py +0 -226
- pyxlpr/ppocr/data/__init__.py +0 -135
- pyxlpr/ppocr/data/imaug/ColorJitter.py +0 -26
- pyxlpr/ppocr/data/imaug/__init__.py +0 -67
- pyxlpr/ppocr/data/imaug/copy_paste.py +0 -170
- pyxlpr/ppocr/data/imaug/east_process.py +0 -437
- pyxlpr/ppocr/data/imaug/gen_table_mask.py +0 -244
- pyxlpr/ppocr/data/imaug/iaa_augment.py +0 -114
- pyxlpr/ppocr/data/imaug/label_ops.py +0 -789
- pyxlpr/ppocr/data/imaug/make_border_map.py +0 -184
- pyxlpr/ppocr/data/imaug/make_pse_gt.py +0 -106
- pyxlpr/ppocr/data/imaug/make_shrink_map.py +0 -126
- pyxlpr/ppocr/data/imaug/operators.py +0 -433
- pyxlpr/ppocr/data/imaug/pg_process.py +0 -906
- pyxlpr/ppocr/data/imaug/randaugment.py +0 -143
- pyxlpr/ppocr/data/imaug/random_crop_data.py +0 -239
- pyxlpr/ppocr/data/imaug/rec_img_aug.py +0 -533
- pyxlpr/ppocr/data/imaug/sast_process.py +0 -777
- pyxlpr/ppocr/data/imaug/text_image_aug/__init__.py +0 -17
- pyxlpr/ppocr/data/imaug/text_image_aug/augment.py +0 -120
- pyxlpr/ppocr/data/imaug/text_image_aug/warp_mls.py +0 -168
- pyxlpr/ppocr/data/lmdb_dataset.py +0 -115
- pyxlpr/ppocr/data/pgnet_dataset.py +0 -104
- pyxlpr/ppocr/data/pubtab_dataset.py +0 -107
- pyxlpr/ppocr/data/simple_dataset.py +0 -372
- pyxlpr/ppocr/losses/__init__.py +0 -61
- pyxlpr/ppocr/losses/ace_loss.py +0 -52
- pyxlpr/ppocr/losses/basic_loss.py +0 -135
- pyxlpr/ppocr/losses/center_loss.py +0 -88
- pyxlpr/ppocr/losses/cls_loss.py +0 -30
- pyxlpr/ppocr/losses/combined_loss.py +0 -67
- pyxlpr/ppocr/losses/det_basic_loss.py +0 -208
- pyxlpr/ppocr/losses/det_db_loss.py +0 -80
- pyxlpr/ppocr/losses/det_east_loss.py +0 -63
- pyxlpr/ppocr/losses/det_pse_loss.py +0 -149
- pyxlpr/ppocr/losses/det_sast_loss.py +0 -121
- pyxlpr/ppocr/losses/distillation_loss.py +0 -272
- pyxlpr/ppocr/losses/e2e_pg_loss.py +0 -140
- pyxlpr/ppocr/losses/kie_sdmgr_loss.py +0 -113
- pyxlpr/ppocr/losses/rec_aster_loss.py +0 -99
- pyxlpr/ppocr/losses/rec_att_loss.py +0 -39
- pyxlpr/ppocr/losses/rec_ctc_loss.py +0 -44
- pyxlpr/ppocr/losses/rec_enhanced_ctc_loss.py +0 -70
- pyxlpr/ppocr/losses/rec_nrtr_loss.py +0 -30
- pyxlpr/ppocr/losses/rec_sar_loss.py +0 -28
- pyxlpr/ppocr/losses/rec_srn_loss.py +0 -47
- pyxlpr/ppocr/losses/table_att_loss.py +0 -109
- pyxlpr/ppocr/metrics/__init__.py +0 -44
- pyxlpr/ppocr/metrics/cls_metric.py +0 -45
- pyxlpr/ppocr/metrics/det_metric.py +0 -82
- pyxlpr/ppocr/metrics/distillation_metric.py +0 -73
- pyxlpr/ppocr/metrics/e2e_metric.py +0 -86
- pyxlpr/ppocr/metrics/eval_det_iou.py +0 -274
- pyxlpr/ppocr/metrics/kie_metric.py +0 -70
- pyxlpr/ppocr/metrics/rec_metric.py +0 -75
- pyxlpr/ppocr/metrics/table_metric.py +0 -50
- pyxlpr/ppocr/modeling/architectures/__init__.py +0 -32
- pyxlpr/ppocr/modeling/architectures/base_model.py +0 -88
- pyxlpr/ppocr/modeling/architectures/distillation_model.py +0 -60
- pyxlpr/ppocr/modeling/backbones/__init__.py +0 -54
- pyxlpr/ppocr/modeling/backbones/det_mobilenet_v3.py +0 -268
- pyxlpr/ppocr/modeling/backbones/det_resnet_vd.py +0 -246
- pyxlpr/ppocr/modeling/backbones/det_resnet_vd_sast.py +0 -285
- pyxlpr/ppocr/modeling/backbones/e2e_resnet_vd_pg.py +0 -265
- pyxlpr/ppocr/modeling/backbones/kie_unet_sdmgr.py +0 -186
- pyxlpr/ppocr/modeling/backbones/rec_mobilenet_v3.py +0 -138
- pyxlpr/ppocr/modeling/backbones/rec_mv1_enhance.py +0 -258
- pyxlpr/ppocr/modeling/backbones/rec_nrtr_mtb.py +0 -48
- pyxlpr/ppocr/modeling/backbones/rec_resnet_31.py +0 -210
- pyxlpr/ppocr/modeling/backbones/rec_resnet_aster.py +0 -143
- pyxlpr/ppocr/modeling/backbones/rec_resnet_fpn.py +0 -307
- pyxlpr/ppocr/modeling/backbones/rec_resnet_vd.py +0 -286
- pyxlpr/ppocr/modeling/heads/__init__.py +0 -54
- pyxlpr/ppocr/modeling/heads/cls_head.py +0 -52
- pyxlpr/ppocr/modeling/heads/det_db_head.py +0 -118
- pyxlpr/ppocr/modeling/heads/det_east_head.py +0 -121
- pyxlpr/ppocr/modeling/heads/det_pse_head.py +0 -37
- pyxlpr/ppocr/modeling/heads/det_sast_head.py +0 -128
- pyxlpr/ppocr/modeling/heads/e2e_pg_head.py +0 -253
- pyxlpr/ppocr/modeling/heads/kie_sdmgr_head.py +0 -206
- pyxlpr/ppocr/modeling/heads/multiheadAttention.py +0 -163
- pyxlpr/ppocr/modeling/heads/rec_aster_head.py +0 -393
- pyxlpr/ppocr/modeling/heads/rec_att_head.py +0 -202
- pyxlpr/ppocr/modeling/heads/rec_ctc_head.py +0 -88
- pyxlpr/ppocr/modeling/heads/rec_nrtr_head.py +0 -826
- pyxlpr/ppocr/modeling/heads/rec_sar_head.py +0 -402
- pyxlpr/ppocr/modeling/heads/rec_srn_head.py +0 -280
- pyxlpr/ppocr/modeling/heads/self_attention.py +0 -406
- pyxlpr/ppocr/modeling/heads/table_att_head.py +0 -246
- pyxlpr/ppocr/modeling/necks/__init__.py +0 -32
- pyxlpr/ppocr/modeling/necks/db_fpn.py +0 -111
- pyxlpr/ppocr/modeling/necks/east_fpn.py +0 -188
- pyxlpr/ppocr/modeling/necks/fpn.py +0 -138
- pyxlpr/ppocr/modeling/necks/pg_fpn.py +0 -314
- pyxlpr/ppocr/modeling/necks/rnn.py +0 -92
- pyxlpr/ppocr/modeling/necks/sast_fpn.py +0 -284
- pyxlpr/ppocr/modeling/necks/table_fpn.py +0 -110
- pyxlpr/ppocr/modeling/transforms/__init__.py +0 -28
- pyxlpr/ppocr/modeling/transforms/stn.py +0 -135
- pyxlpr/ppocr/modeling/transforms/tps.py +0 -308
- pyxlpr/ppocr/modeling/transforms/tps_spatial_transformer.py +0 -156
- pyxlpr/ppocr/optimizer/__init__.py +0 -61
- pyxlpr/ppocr/optimizer/learning_rate.py +0 -228
- pyxlpr/ppocr/optimizer/lr_scheduler.py +0 -49
- pyxlpr/ppocr/optimizer/optimizer.py +0 -160
- pyxlpr/ppocr/optimizer/regularizer.py +0 -52
- pyxlpr/ppocr/postprocess/__init__.py +0 -55
- pyxlpr/ppocr/postprocess/cls_postprocess.py +0 -33
- pyxlpr/ppocr/postprocess/db_postprocess.py +0 -234
- pyxlpr/ppocr/postprocess/east_postprocess.py +0 -143
- pyxlpr/ppocr/postprocess/locality_aware_nms.py +0 -200
- pyxlpr/ppocr/postprocess/pg_postprocess.py +0 -52
- pyxlpr/ppocr/postprocess/pse_postprocess/__init__.py +0 -15
- pyxlpr/ppocr/postprocess/pse_postprocess/pse/__init__.py +0 -29
- pyxlpr/ppocr/postprocess/pse_postprocess/pse/setup.py +0 -14
- pyxlpr/ppocr/postprocess/pse_postprocess/pse_postprocess.py +0 -118
- pyxlpr/ppocr/postprocess/rec_postprocess.py +0 -654
- pyxlpr/ppocr/postprocess/sast_postprocess.py +0 -355
- pyxlpr/ppocr/tools/__init__.py +0 -14
- pyxlpr/ppocr/tools/eval.py +0 -83
- pyxlpr/ppocr/tools/export_center.py +0 -77
- pyxlpr/ppocr/tools/export_model.py +0 -129
- pyxlpr/ppocr/tools/infer/predict_cls.py +0 -151
- pyxlpr/ppocr/tools/infer/predict_det.py +0 -300
- pyxlpr/ppocr/tools/infer/predict_e2e.py +0 -169
- pyxlpr/ppocr/tools/infer/predict_rec.py +0 -414
- pyxlpr/ppocr/tools/infer/predict_system.py +0 -204
- pyxlpr/ppocr/tools/infer/utility.py +0 -629
- pyxlpr/ppocr/tools/infer_cls.py +0 -83
- pyxlpr/ppocr/tools/infer_det.py +0 -134
- pyxlpr/ppocr/tools/infer_e2e.py +0 -122
- pyxlpr/ppocr/tools/infer_kie.py +0 -153
- pyxlpr/ppocr/tools/infer_rec.py +0 -146
- pyxlpr/ppocr/tools/infer_table.py +0 -107
- pyxlpr/ppocr/tools/program.py +0 -596
- pyxlpr/ppocr/tools/test_hubserving.py +0 -117
- pyxlpr/ppocr/tools/train.py +0 -163
- pyxlpr/ppocr/tools/xlprog.py +0 -748
- pyxlpr/ppocr/utils/EN_symbol_dict.txt +0 -94
- pyxlpr/ppocr/utils/__init__.py +0 -24
- pyxlpr/ppocr/utils/dict/ar_dict.txt +0 -117
- pyxlpr/ppocr/utils/dict/arabic_dict.txt +0 -162
- pyxlpr/ppocr/utils/dict/be_dict.txt +0 -145
- pyxlpr/ppocr/utils/dict/bg_dict.txt +0 -140
- pyxlpr/ppocr/utils/dict/chinese_cht_dict.txt +0 -8421
- pyxlpr/ppocr/utils/dict/cyrillic_dict.txt +0 -163
- pyxlpr/ppocr/utils/dict/devanagari_dict.txt +0 -167
- pyxlpr/ppocr/utils/dict/en_dict.txt +0 -63
- pyxlpr/ppocr/utils/dict/fa_dict.txt +0 -136
- pyxlpr/ppocr/utils/dict/french_dict.txt +0 -136
- pyxlpr/ppocr/utils/dict/german_dict.txt +0 -143
- pyxlpr/ppocr/utils/dict/hi_dict.txt +0 -162
- pyxlpr/ppocr/utils/dict/it_dict.txt +0 -118
- pyxlpr/ppocr/utils/dict/japan_dict.txt +0 -4399
- pyxlpr/ppocr/utils/dict/ka_dict.txt +0 -153
- pyxlpr/ppocr/utils/dict/korean_dict.txt +0 -3688
- pyxlpr/ppocr/utils/dict/latin_dict.txt +0 -185
- pyxlpr/ppocr/utils/dict/mr_dict.txt +0 -153
- pyxlpr/ppocr/utils/dict/ne_dict.txt +0 -153
- pyxlpr/ppocr/utils/dict/oc_dict.txt +0 -96
- pyxlpr/ppocr/utils/dict/pu_dict.txt +0 -130
- pyxlpr/ppocr/utils/dict/rs_dict.txt +0 -91
- pyxlpr/ppocr/utils/dict/rsc_dict.txt +0 -134
- pyxlpr/ppocr/utils/dict/ru_dict.txt +0 -125
- pyxlpr/ppocr/utils/dict/ta_dict.txt +0 -128
- pyxlpr/ppocr/utils/dict/table_dict.txt +0 -277
- pyxlpr/ppocr/utils/dict/table_structure_dict.txt +0 -2759
- pyxlpr/ppocr/utils/dict/te_dict.txt +0 -151
- pyxlpr/ppocr/utils/dict/ug_dict.txt +0 -114
- pyxlpr/ppocr/utils/dict/uk_dict.txt +0 -142
- pyxlpr/ppocr/utils/dict/ur_dict.txt +0 -137
- pyxlpr/ppocr/utils/dict/xi_dict.txt +0 -110
- pyxlpr/ppocr/utils/dict90.txt +0 -90
- pyxlpr/ppocr/utils/e2e_metric/Deteval.py +0 -574
- pyxlpr/ppocr/utils/e2e_metric/polygon_fast.py +0 -83
- pyxlpr/ppocr/utils/e2e_utils/extract_batchsize.py +0 -87
- pyxlpr/ppocr/utils/e2e_utils/extract_textpoint_fast.py +0 -457
- pyxlpr/ppocr/utils/e2e_utils/extract_textpoint_slow.py +0 -592
- pyxlpr/ppocr/utils/e2e_utils/pgnet_pp_utils.py +0 -162
- pyxlpr/ppocr/utils/e2e_utils/visual.py +0 -162
- pyxlpr/ppocr/utils/en_dict.txt +0 -95
- pyxlpr/ppocr/utils/gen_label.py +0 -81
- pyxlpr/ppocr/utils/ic15_dict.txt +0 -36
- pyxlpr/ppocr/utils/iou.py +0 -54
- pyxlpr/ppocr/utils/logging.py +0 -69
- pyxlpr/ppocr/utils/network.py +0 -84
- pyxlpr/ppocr/utils/ppocr_keys_v1.txt +0 -6623
- pyxlpr/ppocr/utils/profiler.py +0 -110
- pyxlpr/ppocr/utils/save_load.py +0 -150
- pyxlpr/ppocr/utils/stats.py +0 -72
- pyxlpr/ppocr/utils/utility.py +0 -80
- pyxlpr/ppstructure/__init__.py +0 -13
- pyxlpr/ppstructure/predict_system.py +0 -187
- pyxlpr/ppstructure/table/__init__.py +0 -13
- pyxlpr/ppstructure/table/eval_table.py +0 -72
- pyxlpr/ppstructure/table/matcher.py +0 -192
- pyxlpr/ppstructure/table/predict_structure.py +0 -136
- pyxlpr/ppstructure/table/predict_table.py +0 -221
- pyxlpr/ppstructure/table/table_metric/__init__.py +0 -16
- pyxlpr/ppstructure/table/table_metric/parallel.py +0 -51
- pyxlpr/ppstructure/table/table_metric/table_metric.py +0 -247
- pyxlpr/ppstructure/table/tablepyxl/__init__.py +0 -13
- pyxlpr/ppstructure/table/tablepyxl/style.py +0 -283
- pyxlpr/ppstructure/table/tablepyxl/tablepyxl.py +0 -118
- pyxlpr/ppstructure/utility.py +0 -71
- pyxlpr/xlai.py +0 -10
- /pyxllib/{ext/autogui → autogui}/virtualkey.py +0 -0
- {pyxllib-0.3.96.dist-info → pyxllib-0.3.197.dist-info/licenses}/LICENSE +0 -0
@@ -1,592 +0,0 @@
|
|
1
|
-
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
"""Contains various CTC decoders."""
|
15
|
-
from __future__ import absolute_import
|
16
|
-
from __future__ import division
|
17
|
-
from __future__ import print_function
|
18
|
-
|
19
|
-
import cv2
|
20
|
-
import math
|
21
|
-
|
22
|
-
import numpy as np
|
23
|
-
from itertools import groupby
|
24
|
-
from skimage.morphology._skeletonize import thin
|
25
|
-
|
26
|
-
|
27
|
-
def get_dict(character_dict_path):
|
28
|
-
character_str = ""
|
29
|
-
with open(character_dict_path, "rb") as fin:
|
30
|
-
lines = fin.readlines()
|
31
|
-
for line in lines:
|
32
|
-
line = line.decode('utf-8').strip("\n").strip("\r\n")
|
33
|
-
character_str += line
|
34
|
-
dict_character = list(character_str)
|
35
|
-
return dict_character
|
36
|
-
|
37
|
-
|
38
|
-
def point_pair2poly(point_pair_list):
|
39
|
-
"""
|
40
|
-
Transfer vertical point_pairs into poly point in clockwise.
|
41
|
-
"""
|
42
|
-
pair_length_list = []
|
43
|
-
for point_pair in point_pair_list:
|
44
|
-
pair_length = np.linalg.norm(point_pair[0] - point_pair[1])
|
45
|
-
pair_length_list.append(pair_length)
|
46
|
-
pair_length_list = np.array(pair_length_list)
|
47
|
-
pair_info = (pair_length_list.max(), pair_length_list.min(),
|
48
|
-
pair_length_list.mean())
|
49
|
-
|
50
|
-
point_num = len(point_pair_list) * 2
|
51
|
-
point_list = [0] * point_num
|
52
|
-
for idx, point_pair in enumerate(point_pair_list):
|
53
|
-
point_list[idx] = point_pair[0]
|
54
|
-
point_list[point_num - 1 - idx] = point_pair[1]
|
55
|
-
return np.array(point_list).reshape(-1, 2), pair_info
|
56
|
-
|
57
|
-
|
58
|
-
def shrink_quad_along_width(quad, begin_width_ratio=0., end_width_ratio=1.):
|
59
|
-
"""
|
60
|
-
Generate shrink_quad_along_width.
|
61
|
-
"""
|
62
|
-
ratio_pair = np.array(
|
63
|
-
[[begin_width_ratio], [end_width_ratio]], dtype=np.float32)
|
64
|
-
p0_1 = quad[0] + (quad[1] - quad[0]) * ratio_pair
|
65
|
-
p3_2 = quad[3] + (quad[2] - quad[3]) * ratio_pair
|
66
|
-
return np.array([p0_1[0], p0_1[1], p3_2[1], p3_2[0]])
|
67
|
-
|
68
|
-
|
69
|
-
def expand_poly_along_width(poly, shrink_ratio_of_width=0.3):
|
70
|
-
"""
|
71
|
-
expand poly along width.
|
72
|
-
"""
|
73
|
-
point_num = poly.shape[0]
|
74
|
-
left_quad = np.array(
|
75
|
-
[poly[0], poly[1], poly[-2], poly[-1]], dtype=np.float32)
|
76
|
-
left_ratio = -shrink_ratio_of_width * np.linalg.norm(left_quad[0] - left_quad[3]) / \
|
77
|
-
(np.linalg.norm(left_quad[0] - left_quad[1]) + 1e-6)
|
78
|
-
left_quad_expand = shrink_quad_along_width(left_quad, left_ratio, 1.0)
|
79
|
-
right_quad = np.array(
|
80
|
-
[
|
81
|
-
poly[point_num // 2 - 2], poly[point_num // 2 - 1],
|
82
|
-
poly[point_num // 2], poly[point_num // 2 + 1]
|
83
|
-
],
|
84
|
-
dtype=np.float32)
|
85
|
-
right_ratio = 1.0 + \
|
86
|
-
shrink_ratio_of_width * np.linalg.norm(right_quad[0] - right_quad[3]) / \
|
87
|
-
(np.linalg.norm(right_quad[0] - right_quad[1]) + 1e-6)
|
88
|
-
right_quad_expand = shrink_quad_along_width(right_quad, 0.0, right_ratio)
|
89
|
-
poly[0] = left_quad_expand[0]
|
90
|
-
poly[-1] = left_quad_expand[-1]
|
91
|
-
poly[point_num // 2 - 1] = right_quad_expand[1]
|
92
|
-
poly[point_num // 2] = right_quad_expand[2]
|
93
|
-
return poly
|
94
|
-
|
95
|
-
|
96
|
-
def softmax(logits):
|
97
|
-
"""
|
98
|
-
logits: N x d
|
99
|
-
"""
|
100
|
-
max_value = np.max(logits, axis=1, keepdims=True)
|
101
|
-
exp = np.exp(logits - max_value)
|
102
|
-
exp_sum = np.sum(exp, axis=1, keepdims=True)
|
103
|
-
dist = exp / exp_sum
|
104
|
-
return dist
|
105
|
-
|
106
|
-
|
107
|
-
def get_keep_pos_idxs(labels, remove_blank=None):
|
108
|
-
"""
|
109
|
-
Remove duplicate and get pos idxs of keep items.
|
110
|
-
The value of keep_blank should be [None, 95].
|
111
|
-
"""
|
112
|
-
duplicate_len_list = []
|
113
|
-
keep_pos_idx_list = []
|
114
|
-
keep_char_idx_list = []
|
115
|
-
for k, v_ in groupby(labels):
|
116
|
-
current_len = len(list(v_))
|
117
|
-
if k != remove_blank:
|
118
|
-
current_idx = int(sum(duplicate_len_list) + current_len // 2)
|
119
|
-
keep_pos_idx_list.append(current_idx)
|
120
|
-
keep_char_idx_list.append(k)
|
121
|
-
duplicate_len_list.append(current_len)
|
122
|
-
return keep_char_idx_list, keep_pos_idx_list
|
123
|
-
|
124
|
-
|
125
|
-
def remove_blank(labels, blank=0):
|
126
|
-
new_labels = [x for x in labels if x != blank]
|
127
|
-
return new_labels
|
128
|
-
|
129
|
-
|
130
|
-
def insert_blank(labels, blank=0):
|
131
|
-
new_labels = [blank]
|
132
|
-
for l in labels:
|
133
|
-
new_labels += [l, blank]
|
134
|
-
return new_labels
|
135
|
-
|
136
|
-
|
137
|
-
def ctc_greedy_decoder(probs_seq, blank=95, keep_blank_in_idxs=True):
|
138
|
-
"""
|
139
|
-
CTC greedy (best path) decoder.
|
140
|
-
"""
|
141
|
-
raw_str = np.argmax(np.array(probs_seq), axis=1)
|
142
|
-
remove_blank_in_pos = None if keep_blank_in_idxs else blank
|
143
|
-
dedup_str, keep_idx_list = get_keep_pos_idxs(
|
144
|
-
raw_str, remove_blank=remove_blank_in_pos)
|
145
|
-
dst_str = remove_blank(dedup_str, blank=blank)
|
146
|
-
return dst_str, keep_idx_list
|
147
|
-
|
148
|
-
|
149
|
-
def instance_ctc_greedy_decoder(gather_info,
|
150
|
-
logits_map,
|
151
|
-
keep_blank_in_idxs=True):
|
152
|
-
"""
|
153
|
-
gather_info: [[x, y], [x, y] ...]
|
154
|
-
logits_map: H x W X (n_chars + 1)
|
155
|
-
"""
|
156
|
-
_, _, C = logits_map.shape
|
157
|
-
ys, xs = zip(*gather_info)
|
158
|
-
logits_seq = logits_map[list(ys), list(xs)] # n x 96
|
159
|
-
probs_seq = softmax(logits_seq)
|
160
|
-
dst_str, keep_idx_list = ctc_greedy_decoder(
|
161
|
-
probs_seq, blank=C - 1, keep_blank_in_idxs=keep_blank_in_idxs)
|
162
|
-
keep_gather_list = [gather_info[idx] for idx in keep_idx_list]
|
163
|
-
return dst_str, keep_gather_list
|
164
|
-
|
165
|
-
|
166
|
-
def ctc_decoder_for_image(gather_info_list, logits_map,
|
167
|
-
keep_blank_in_idxs=True):
|
168
|
-
"""
|
169
|
-
CTC decoder using multiple processes.
|
170
|
-
"""
|
171
|
-
decoder_results = []
|
172
|
-
for gather_info in gather_info_list:
|
173
|
-
res = instance_ctc_greedy_decoder(
|
174
|
-
gather_info, logits_map, keep_blank_in_idxs=keep_blank_in_idxs)
|
175
|
-
decoder_results.append(res)
|
176
|
-
return decoder_results
|
177
|
-
|
178
|
-
|
179
|
-
def sort_with_direction(pos_list, f_direction):
|
180
|
-
"""
|
181
|
-
f_direction: h x w x 2
|
182
|
-
pos_list: [[y, x], [y, x], [y, x] ...]
|
183
|
-
"""
|
184
|
-
|
185
|
-
def sort_part_with_direction(pos_list, point_direction):
|
186
|
-
pos_list = np.array(pos_list).reshape(-1, 2)
|
187
|
-
point_direction = np.array(point_direction).reshape(-1, 2)
|
188
|
-
average_direction = np.mean(point_direction, axis=0, keepdims=True)
|
189
|
-
pos_proj_leng = np.sum(pos_list * average_direction, axis=1)
|
190
|
-
sorted_list = pos_list[np.argsort(pos_proj_leng)].tolist()
|
191
|
-
sorted_direction = point_direction[np.argsort(pos_proj_leng)].tolist()
|
192
|
-
return sorted_list, sorted_direction
|
193
|
-
|
194
|
-
pos_list = np.array(pos_list).reshape(-1, 2)
|
195
|
-
point_direction = f_direction[pos_list[:, 0], pos_list[:, 1]] # x, y
|
196
|
-
point_direction = point_direction[:, ::-1] # x, y -> y, x
|
197
|
-
sorted_point, sorted_direction = sort_part_with_direction(pos_list,
|
198
|
-
point_direction)
|
199
|
-
|
200
|
-
point_num = len(sorted_point)
|
201
|
-
if point_num >= 16:
|
202
|
-
middle_num = point_num // 2
|
203
|
-
first_part_point = sorted_point[:middle_num]
|
204
|
-
first_point_direction = sorted_direction[:middle_num]
|
205
|
-
sorted_fist_part_point, sorted_fist_part_direction = sort_part_with_direction(
|
206
|
-
first_part_point, first_point_direction)
|
207
|
-
|
208
|
-
last_part_point = sorted_point[middle_num:]
|
209
|
-
last_point_direction = sorted_direction[middle_num:]
|
210
|
-
sorted_last_part_point, sorted_last_part_direction = sort_part_with_direction(
|
211
|
-
last_part_point, last_point_direction)
|
212
|
-
sorted_point = sorted_fist_part_point + sorted_last_part_point
|
213
|
-
sorted_direction = sorted_fist_part_direction + sorted_last_part_direction
|
214
|
-
|
215
|
-
return sorted_point, np.array(sorted_direction)
|
216
|
-
|
217
|
-
|
218
|
-
def add_id(pos_list, image_id=0):
|
219
|
-
"""
|
220
|
-
Add id for gather feature, for inference.
|
221
|
-
"""
|
222
|
-
new_list = []
|
223
|
-
for item in pos_list:
|
224
|
-
new_list.append((image_id, item[0], item[1]))
|
225
|
-
return new_list
|
226
|
-
|
227
|
-
|
228
|
-
def sort_and_expand_with_direction(pos_list, f_direction):
|
229
|
-
"""
|
230
|
-
f_direction: h x w x 2
|
231
|
-
pos_list: [[y, x], [y, x], [y, x] ...]
|
232
|
-
"""
|
233
|
-
h, w, _ = f_direction.shape
|
234
|
-
sorted_list, point_direction = sort_with_direction(pos_list, f_direction)
|
235
|
-
|
236
|
-
# expand along
|
237
|
-
point_num = len(sorted_list)
|
238
|
-
sub_direction_len = max(point_num // 3, 2)
|
239
|
-
left_direction = point_direction[:sub_direction_len, :]
|
240
|
-
right_dirction = point_direction[point_num - sub_direction_len:, :]
|
241
|
-
|
242
|
-
left_average_direction = -np.mean(left_direction, axis=0, keepdims=True)
|
243
|
-
left_average_len = np.linalg.norm(left_average_direction)
|
244
|
-
left_start = np.array(sorted_list[0])
|
245
|
-
left_step = left_average_direction / (left_average_len + 1e-6)
|
246
|
-
|
247
|
-
right_average_direction = np.mean(right_dirction, axis=0, keepdims=True)
|
248
|
-
right_average_len = np.linalg.norm(right_average_direction)
|
249
|
-
right_step = right_average_direction / (right_average_len + 1e-6)
|
250
|
-
right_start = np.array(sorted_list[-1])
|
251
|
-
|
252
|
-
append_num = max(
|
253
|
-
int((left_average_len + right_average_len) / 2.0 * 0.15), 1)
|
254
|
-
left_list = []
|
255
|
-
right_list = []
|
256
|
-
for i in range(append_num):
|
257
|
-
ly, lx = np.round(left_start + left_step * (i + 1)).flatten().astype(
|
258
|
-
'int32').tolist()
|
259
|
-
if ly < h and lx < w and (ly, lx) not in left_list:
|
260
|
-
left_list.append((ly, lx))
|
261
|
-
ry, rx = np.round(right_start + right_step * (i + 1)).flatten().astype(
|
262
|
-
'int32').tolist()
|
263
|
-
if ry < h and rx < w and (ry, rx) not in right_list:
|
264
|
-
right_list.append((ry, rx))
|
265
|
-
|
266
|
-
all_list = left_list[::-1] + sorted_list + right_list
|
267
|
-
return all_list
|
268
|
-
|
269
|
-
|
270
|
-
def sort_and_expand_with_direction_v2(pos_list, f_direction, binary_tcl_map):
|
271
|
-
"""
|
272
|
-
f_direction: h x w x 2
|
273
|
-
pos_list: [[y, x], [y, x], [y, x] ...]
|
274
|
-
binary_tcl_map: h x w
|
275
|
-
"""
|
276
|
-
h, w, _ = f_direction.shape
|
277
|
-
sorted_list, point_direction = sort_with_direction(pos_list, f_direction)
|
278
|
-
|
279
|
-
# expand along
|
280
|
-
point_num = len(sorted_list)
|
281
|
-
sub_direction_len = max(point_num // 3, 2)
|
282
|
-
left_direction = point_direction[:sub_direction_len, :]
|
283
|
-
right_dirction = point_direction[point_num - sub_direction_len:, :]
|
284
|
-
|
285
|
-
left_average_direction = -np.mean(left_direction, axis=0, keepdims=True)
|
286
|
-
left_average_len = np.linalg.norm(left_average_direction)
|
287
|
-
left_start = np.array(sorted_list[0])
|
288
|
-
left_step = left_average_direction / (left_average_len + 1e-6)
|
289
|
-
|
290
|
-
right_average_direction = np.mean(right_dirction, axis=0, keepdims=True)
|
291
|
-
right_average_len = np.linalg.norm(right_average_direction)
|
292
|
-
right_step = right_average_direction / (right_average_len + 1e-6)
|
293
|
-
right_start = np.array(sorted_list[-1])
|
294
|
-
|
295
|
-
append_num = max(
|
296
|
-
int((left_average_len + right_average_len) / 2.0 * 0.15), 1)
|
297
|
-
max_append_num = 2 * append_num
|
298
|
-
|
299
|
-
left_list = []
|
300
|
-
right_list = []
|
301
|
-
for i in range(max_append_num):
|
302
|
-
ly, lx = np.round(left_start + left_step * (i + 1)).flatten().astype(
|
303
|
-
'int32').tolist()
|
304
|
-
if ly < h and lx < w and (ly, lx) not in left_list:
|
305
|
-
if binary_tcl_map[ly, lx] > 0.5:
|
306
|
-
left_list.append((ly, lx))
|
307
|
-
else:
|
308
|
-
break
|
309
|
-
|
310
|
-
for i in range(max_append_num):
|
311
|
-
ry, rx = np.round(right_start + right_step * (i + 1)).flatten().astype(
|
312
|
-
'int32').tolist()
|
313
|
-
if ry < h and rx < w and (ry, rx) not in right_list:
|
314
|
-
if binary_tcl_map[ry, rx] > 0.5:
|
315
|
-
right_list.append((ry, rx))
|
316
|
-
else:
|
317
|
-
break
|
318
|
-
|
319
|
-
all_list = left_list[::-1] + sorted_list + right_list
|
320
|
-
return all_list
|
321
|
-
|
322
|
-
|
323
|
-
def generate_pivot_list_curved(p_score,
|
324
|
-
p_char_maps,
|
325
|
-
f_direction,
|
326
|
-
score_thresh=0.5,
|
327
|
-
is_expand=True,
|
328
|
-
is_backbone=False,
|
329
|
-
image_id=0):
|
330
|
-
"""
|
331
|
-
return center point and end point of TCL instance; filter with the char maps;
|
332
|
-
"""
|
333
|
-
p_score = p_score[0]
|
334
|
-
f_direction = f_direction.transpose(1, 2, 0)
|
335
|
-
p_tcl_map = (p_score > score_thresh) * 1.0
|
336
|
-
skeleton_map = thin(p_tcl_map)
|
337
|
-
instance_count, instance_label_map = cv2.connectedComponents(
|
338
|
-
skeleton_map.astype(np.uint8), connectivity=8)
|
339
|
-
|
340
|
-
# get TCL Instance
|
341
|
-
all_pos_yxs = []
|
342
|
-
center_pos_yxs = []
|
343
|
-
end_points_yxs = []
|
344
|
-
instance_center_pos_yxs = []
|
345
|
-
pred_strs = []
|
346
|
-
if instance_count > 0:
|
347
|
-
for instance_id in range(1, instance_count):
|
348
|
-
pos_list = []
|
349
|
-
ys, xs = np.where(instance_label_map == instance_id)
|
350
|
-
pos_list = list(zip(ys, xs))
|
351
|
-
|
352
|
-
### FIX-ME, eliminate outlier
|
353
|
-
if len(pos_list) < 3:
|
354
|
-
continue
|
355
|
-
|
356
|
-
if is_expand:
|
357
|
-
pos_list_sorted = sort_and_expand_with_direction_v2(
|
358
|
-
pos_list, f_direction, p_tcl_map)
|
359
|
-
else:
|
360
|
-
pos_list_sorted, _ = sort_with_direction(pos_list, f_direction)
|
361
|
-
all_pos_yxs.append(pos_list_sorted)
|
362
|
-
|
363
|
-
# use decoder to filter backgroud points.
|
364
|
-
p_char_maps = p_char_maps.transpose([1, 2, 0])
|
365
|
-
decode_res = ctc_decoder_for_image(
|
366
|
-
all_pos_yxs, logits_map=p_char_maps, keep_blank_in_idxs=True)
|
367
|
-
for decoded_str, keep_yxs_list in decode_res:
|
368
|
-
if is_backbone:
|
369
|
-
keep_yxs_list_with_id = add_id(keep_yxs_list, image_id=image_id)
|
370
|
-
instance_center_pos_yxs.append(keep_yxs_list_with_id)
|
371
|
-
pred_strs.append(decoded_str)
|
372
|
-
else:
|
373
|
-
end_points_yxs.extend((keep_yxs_list[0], keep_yxs_list[-1]))
|
374
|
-
center_pos_yxs.extend(keep_yxs_list)
|
375
|
-
|
376
|
-
if is_backbone:
|
377
|
-
return pred_strs, instance_center_pos_yxs
|
378
|
-
else:
|
379
|
-
return center_pos_yxs, end_points_yxs
|
380
|
-
|
381
|
-
|
382
|
-
def generate_pivot_list_horizontal(p_score,
|
383
|
-
p_char_maps,
|
384
|
-
f_direction,
|
385
|
-
score_thresh=0.5,
|
386
|
-
is_backbone=False,
|
387
|
-
image_id=0):
|
388
|
-
"""
|
389
|
-
return center point and end point of TCL instance; filter with the char maps;
|
390
|
-
"""
|
391
|
-
p_score = p_score[0]
|
392
|
-
f_direction = f_direction.transpose(1, 2, 0)
|
393
|
-
p_tcl_map_bi = (p_score > score_thresh) * 1.0
|
394
|
-
instance_count, instance_label_map = cv2.connectedComponents(
|
395
|
-
p_tcl_map_bi.astype(np.uint8), connectivity=8)
|
396
|
-
|
397
|
-
# get TCL Instance
|
398
|
-
all_pos_yxs = []
|
399
|
-
center_pos_yxs = []
|
400
|
-
end_points_yxs = []
|
401
|
-
instance_center_pos_yxs = []
|
402
|
-
|
403
|
-
if instance_count > 0:
|
404
|
-
for instance_id in range(1, instance_count):
|
405
|
-
pos_list = []
|
406
|
-
ys, xs = np.where(instance_label_map == instance_id)
|
407
|
-
pos_list = list(zip(ys, xs))
|
408
|
-
|
409
|
-
### FIX-ME, eliminate outlier
|
410
|
-
if len(pos_list) < 5:
|
411
|
-
continue
|
412
|
-
|
413
|
-
# add rule here
|
414
|
-
main_direction = extract_main_direction(pos_list,
|
415
|
-
f_direction) # y x
|
416
|
-
reference_directin = np.array([0, 1]).reshape([-1, 2]) # y x
|
417
|
-
is_h_angle = abs(np.sum(
|
418
|
-
main_direction * reference_directin)) < math.cos(math.pi / 180 *
|
419
|
-
70)
|
420
|
-
|
421
|
-
point_yxs = np.array(pos_list)
|
422
|
-
max_y, max_x = np.max(point_yxs, axis=0)
|
423
|
-
min_y, min_x = np.min(point_yxs, axis=0)
|
424
|
-
is_h_len = (max_y - min_y) < 1.5 * (max_x - min_x)
|
425
|
-
|
426
|
-
pos_list_final = []
|
427
|
-
if is_h_len:
|
428
|
-
xs = np.unique(xs)
|
429
|
-
for x in xs:
|
430
|
-
ys = instance_label_map[:, x].copy().reshape((-1, ))
|
431
|
-
y = int(np.where(ys == instance_id)[0].mean())
|
432
|
-
pos_list_final.append((y, x))
|
433
|
-
else:
|
434
|
-
ys = np.unique(ys)
|
435
|
-
for y in ys:
|
436
|
-
xs = instance_label_map[y, :].copy().reshape((-1, ))
|
437
|
-
x = int(np.where(xs == instance_id)[0].mean())
|
438
|
-
pos_list_final.append((y, x))
|
439
|
-
|
440
|
-
pos_list_sorted, _ = sort_with_direction(pos_list_final,
|
441
|
-
f_direction)
|
442
|
-
all_pos_yxs.append(pos_list_sorted)
|
443
|
-
|
444
|
-
# use decoder to filter backgroud points.
|
445
|
-
p_char_maps = p_char_maps.transpose([1, 2, 0])
|
446
|
-
decode_res = ctc_decoder_for_image(
|
447
|
-
all_pos_yxs, logits_map=p_char_maps, keep_blank_in_idxs=True)
|
448
|
-
for decoded_str, keep_yxs_list in decode_res:
|
449
|
-
if is_backbone:
|
450
|
-
keep_yxs_list_with_id = add_id(keep_yxs_list, image_id=image_id)
|
451
|
-
instance_center_pos_yxs.append(keep_yxs_list_with_id)
|
452
|
-
else:
|
453
|
-
end_points_yxs.extend((keep_yxs_list[0], keep_yxs_list[-1]))
|
454
|
-
center_pos_yxs.extend(keep_yxs_list)
|
455
|
-
|
456
|
-
if is_backbone:
|
457
|
-
return instance_center_pos_yxs
|
458
|
-
else:
|
459
|
-
return center_pos_yxs, end_points_yxs
|
460
|
-
|
461
|
-
|
462
|
-
def generate_pivot_list_slow(p_score,
|
463
|
-
p_char_maps,
|
464
|
-
f_direction,
|
465
|
-
score_thresh=0.5,
|
466
|
-
is_backbone=False,
|
467
|
-
is_curved=True,
|
468
|
-
image_id=0):
|
469
|
-
"""
|
470
|
-
Warp all the function together.
|
471
|
-
"""
|
472
|
-
if is_curved:
|
473
|
-
return generate_pivot_list_curved(
|
474
|
-
p_score,
|
475
|
-
p_char_maps,
|
476
|
-
f_direction,
|
477
|
-
score_thresh=score_thresh,
|
478
|
-
is_expand=True,
|
479
|
-
is_backbone=is_backbone,
|
480
|
-
image_id=image_id)
|
481
|
-
else:
|
482
|
-
return generate_pivot_list_horizontal(
|
483
|
-
p_score,
|
484
|
-
p_char_maps,
|
485
|
-
f_direction,
|
486
|
-
score_thresh=score_thresh,
|
487
|
-
is_backbone=is_backbone,
|
488
|
-
image_id=image_id)
|
489
|
-
|
490
|
-
|
491
|
-
# for refine module
|
492
|
-
def extract_main_direction(pos_list, f_direction):
|
493
|
-
"""
|
494
|
-
f_direction: h x w x 2
|
495
|
-
pos_list: [[y, x], [y, x], [y, x] ...]
|
496
|
-
"""
|
497
|
-
pos_list = np.array(pos_list)
|
498
|
-
point_direction = f_direction[pos_list[:, 0], pos_list[:, 1]]
|
499
|
-
point_direction = point_direction[:, ::-1] # x, y -> y, x
|
500
|
-
average_direction = np.mean(point_direction, axis=0, keepdims=True)
|
501
|
-
average_direction = average_direction / (
|
502
|
-
np.linalg.norm(average_direction) + 1e-6)
|
503
|
-
return average_direction
|
504
|
-
|
505
|
-
|
506
|
-
def sort_by_direction_with_image_id_deprecated(pos_list, f_direction):
|
507
|
-
"""
|
508
|
-
f_direction: h x w x 2
|
509
|
-
pos_list: [[id, y, x], [id, y, x], [id, y, x] ...]
|
510
|
-
"""
|
511
|
-
pos_list_full = np.array(pos_list).reshape(-1, 3)
|
512
|
-
pos_list = pos_list_full[:, 1:]
|
513
|
-
point_direction = f_direction[pos_list[:, 0], pos_list[:, 1]] # x, y
|
514
|
-
point_direction = point_direction[:, ::-1] # x, y -> y, x
|
515
|
-
average_direction = np.mean(point_direction, axis=0, keepdims=True)
|
516
|
-
pos_proj_leng = np.sum(pos_list * average_direction, axis=1)
|
517
|
-
sorted_list = pos_list_full[np.argsort(pos_proj_leng)].tolist()
|
518
|
-
return sorted_list
|
519
|
-
|
520
|
-
|
521
|
-
def sort_by_direction_with_image_id(pos_list, f_direction):
|
522
|
-
"""
|
523
|
-
f_direction: h x w x 2
|
524
|
-
pos_list: [[y, x], [y, x], [y, x] ...]
|
525
|
-
"""
|
526
|
-
|
527
|
-
def sort_part_with_direction(pos_list_full, point_direction):
|
528
|
-
pos_list_full = np.array(pos_list_full).reshape(-1, 3)
|
529
|
-
pos_list = pos_list_full[:, 1:]
|
530
|
-
point_direction = np.array(point_direction).reshape(-1, 2)
|
531
|
-
average_direction = np.mean(point_direction, axis=0, keepdims=True)
|
532
|
-
pos_proj_leng = np.sum(pos_list * average_direction, axis=1)
|
533
|
-
sorted_list = pos_list_full[np.argsort(pos_proj_leng)].tolist()
|
534
|
-
sorted_direction = point_direction[np.argsort(pos_proj_leng)].tolist()
|
535
|
-
return sorted_list, sorted_direction
|
536
|
-
|
537
|
-
pos_list = np.array(pos_list).reshape(-1, 3)
|
538
|
-
point_direction = f_direction[pos_list[:, 1], pos_list[:, 2]] # x, y
|
539
|
-
point_direction = point_direction[:, ::-1] # x, y -> y, x
|
540
|
-
sorted_point, sorted_direction = sort_part_with_direction(pos_list,
|
541
|
-
point_direction)
|
542
|
-
|
543
|
-
point_num = len(sorted_point)
|
544
|
-
if point_num >= 16:
|
545
|
-
middle_num = point_num // 2
|
546
|
-
first_part_point = sorted_point[:middle_num]
|
547
|
-
first_point_direction = sorted_direction[:middle_num]
|
548
|
-
sorted_fist_part_point, sorted_fist_part_direction = sort_part_with_direction(
|
549
|
-
first_part_point, first_point_direction)
|
550
|
-
|
551
|
-
last_part_point = sorted_point[middle_num:]
|
552
|
-
last_point_direction = sorted_direction[middle_num:]
|
553
|
-
sorted_last_part_point, sorted_last_part_direction = sort_part_with_direction(
|
554
|
-
last_part_point, last_point_direction)
|
555
|
-
sorted_point = sorted_fist_part_point + sorted_last_part_point
|
556
|
-
sorted_direction = sorted_fist_part_direction + sorted_last_part_direction
|
557
|
-
|
558
|
-
return sorted_point
|
559
|
-
|
560
|
-
|
561
|
-
def generate_pivot_list_tt_inference(p_score,
|
562
|
-
p_char_maps,
|
563
|
-
f_direction,
|
564
|
-
score_thresh=0.5,
|
565
|
-
is_backbone=False,
|
566
|
-
is_curved=True,
|
567
|
-
image_id=0):
|
568
|
-
"""
|
569
|
-
return center point and end point of TCL instance; filter with the char maps;
|
570
|
-
"""
|
571
|
-
p_score = p_score[0]
|
572
|
-
f_direction = f_direction.transpose(1, 2, 0)
|
573
|
-
p_tcl_map = (p_score > score_thresh) * 1.0
|
574
|
-
skeleton_map = thin(p_tcl_map)
|
575
|
-
instance_count, instance_label_map = cv2.connectedComponents(
|
576
|
-
skeleton_map.astype(np.uint8), connectivity=8)
|
577
|
-
|
578
|
-
# get TCL Instance
|
579
|
-
all_pos_yxs = []
|
580
|
-
if instance_count > 0:
|
581
|
-
for instance_id in range(1, instance_count):
|
582
|
-
pos_list = []
|
583
|
-
ys, xs = np.where(instance_label_map == instance_id)
|
584
|
-
pos_list = list(zip(ys, xs))
|
585
|
-
### FIX-ME, eliminate outlier
|
586
|
-
if len(pos_list) < 3:
|
587
|
-
continue
|
588
|
-
pos_list_sorted = sort_and_expand_with_direction_v2(
|
589
|
-
pos_list, f_direction, p_tcl_map)
|
590
|
-
pos_list_sorted_with_id = add_id(pos_list_sorted, image_id=image_id)
|
591
|
-
all_pos_yxs.append(pos_list_sorted_with_id)
|
592
|
-
return all_pos_yxs
|