Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions labelme/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1257,14 +1257,19 @@ def _edit_label(self, value=None):
shape.description = description

self._update_shape_color(shape)
# modified by jia.huang 2025.04.05
if shape.group_id is None:
item.setText(
'{} <font color="#{:02x}{:02x}{:02x}">●</font>'.format(
html.escape(shape.label), *shape.fill_color.getRgb()[:3]
)
)
item_text = shape.label
else:
item.setText("{} ({})".format(shape.label, shape.group_id))
item_text = "{} ({})".format(shape.label, shape.group_id)
flags_part = ""
if shape.flags:
true_flags = [k for k, v in shape.flags.items() if v]
if true_flags:
flags_part += f'<font color="gray">{', '.join(true_flags)}</font>'
color_part = '<font color="#{:02x}{:02x}{:02x}">●</font>'.format(*shape.fill_color.getRgb()[:3])
item.setText(' '.join([html.escape(item_text), color_part, flags_part]))
# modified end
self.setDirty()
if self.uniqLabelList.findItemByLabel(shape.label) is None:
item = self.uniqLabelList.createItemFromLabel(shape.label)
Expand Down Expand Up @@ -1330,11 +1335,15 @@ def addLabel(self, shape):
action.setEnabled(True)

self._update_shape_color(shape)
label_list_item.setText(
'{} <font color="#{:02x}{:02x}{:02x}">●</font>'.format(
html.escape(text), *shape.fill_color.getRgb()[:3]
)
)
# modified by jia.huang 2025.04.05
flags_part = ""
if shape.flags:
true_flags = [k for k, v in shape.flags.items() if v]
if true_flags:
flags_part += f'<font color="gray">{', '.join(true_flags)}</font>'
color_part = '<font color="#{:02x}{:02x}{:02x}">●</font>'.format(*shape.fill_color.getRgb()[:3])
label_list_item.setText(' '.join([html.escape(text), color_part, flags_part]))
# modified end

def _update_shape_color(self, shape):
r, g, b = self._get_rgb_by_label(shape.label)
Expand Down
14 changes: 14 additions & 0 deletions labelme/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@ def paint(self, painter):
color = self.select_fill_color if self.selected else self.fill_color
painter.fillPath(line_path, color)

# added by jia.huang 2025-04-05
if self.label:
font = QtGui.QFont()
font.setPointSize(16)
font.setBold(True)
painter.setFont(font)
x_coords = [p.x() for p in self.points]
y_coords = [p.y() for p in self.points]
min_x = min(x_coords)
min_y = min(y_coords)
point = self._scale_point(QtCore.QPointF(min_x + 4, min_y + 16))
painter.drawText(point, self.label)
# added end

pen.setColor(QtGui.QColor(255, 0, 0, 255))
painter.setPen(pen)
painter.drawPath(negative_vrtx_path)
Expand Down