コード例 #1
0
    def loadLabels(self, shapes):
        s = []
        for label, points, line_color, fill_color, difficult in shapes:
            shape = Shape(label=label)
            for x, y in points:

                # Ensure the labels are within the bounds of the image.
                # If not, fix them.
                x, y, snapped = self.canvas.snapPointToCanvas(x, y)
                if snapped:
                    self.setDirty()

                shape.addPoint(QPointF(x, y))
            shape.difficult = difficult
            shape.close()
            s.append(shape)

            if line_color:
                shape.line_color = QColor(*line_color)
            else:
                shape.line_color = generateColorByText(label)

            if fill_color:
                shape.fill_color = QColor(*fill_color)
            else:
                shape.fill_color = generateColorByText(label)

            self.addLabel(shape)
        # self.updateComboBox()
        self.canvas.loadShapes(s)
コード例 #2
0
    def load_record(self):
        if not self.may_continue():
            return
        self.set_clean()
        self.clear_labels()
        item = self.recordList.selectedItems()[0]
        if not item:
            return
        self.current_record = item.text()
        if self.stream_enabled:
            self._stop_video()

        component = self.componentList.selectedItems()[0].text()
        filename = item.text().replace('№', '')
        f = filename.split(' ')
        filename = '{}{:04d}'.format(f[0], int(f[1]))
        path = os.path.join(self.path, component, 'records', filename)

        img_path = path + '.jpg'
        txt_path = path + '.txt'
        self.frame = cv2.imread(img_path)
        if self.frame is None:
            return
        self.frame = cv2.cvtColor(self.frame, cv2.COLOR_BGR2RGB)
        self.canvas.loadPixmap(
            QPixmap.fromImage(qimage2ndarray.array2qimage(self.frame)))
        self.canvas.adjustSize()

        with open(txt_path, 'r') as bndboxes_file:
            for box in bndboxes_file:
                index, xcen, ycen, w, h = box.strip().split(' ')
                label = self.database_handler.classes[int(index)]
                xmin, ymin, xmax, ymax = yolo2points(xcen, ycen, w, h,
                                                     self.frame.shape[1],
                                                     self.frame.shape[0])
                points = [(xmin, ymin), (xmax, ymin), (xmax, ymax),
                          (xmin, ymax)]

                shape = Shape(label=label)
                for x, y in points:
                    x, y, snapped = self.canvas.snapPointToCanvas(x, y)
                    if snapped:
                        self.set_dirty()
                    shape.addPoint(QPointF(x, y))
                shape.difficult = False
                shape.fill_color = generate_color_by_text(label)
                shape.line_color = generate_color_by_text(label)
                shape.close()
                self.shapes.append(shape)
                self.add_label(shape)
        self.canvas.loadShapes(self.shapes)
コード例 #3
0
 def loadParams(self):
     try:
         params = load_from_json("params/param.json")
         shapes = params["shapes"]
         for sh in shapes:
             index, label, r = sh["id"], sh["label"], sh["rect"]
             generate_color = generateColorByText(label)
             shape = Shape(label=label,
                           line_color=generate_color,
                           paintLabel=True)
             # shape.fill = True
             shape.fill_color = generate_color
             shape.points = 4 * [QPoint()]
             shape.points[0] = QPointF(r[0], r[1])
             shape.points[1] = QPointF(r[0] + r[2], r[1])
             shape.points[2] = QPointF(r[0] + r[2], r[1] + r[3])
             shape.points[3] = QPointF(r[0], r[1] + r[3])
             shape.close()
             self.canvas.shapes.append(shape)
             self.addLabel(shape)
     except:
         pass
コード例 #4
0
    def loadLabels(self, shapes):
        s = []

        for label, points, line_color, fill_color, difficult in shapes:
            shape = Shape(label=label)

            for x, y in points:
                shape.addPoint(QPointF(x, y))

            shape.difficult = difficult
            shape.close()
            s.append(shape)

            self.addLabel(shape)

            if line_color:
                shape.line_color = QColor(*line_color)

            if fill_color:
                shape.fill_color = QColor(*fill_color)

        self.canvas.loadShapes(s)