diff --git a/PPOCRLabel.py b/PPOCRLabel.py index f5ac99c..2a354a0 100644 --- a/PPOCRLabel.py +++ b/PPOCRLabel.py @@ -150,6 +150,7 @@ def __init__( rec_char_dict_path=None, cls_model_dir=None, label_font_path=None, + selected_shape_color=(255, 255, 0), ): super(MainWindow, self).__init__() self.setWindowTitle(__appname__) @@ -1199,7 +1200,7 @@ def getStr(strId): if self.filePath and os.path.isdir(self.filePath): self.openDirDialog(dirpath=self.filePath, silent=True) - # load font + # load label font self.label_font_family = None if label_font_path is not None: label_font_id = QFontDatabase.addApplicationFont(label_font_path) @@ -1208,6 +1209,9 @@ def getStr(strId): label_font_id )[0] + # selected shape color + self.selected_shape_color = selected_shape_color + def menu(self, title, actions=None): menu = self.menuBar().addMenu(title) if actions: @@ -1940,7 +1944,11 @@ def _update_shape_color(self, shape): shape.vertex_fill_color = QColor(r, g, b) shape.hvertex_fill_color = QColor(255, 255, 255) shape.fill_color = QColor(r, g, b, 32) - shape.select_line_color = QColor(255, 255, 255) + shape.select_line_color = QColor( + self.selected_shape_color[0], + self.selected_shape_color[1], + self.selected_shape_color[2], + ) shape.select_fill_color = QColor(r, g, b, 32) def _get_rgb_by_label(self, label, kie_mode): @@ -3567,6 +3575,14 @@ def str2bool(v): return v.lower() in ("true", "t", "1") +def parse_rgb(value): + r, g, b = value.split(",") + r, g, b = int(r), int(g), int(b) + if not (0 <= r <= 255 and 0 <= g <= 255 and 0 <= b <= 255): + raise argparse.ArgumentTypeError("RGB values must be between 0 and 255.") + return (r, g, b) + + def get_main_app(argv=[]): """ Standard boilerplate Qt application code. @@ -3598,6 +3614,13 @@ def get_main_app(argv=[]): "--bbox_auto_zoom_center", type=str2bool, default=False, nargs="?" ) arg_parser.add_argument("--label_font_path", type=str, default=None, nargs="?") + arg_parser.add_argument( + "--selected_shape_color", + type=parse_rgb, + default="255,255,0", + nargs="?", + help='An RGB value as "R,G,B".', + ) args = arg_parser.parse_args(argv[1:]) @@ -3613,6 +3636,7 @@ def get_main_app(argv=[]): cls_model_dir=args.cls_model_dir, bbox_auto_zoom_center=args.bbox_auto_zoom_center, label_font_path=args.label_font_path, + selected_shape_color=args.selected_shape_color, ) win.show() return app, win diff --git a/README.md b/README.md index a040744..f11b674 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,8 @@ PPOCRLabelv2 is a semi-automatic graphic annotation tool suitable for OCR field, ### Recent Update - 2024.11: - - Add `label_font_path` parameter to change the font of the label. + - Add the `label_font_path` parameter to change the font of the label. + - Add the `selected_shape_color` parameter to change the color of the selected label box and font. - 2024.09: - Added `Re-recognition` and `Auto Save Unsaved changes` features. For usage details, please refer to the "11. Additional Feature Description" in the "2.1 Operational Steps" section below. - Added the parameter `--img_list_natural_sort`, which defaults to natural sorting for the left image list. After configuring this parameter, character sorting will be used to easily locate images based on character order. diff --git a/README_ch.md b/README_ch.md index 7c91f10..38f9a99 100644 --- a/README_ch.md +++ b/README_ch.md @@ -18,6 +18,7 @@ PPOCRLabel是一款适用于OCR领域的半自动化图形标注工具,内置P - 2024.11: - 新增`label_font_path`参数,用来改变标签字体 + - 新增`selected_shape_color`参数,用来改变选中标签框和字体颜色 - 2024.09: - 新增`自动重新识别`和`自动保存未提交变更`功能,使用方法详见下方`2.1 操作步骤`的`11. 补充功能说明`。 - 新增`--img_list_natural_sort`参数,默认左侧图片列表使用自然排序,配置该参数后,将使用字符排序,方便根据字符顺序定位图片。