def on_apply_clicked(self): """ Handle when apply button is clicked Only apply the matrix when it meets all validation criteria :return: None if verification fails """ if self.verify_not_empty(): utils.display_img(self.apply_kernel_transformation(), self.imageViewLabel)
def on_reset_clicked(self): """ Handle when the reset button is clicked :return: """ # Display the original image and reset the processed image utils.display_img(self._image, self.imageViewLabel) self._processed_image = self._image.copy()
def on_facial_recog_cb_changed(self, cb_index): """ Handle when the detect button is clicked on the UI """ if self._color_img is None: return if cb_index == SHOW_FACIAL_RECOG: utils.display_img(self._detected_img, self.leftImgLabel) if cb_index == HIDE_FACIAL_RECOG: utils.display_img(self._color_img, self.leftImgLabel)
def __init__(self, image): super(ImageDescriptionDialog, self).__init__() loadUi(IMAGE_DESCRIPT_DIALOG_UI, self) self.kernel = None self.kernel_matrix_edits = [ self.m_r1c1, self.m_r2c1, self.m_r3c1, self.m_r1c2, self.m_r2c2, self.m_r3c2, self.m_r1c3, self.m_r2c3, self.m_r3c3, ] self.set_validation() description_labels = [ self.shapeDataLabel, self.channelsDataLabel, self.sizeDataLabel, self.datatypeDataLabel ] # Set up initial display labels utils.display_img(image, self.imageViewLabel) (h, w, c) = image.shape self.shapeDataLabel.setText(f"{w} x {h} pixels") self.channelsDataLabel.setText(f"{c}") self.sizeDataLabel.setText(f"{image.size} pixels") self.datatypeDataLabel.setText(f"{image.dtype}") # Resize all labels to match the max width max_label_width = 0 for label in description_labels: if label.width() > max_label_width: max_label_width = label.width() for label in description_labels: # Add padding to the width for size dimensions label.setFixedWidth(max_label_width + 50) # CV image that is passed to the dialog menu # Note: We do not want a dialog without an image to accompany it self._image = image # Cache both the original and processed image self._processed_image = image.copy() # Connect UI buttons self.applyButton.clicked.connect(self.on_apply_clicked) self.resetButton.clicked.connect(self.on_reset_clicked) self.normalizeButton.clicked.connect(self.on_normalize_clicked)
def on_normalize_clicked(self): """ Normalize the current kernel matrix and display the result :return: None if the kernel has not been applied """ if self.kernel is None: return # Get the sum of the matrix and create the new normalized matrix sum = np.sum(self.kernel, dtype=np.int32) normalized_kernel = self.kernel / sum self._processed_image = self._image.copy() image = cv2.filter2D(self._processed_image, -1, normalized_kernel) utils.display_img(image, self.imageViewLabel)
def rotate_image(self, rotation_angle): """ Handle when an image is rotated via the dial or spinbox :param rotation_angle: Angle of rotation from the QDial :return: """ if self._color_img is None: return self._rotation_processor.set_unique_value(rotation_angle) self._rotated_img = self._rotation_processor.process_image(self._color_img, self._processed_img) # Do processing every time the image is rotated, this time used the processed image in place of the # un-modified image. We want to use the size/shape of the transformed image this time for (_, p) in self._processors.items(): self._processed_img = p.process_image(self._rotated_img, self._processed_img) utils.display_img(self._processed_img, self.rightImgLabel)
def on_slider_move(self, behavior_name, slider_value): """ Slot which catches emitted slider movements :param behavior_name: Processor behavior.name :param slider_value: QSlider value from the UI """ if self._color_img is None: return # Cache the processors unique value from it's respective slider position self._processors[behavior_name].set_unique_value(slider_value) # We need to loop through every processor and reprocess each time any slider is moved for (_, p) in self._processors.items(): # Use the rotated image for any changed dimensions self._processed_img = p.process_image(self._rotated_img, self._processed_img) utils.display_img(self._processed_img, self.rightImgLabel)
def update_frame(self): """ Handle when the frame timer times out :return: """ (_, self._image) = self._capture.read() # Flip the image after reading self._image = cv2.flip(self._image, 1) self._image_detected = self._image.copy() if self._recog_active: grayscale_img = cv2.cvtColor(self._image, cv2.COLOR_BGR2GRAY) self._image_detected = self._detector.detect( grayscale_img, self._image) utils.display_img(self._image_detected, self.webcamDisplayLabel, scale_contents=True) self._image_detected = self._image.copy()
def load_image(self, img_path): """ Loads an image :param img_path: The path to (including) the image :return: Return nothing if the image is not found """ self._color_img = cv2.imread(img_path) if self._color_img is None: return self._grayscale_img = cv2.cvtColor(self._color_img, cv2.COLOR_BGR2GRAY) self._processed_img = self._color_img.copy() self._rotated_img = self._color_img.copy() self._detected_img = self._color_img.copy() # Try to detect faces on import self._detected_img = self._detector.detect(self._grayscale_img, self._detected_img) self.display_detection() if self.facialRecogComboBox.currentIndex() == SHOW_FACIAL_RECOG: utils.display_img(self._detected_img, self.leftImgLabel) else: utils.display_img(self._color_img, self.leftImgLabel) # Display the original image on the right label on import utils.display_img(self._color_img, self.rightImgLabel)