Created
January 15, 2022 16:34
-
-
Save erap129/aeaba0b462e1647b7e7d6692ef60c1f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def choose_source_image(self): | |
self.source_filename = QFileDialog.getOpenFileName()[0] | |
self.source_image_data = cv2.imread(self.source_filename) | |
source_image_resized = resize_image(self.source_image_data, self.max_img_width, self.max_img_height) | |
self.source_image.setPixmap(pixmap_from_cv_image(source_image_resized)) | |
def process_image(self): | |
if self.source_image_data is None: | |
error_dialog = QErrorMessage() | |
error_dialog.showMessage('No image selected') | |
error_dialog.exec() | |
else: | |
self.result_image_data, percent_traced = get_image_mask(self.source_image_data, | |
[self.r_select.value(), self.g_select.value(), self.b_select.value()], | |
self.threshold_select.value()) | |
self.percent_traced_label.setText(f'Percent of image traced: {(percent_traced * 100):.3f}%') | |
result_image_resized = resize_image(self.result_image_data, self.max_img_width, self.max_img_height) | |
self.result_image.setPixmap(pixmap_from_cv_image(result_image_resized)) | |
def save_as_file(self): | |
if self.result_image_data is None: | |
error_dialog = QErrorMessage() | |
error_dialog.showMessage('No image processed') | |
error_dialog.exec() | |
else: | |
filename = QFileDialog.getSaveFileName(self, 'Save File')[0] | |
if len(filename) > 0: | |
cv2.imwrite(filename, self.result_image_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment