def new_shape(self):
        """Pop-up and give focus to the label editor.
        position MUST be in global coordinates.
        """
        BB = QDialogButtonBox

        x1, y1, x2, y2 = int(self.canvas.line[0].x()), int(
            self.canvas.line[0].y()), int(self.canvas.line[1].x()), int(
                self.canvas.line[1].y())
        image = self.image[y1:y2, x1:x2]
        self.labelDialog = LabelDialog(parent=self, image=image)

        self.labelDialog.show()
Beispiel #2
0
    def __init__(self, camera=None, path=None):
        super(DatabaseEditor, self).__init__()
        self.setupUi(self)
        self.camera = camera
        self.stream_enabled = False
        self.dirty = False
        self.frame = None
        self.items_to_shapes = {}
        self.shapes_to_items = {}
        self.prev_label_text = ''
        self.last_label = None
        self.shapes = []
        self.path = path
        self._no_selection_slot = False
        self.current_component = ''
        self.current_record = ''

        self.database_handler = DatabaseHandler(path)
        self.label_list = self.database_handler.classes.copy()
        self.label_dialog = LabelDialog(parent=self, listItem=self.label_list)

        self.scrollBars = {
            Qt.Vertical: self.scrollArea.verticalScrollBar(),
            Qt.Horizontal: self.scrollArea.horizontalScrollBar()
        }

        # context menus
        delete_record_action = Action(self, 'Delete record', self.delete_record, enabled=True)
        add_record_action = Action(self, 'Add record', self.add_record, enabled=True)
        self.record_menu = QMenu()
        add_actions(self.record_menu, (delete_record_action, add_record_action))

        delete_component_action = Action(self, 'Delete component', self.delete_component, enabled=True)
        add_component_action = Action(self, 'Add component', self.add_component, enabled=True)
        add_component_image_action = Action(self, 'Add components image', self.add_component_image, enabled=True)
        self.component_menu = QMenu()
        add_actions(self.component_menu, (delete_component_action, add_component_action, add_component_image_action))

        delete_shape_action = Action(self, 'Delete rectangle', self.delete_shape, enabled=True)
        self.rectangle_menu = QMenu()
        add_actions(self.rectangle_menu, delete_shape_action)

        self.modeEdit.setChecked(True)
        self.modeSelect.setChecked(False)

        self.labelCoordinates = QLabel('')
        self.statusBar().addPermanentWidget(self.labelCoordinates)

        self.connect()
        self.display_classes()
Beispiel #3
0
 def save_labels(self):
     component = self.current_component
     record = self.current_record
     self.label_dialog = LabelDialog(parent=self,
                                     listItem=self.database_handler.classes)
     if record:
         self.database_handler.edit_record(component, record, self.frame,
                                           self.shapes)
     else:
         if component:
             text = component
         else:
             text = self.label_dialog.popUp(self.last_label)
         self.database_handler.add_record(text, self.frame, self.shapes)
         self.display_classes()
     self.set_clean()
Beispiel #4
0
    def new_shape(self):
        if len(self.label_list):
            self.label_dialog = LabelDialog(parent=self, listItem=self.label_list)

        text = self.label_dialog.popUp(text=self.prev_label_text)
        self.last_label = text

        if text is not None:
            self.prev_label_text = text
            color = generate_color_by_text(text)
            shape = self.canvas.setLastLabel(text, color, color)
            self.add_label(shape)
            self.shapes.append(shape)
            if text not in self.label_list:
                self.label_list.append(text)
            self.set_dirty()
        else:
            self.canvas.resetAllLines()
        self.mode_edit(False)