def __init__(self, app): super().__init__() self.app = app self.showMaximized() self.image_service = ImageService() self.storage_service = StorageService() self.stacked_widget = QStackedWidget() self.stacked_widget.showMaximized() self.main_widget = MainWidget(self) self.settings_widget = SettingsWidget(self, Settings()) self.pattern_widget = PatternWidget(self, Pattern()) self.stacked_widget.addWidget(self.main_widget) self.stacked_widget.addWidget(self.pattern_widget) self.stacked_widget.addWidget(self.settings_widget) self.setCentralWidget(self.stacked_widget) self.selected_pattern_name = None self.selected_settings_name = None self.pattern = None self.settings = None self._create_actions() self._set_menu_bar() self._set_tool_bar() self.errors_color = QColor(255, 0, 0)
def create_pattern(self, pattern_name): bin_image = np.random.randint(2, size=(20, 10)) bin_image[bin_image == 1] = 255 keypoints = [ cv2.KeyPoint(5, 5, 2, -1, 0, 0, -1), cv2.KeyPoint(2, 2, 1, -1, 1, 1, -1) ] descriptors = np.random.randint(256, size=(len(keypoints), 32)) return Pattern(pattern_name, bin_image, keypoints, descriptors)
def load_pattern(self, name): directory = os.path.join(PATTERNS_DIR, name) pattern = Pattern(name) if os.path.exists(directory): pattern.image = cv2.imread( os.path.join(directory, BINARY_FILENAME), cv2.IMREAD_GRAYSCALE) with open(os.path.join(directory, KEYPOINTS_FILENAME), 'r') as f: pattern.keypoints = self._json_to_keypoints(json.load(f)) pattern.descriptors = np.load( os.path.join(directory, DESCRIPTORS_FILENAME)) return pattern
def _new_pattern_action_handler(self): file_dialog = QFileDialog(self) file_dialog.setNameFilters(["All Files (*)", "Images (*.png *.jpg)"]) file_dialog.selectNameFilter("Images (*.png *.jpg)") if file_dialog.exec_(): filename = file_dialog.selectedFiles()[0] with wait_cursor(): image_orig = cv2.imread(filename, cv2.IMREAD_COLOR) self.stacked_widget.removeWidget(self.pattern_widget) self.settings_widget = PatternWidget(self, Pattern()) self.stacked_widget.addWidget(self.pattern_widget) self.stacked_widget.setCurrentWidget(self.pattern_widget) self.pattern_widget.setImage(image_orig) self.pattern_widget.update()