diff --git a/doc/doc_ch/detection.md b/doc/doc_ch/detection.md index bacf854e62ae3acc7d3fb815d3d88bfe0a571fd5..cfff12f976f0a0abe06c37187755d78358e5ca25 100644 --- a/doc/doc_ch/detection.md +++ b/doc/doc_ch/detection.md @@ -23,7 +23,7 @@ wget -P ./train_data/ https://paddleocr.bj.bcebos.com/dataset/test_icdar2015_la └─ test_icdar2015_label.txt icdar数据集的测试标注 ``` -提供的标注文件格式为: +提供的标注文件格式为,其中中间是"\t"分隔: ``` " 图像文件名 json.dumps编码的图像标注信息" ch4_test_images/img_61.jpg [{"transcription": "MASA", "points": [[310, 104], [416, 141], [418, 216], [312, 179]], ...}] diff --git a/doc/imgs_results_vis2/1.jpg b/doc/imgs_results_vis2/1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..f6bb48b6d221041238b01b6f2cf331ed2d45770a Binary files /dev/null and b/doc/imgs_results_vis2/1.jpg differ diff --git a/doc/imgs_results_vis2/10.jpg b/doc/imgs_results_vis2/10.jpg new file mode 100644 index 0000000000000000000000000000000000000000..03585245bf93d592530f344d906847080891de50 Binary files /dev/null and b/doc/imgs_results_vis2/10.jpg differ diff --git a/doc/imgs_results_vis2/11.jpg b/doc/imgs_results_vis2/11.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2b5392a5a8836b56e84dd2695eac239cbeb81b46 Binary files /dev/null and b/doc/imgs_results_vis2/11.jpg differ diff --git a/doc/imgs_results_vis2/12.jpg b/doc/imgs_results_vis2/12.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a7b6518cf5241f1ef6f30d02225e8c883b552d76 Binary files /dev/null and b/doc/imgs_results_vis2/12.jpg differ diff --git a/doc/imgs_results_vis2/13.png b/doc/imgs_results_vis2/13.png new file mode 100644 index 0000000000000000000000000000000000000000..fca7ac3953e2443da0bb0a470e72a564ebec6e4d Binary files /dev/null and b/doc/imgs_results_vis2/13.png differ diff --git a/doc/imgs_results_vis2/15.jpg b/doc/imgs_results_vis2/15.jpg new file mode 100644 index 0000000000000000000000000000000000000000..47a32eeff2ecd9667cd3fb890472eec7612f14d0 Binary files /dev/null and b/doc/imgs_results_vis2/15.jpg differ diff --git a/doc/imgs_results_vis2/16.png b/doc/imgs_results_vis2/16.png new file mode 100644 index 0000000000000000000000000000000000000000..191c4759fcd23dc306b03205e0295e10eed13ab1 Binary files /dev/null and b/doc/imgs_results_vis2/16.png differ diff --git a/doc/imgs_results_vis2/17.png b/doc/imgs_results_vis2/17.png new file mode 100644 index 0000000000000000000000000000000000000000..0ba1b073e7edcee78ca7e6195b8487381f6c5663 Binary files /dev/null and b/doc/imgs_results_vis2/17.png differ diff --git a/doc/imgs_results_vis2/2.jpg b/doc/imgs_results_vis2/2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..8e46314c88c931ff98b3d6ac75eae184698e639a Binary files /dev/null and b/doc/imgs_results_vis2/2.jpg differ diff --git a/doc/imgs_results_vis2/22.jpg b/doc/imgs_results_vis2/22.jpg new file mode 100644 index 0000000000000000000000000000000000000000..aea7791cf7953bf2708a8fbe44ecab6c3b8b9396 Binary files /dev/null and b/doc/imgs_results_vis2/22.jpg differ diff --git a/doc/imgs_results_vis2/3.jpg b/doc/imgs_results_vis2/3.jpg new file mode 100644 index 0000000000000000000000000000000000000000..f3ac72acfa552a326ac81b45186f07c4e8a1e46e Binary files /dev/null and b/doc/imgs_results_vis2/3.jpg differ diff --git a/doc/imgs_results_vis2/4.jpg b/doc/imgs_results_vis2/4.jpg new file mode 100644 index 0000000000000000000000000000000000000000..6986959d935ec02fd345dd47bf3ca2f5b0606d71 Binary files /dev/null and b/doc/imgs_results_vis2/4.jpg differ diff --git a/doc/imgs_results_vis2/5.jpg b/doc/imgs_results_vis2/5.jpg new file mode 100644 index 0000000000000000000000000000000000000000..c6fadd0ec1401c25f2902482f971a4cd98c69e8c Binary files /dev/null and b/doc/imgs_results_vis2/5.jpg differ diff --git a/doc/imgs_results_vis2/6.jpg b/doc/imgs_results_vis2/6.jpg new file mode 100644 index 0000000000000000000000000000000000000000..232e53a3b0d3299d7ac93298901a692da8345e95 Binary files /dev/null and b/doc/imgs_results_vis2/6.jpg differ diff --git a/doc/imgs_results_vis2/7.jpg b/doc/imgs_results_vis2/7.jpg new file mode 100644 index 0000000000000000000000000000000000000000..31ee1078409c49418cbad8e15143da98c799bdb3 Binary files /dev/null and b/doc/imgs_results_vis2/7.jpg differ diff --git a/doc/imgs_results_vis2/8.jpg b/doc/imgs_results_vis2/8.jpg new file mode 100644 index 0000000000000000000000000000000000000000..db6e913ce6f44f5262afe5432f5a62745be322ee Binary files /dev/null and b/doc/imgs_results_vis2/8.jpg differ diff --git a/doc/imgs_results_vis2/9.jpg b/doc/imgs_results_vis2/9.jpg new file mode 100644 index 0000000000000000000000000000000000000000..5b28f97b3f3687a61d34e297878b0e6aeb82db12 Binary files /dev/null and b/doc/imgs_results_vis2/9.jpg differ diff --git a/tools/infer/predict_system.py b/tools/infer/predict_system.py index 032d094cf4d573b36004e34dc8d40da00013f6b3..57f9a7e0a9c27436968219834ac14c815257596d 100755 --- a/tools/infer/predict_system.py +++ b/tools/infer/predict_system.py @@ -30,6 +30,7 @@ import time from ppocr.utils.utility import get_image_file_list from PIL import Image from tools.infer.utility import draw_ocr +from tools.infer.utility import draw_ocr_box_txt class TextSystem(object): diff --git a/tools/infer/utility.py b/tools/infer/utility.py index c3d3b445578eeac0bf981f67a7d775ffdc2ba3d7..ba5a3f386e0fa967b23a65fe5c397b76cf04397c 100755 --- a/tools/infer/utility.py +++ b/tools/infer/utility.py @@ -157,6 +157,44 @@ def draw_ocr(image, boxes, txts, scores, draw_txt=True, drop_score=0.5): return image +def draw_ocr_box_txt(image, boxes, txts): + h, w = image.height, image.width + img_left = image.copy() + img_right = Image.new('RGB', (w, h), (255, 255, 255)) + + import random + # 每次使用相同的随机种子 ,可以保证两次颜色一致 + random.seed(0) + draw_left = ImageDraw.Draw(img_left) + draw_right = ImageDraw.Draw(img_right) + for (box, txt) in zip(boxes, txts): + color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) + draw_left.polygon(box, fill=color) + draw_right.polygon([box[0][0], box[0][1], + box[1][0], box[1][1], + box[2][0], box[2][1], + box[3][0], box[3][1]], outline=color) + box_height = math.sqrt((box[0][0] - box[3][0]) ** 2 + (box[0][1] - box[3][1]) ** 2) + box_width = math.sqrt((box[0][0] - box[1][0]) ** 2 + (box[0][1] - box[1][1]) ** 2) + if box_height > 2 * box_width: + font_size = max(int(box_width * 0.9), 10) + font = ImageFont.truetype("./doc/simfang.ttf", font_size, encoding="utf-8") + cur_y = box[0][1] + for c in txt: + char_size = font.getsize(c) + draw_right.text((box[0][0] + 3, cur_y), c, fill=(0, 0, 0), font=font) + cur_y += char_size[1] + else: + font_size = max(int(box_height * 0.8), 10) + font = ImageFont.truetype("./doc/simfang.ttf", font_size, encoding="utf-8") + draw_right.text([box[0][0], box[0][1]], txt, fill=(0, 0, 0), font=font) + img_left = Image.blend(image, img_left, 0.5) + img_show = Image.new('RGB', (w * 2, h), (255, 255, 255)) + img_show.paste(img_left, (0, 0, w, h)) + img_show.paste(img_right, (w, 0, w * 2, h)) + return np.array(img_show) + + def str_count(s): """ Count the number of Chinese characters, diff --git a/tools/program.py b/tools/program.py index 30e9d7379bd07a0570c613ea25d1b440ed8bc682..3c71065a167fa18fc9d00535dace97737904b74d 100755 --- a/tools/program.py +++ b/tools/program.py @@ -114,7 +114,10 @@ def merge_config(config): global_config[key] = value else: sub_keys = key.split('.') - assert (sub_keys[0] in global_config), "the sub_keys can only be one of global_config: {}, but get: {}, please check your running command".format(global_config.keys(), sub_keys[0]) + assert ( + sub_keys[0] in global_config + ), "the sub_keys can only be one of global_config: {}, but get: {}, please check your running command".format( + global_config.keys(), sub_keys[0]) cur = global_config[sub_keys[0]] for idx, sub_key in enumerate(sub_keys[1:]): assert (sub_key in cur) @@ -177,7 +180,6 @@ def build(config, main_prog, startup_prog, mode): optimizer.minimize(opt_loss) opt_loss_name = opt_loss.name global_lr = optimizer._global_learning_rate() - global_lr.persistable = True fetch_name_list.insert(0, "lr") fetch_varname_list.insert(0, global_lr.name) return (dataloader, fetch_name_list, fetch_varname_list, opt_loss_name)