摘要
使用labelImg时,在未选中数据标签时按Ctrl+D
时会闪退,在终端中有以下报错
修复
在/usr/lib/python3.9/site-packages/labelImg/labelImg.py
第784行,没有数据标签选中时shape
对象没有paint_label
属性,添加一个条件过滤就好
第783行
1 2 3 4 5 6 7 8 9 10 11 12
| def add_label(self, shape): shape.paint_label = self.display_label_option.isChecked() item = HashableQListWidgetItem(shape.label) item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Checked) item.setBackground(generate_color_by_text(shape.label)) self.items_to_shapes[item] = shape self.shapes_to_items[shape] = item self.label_list.addItem(item) for action in self.actions.onShapesPresent: action.setEnabled(True) self.update_combo_box()
|
改为
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| def add_label(self, shape): if shape is None: print('add empty label') return shape.paint_label = self.display_label_option.isChecked() item = HashableQListWidgetItem(shape.label) item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Checked) item.setBackground(generate_color_by_text(shape.label)) self.items_to_shapes[item] = shape self.shapes_to_items[shape] = item self.label_list.addItem(item) for action in self.actions.onShapesPresent: action.setEnabled(True) self.update_combo_box()
|