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)
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)
def loadLabels(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) return s
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)