Skip to content

Commit

Permalink
add a new parameter to change the color of the selected label box and…
Browse files Browse the repository at this point in the history
… font (#101)

* add change selected label color args

* update readme

---------

Co-authored-by: [email protected] <7p=e763wN3A6k+[C>
  • Loading branch information
yes-github authored Oct 31, 2024
1 parent 81a9c55 commit e9accf8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
28 changes: 26 additions & 2 deletions PPOCRLabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:])

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions README_ch.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ PPOCRLabel是一款适用于OCR领域的半自动化图形标注工具,内置P

- 2024.11:
- 新增`label_font_path`参数,用来改变标签字体
- 新增`selected_shape_color`参数,用来改变选中标签框和字体颜色
- 2024.09:
- 新增`自动重新识别``自动保存未提交变更`功能,使用方法详见下方`2.1 操作步骤``11. 补充功能说明`
- 新增`--img_list_natural_sort`参数,默认左侧图片列表使用自然排序,配置该参数后,将使用字符排序,方便根据字符顺序定位图片。
Expand Down

0 comments on commit e9accf8

Please sign in to comment.