def display_points(self): self.clear_points() if self.current_image_name in self.points: display_radius = self.ui['point']['radius'] active_color = QtGui.QColor(self.ui['point']['color'][0], self.ui['point']['color'][1], self.ui['point']['color'][2]) active_brush = QtGui.QBrush(active_color, QtCore.Qt.BrushStyle.SolidPattern) active_pen = QtGui.QPen(active_brush, 2) for class_name in self.points[self.current_image_name]: points = self.points[self.current_image_name][class_name] brush = QtGui.QBrush(self.colors[class_name], QtCore.Qt.BrushStyle.SolidPattern) pen = QtGui.QPen(brush, 2) for point in points: if class_name == self.current_class_name: self.addEllipse( QtCore.QRectF( point.x() - ((display_radius - 1) / 2), point.y() - ((display_radius - 1) / 2), display_radius, display_radius), active_pen, active_brush) else: self.addEllipse( QtCore.QRectF( point.x() - ((display_radius - 1) / 2), point.y() - ((display_radius - 1) / 2), display_radius, display_radius), pen, brush)
def paintEvent(self, event): if self.svgRenderer: painter = QPainter(self) rect = QtCore.QRectF( -self.scrollPos.x(), -self.scrollPos.y(), self.svgRenderer.defaultSize().width() * self.zoom, self.svgRenderer.defaultSize().height() * self.zoom, ) self.svgRenderer.render(painter, rect)
def select_points(self, rect): self.selection = [] self.display_points() current = self.points[self.current_image_name] display_radius = self.ui['point']['radius'] for class_name in current: for point in current[class_name]: if rect.contains(point): offset = ((display_radius + 6) // 2) self.addEllipse( QtCore.QRectF(point.x() - offset, point.y() - offset, display_radius + 6, display_radius + 6), self.selected_pen) self.selection.append((class_name, point))
def add_point(self, point): if self.current_image_name is not None and self.current_class_name is not None: if self.current_class_name not in self.points[ self.current_image_name]: self.points[self.current_image_name][ self.current_class_name] = [] display_radius = self.ui['point']['radius'] active_color = QtGui.QColor(self.ui['point']['color'][0], self.ui['point']['color'][1], self.ui['point']['color'][2]) active_brush = QtGui.QBrush(active_color, QtCore.Qt.BrushStyle.SolidPattern) active_pen = QtGui.QPen(active_brush, 2) self.points[self.current_image_name][ self.current_class_name].append(point) self.addEllipse( QtCore.QRectF(point.x() - ((display_radius - 1) / 2), point.y() - ((display_radius - 1) / 2), display_radius, display_radius), active_pen, active_brush) self.update_point_count.emit( self.current_image_name, self.current_class_name, len(self.points[self.current_image_name][ self.current_class_name]))