def setup_image_groupbox_ui(self): """Setups image_groupbox with three images, which represent the first, raw image of the video. The calculated background image, and the thresholded image.""" self.image_groupbox = QGroupBox('Images') layout = QHBoxLayout() self.raw_image, _ = self.video.get_frame(0) self.background_image = calc_background_image( self.video, self.tracking_settings.background_n_frames) self.thresholded_image = convert_img_to_uint8( threshold_image(self.raw_image, self.background_image, self.tracking_settings.threshold) ) self.raw_image_label = QLabel() self.background_image_label = QLabel() self.threshold_image_label = QLabel() raw_image_pixmap = QPixmap.fromImage(get_q_image(self.raw_image)) background_image_pixmap = QPixmap.fromImage( get_q_image(self.background_image)) threshold_image_pixmap = QPixmap.fromImage( get_q_image(self.thresholded_image)) self.raw_image_label.setPixmap(raw_image_pixmap) self.background_image_label.setPixmap(background_image_pixmap) self.threshold_image_label.setPixmap(threshold_image_pixmap) layout.addWidget(self.background_image_label) layout.addWidget(self.raw_image_label) layout.addWidget(self.threshold_image_label) self.image_groupbox.setLayout(layout)
def update_background_image(self, n_frames): self.tracking_settings.background_n_frames = n_frames self.background_image = calc_background_image( self.video, self.tracking_settings.background_n_frames) background_image_pixmap = QPixmap.fromImage( get_q_image(self.background_image)) self.background_image_label.setPixmap(background_image_pixmap)
def update_frame_label(self, frame_number=None): if frame_number is None: frame_number = self.current_frame_ix if frame_number < 0: self.current_frame_ix = 0 elif frame_number >= self.video.get_n_frames(): self.current_frame_ix = self.video.get_n_frames() - 1 else: self.current_frame_ix = frame_number img, _ = self.video.get_frame(self.current_frame_ix) # annotate the image if we have tracking_data available. if self.tracking_data is not None: img = img_as_float(img) img = gray2rgb(img) centroid_rr = self.tracking_data['rr'][self.current_frame_ix] centroid_cc = self.tracking_data['cc'][self.current_frame_ix] rr, cc = circle(centroid_rr, centroid_cc, 3) img[rr, cc, :] = [1., 0, 0] img = img_as_ubyte(img) pixmap = QPixmap.fromImage(get_q_image(img)) self.frame_label.setPixmap(pixmap) self.frame_changed.emit(self.current_frame_ix, self._frame_to_time(self.current_frame_ix), int(self.frame_rate))
def update_threshold_image(self, threshold): self.tracking_settings.threshold = threshold / 100. self.thresholded_image = convert_img_to_uint8( threshold_image(self.raw_image, self.background_image, self.tracking_settings.threshold) ) threshold_image_pixmap = QPixmap.fromImage( get_q_image(self.thresholded_image)) self.threshold_image_label.setPixmap(threshold_image_pixmap)
def set_graphics_scene_ui(self): self.graphics_scene_groupbox = QGroupBox() layout = QGridLayout() self.graphics_scene = QGraphicsScene() #background image self.graphics_scene_pixmap = self.graphics_scene.addPixmap( QPixmap.fromImage(get_q_image(self.video.get_frame(0)[0]))) self.graphics_scene_view = QGraphicsView(self.graphics_scene) self.initial_mask_point_locations = np.array( [[self.video.get_width() / 4, 0], [self.video.get_width() / 2, self.video.get_height() / 3], [self.video.get_width() / 4 * 3, 0], [self.video.get_width(), self.video.get_height() / 4], [self.video.get_width() / 3 * 2, self.video.get_height() / 2], [self.video.get_width(), self.video.get_height() / 4 * 3], [self.video.get_width() / 4, self.video.get_height()], [self.video.get_width() / 2, self.video.get_height() / 3 * 2], [self.video.get_width() / 4 * 3, self.video.get_height()], [0, self.video.get_height() / 4], [self.video.get_width() / 3, self.video.get_height() / 2], [0, self.video.get_height() / 4 * 3]]) point_colors = [ Qt.blue, Qt.darkBlue, Qt.blue, Qt.green, Qt.darkGreen, Qt.green, Qt.cyan, Qt.darkCyan, Qt.cyan, Qt.magenta, Qt.darkMagenta, Qt.magenta ] self.mask_points = [ MaskPoint(self.initial_mask_point_locations[i, 0], self.initial_mask_point_locations[i, 1], 10, point_colors[i], '') for i in xrange(len(point_colors)) ] for mask_point in self.mask_points: self.graphics_scene.addItem(mask_point) self.generate_mask_button = QPushButton('Update Mask') self.generate_mask_button.clicked.connect(self.generate_mask) self.load_mask_button = QPushButton('Load Mask') self.load_mask_button.clicked.connect(self.load_mask) self.save_mask_button = QPushButton('Save Mask') self.save_mask_button.clicked.connect(self.save_mask) layout.addWidget(self.graphics_scene_view, 0, 0, 5, 5) layout.addWidget(self.generate_mask_button, 5, 4, 1, 1) layout.addWidget(self.load_mask_button, 6, 0, 1, 1) layout.addWidget(self.save_mask_button, 6, 1, 1, 1) self.graphics_scene_groupbox.setLayout(layout)
def __init__(self, parent=None): super(VideoWidget, self).__init__(parent) self.video = None self.video_filename = None self.tracking_data = None self.is_playing = False self.current_frame_ix = 0 self.frame_rate = 30 self.frame_label = QLabel() # this allows the image to stretch when the window is resized self.frame_label.setScaledContents(True) # set the frame_label to a blank image that is the same size/shape # as our video data img = np.zeros(shape=(240, 320), dtype=np.uint8) pixmap = QPixmap.fromImage(get_q_image(img)) self.frame_label.setPixmap(pixmap) # set the layout of this widget to a single QLabel layout = QGridLayout() layout.addWidget(self.frame_label, 0, 0) self.setLayout(layout)
def update_raw_image(self, frame_ix): self.raw_image, _ = self.video.get_frame(frame_ix) raw_image_pixmap = QPixmap.fromImage(get_q_image(self.raw_image)) self.raw_image_label.setPixmap(raw_image_pixmap)
def update_arena_with_mask_image_label(self): # TODO: update arena_with_mask_image here self.arena_with_mask_image_label.setPixmap( QPixmap.fromImage(get_q_image(self.arena_with_mask_image)))
def update_mask_image_label(self): # TODO: update mask here. self.mask_image_label.setPixmap( QPixmap.fromImage(get_q_image(self.mask_image)))
def update_arena_image_label(self): self.arena_image_label.setPixmap( QPixmap.fromImage(get_q_image(self.arena_image)))