示例#1
0
 def on_export_image(self):
     img = pixmap_to_numpy(self.pixmap.pixmap())
     file_name = QFileDialog.getSaveFileName(
         self.main_window,
         directory=self.main_window.project.export_dir,
         filter="*.png *.jpg")[0]
     cv2.imwrite(file_name, img)
示例#2
0
    def on_export(self):
        img = self.on_update()
        self.directory = self.file_browser.get_path()
        if not os.path.isdir(self.directory):
            if self.main_window is not None:
                file_name = QFileDialog.getSaveFileName(
                    self,
                    self.naming_widget.get_naming() + ".png",
                    directory=self.main_window.project.export_dir,
                    filter="*.png *.jpg")[0]
            else:
                file_name = QFileDialog.getSaveFileName(
                    self,
                    self.naming_widget.get_naming() + ".png",
                    filter="*.png *.jpg")[0]
        else:
            self.last_directories.append(self.directory)
            file_name = os.path.join(self.directory,
                                     self.naming_widget.get_naming() + ".png")

        if os.path.isfile(file_name):
            msgBox = QMessageBox()
            msgBox.setText("A File with this name already exists, "
                           "how do you want to proceed. ")
            msgBox.addButton(QPushButton('Overwrite'), QMessageBox.YesRole)
            msgBox.addButton(QPushButton('Create Unique Name'),
                             QMessageBox.NoRole)
            msgBox.addButton(QPushButton('Cancel'), QMessageBox.RejectRole)

            ret = msgBox.exec_()

            if ret == 0:
                file_name = file_name
            elif ret == 1:
                file_name_new = file_name
                ftype = "." + file_name.split(".")[-1:][0]
                c = 1
                while (os.path.isfile(file_name_new)):
                    file_name_new = file_name.replace(
                        ftype, "") + "_" + str(c).zfill(2) + ftype
                    c += 1
                file_name = file_name_new
            else:
                return

        try:
            region = self.preview.region
            size = QSize(self.spinBox_Width.value(),
                         self.spinBox_Height.value())

            img = pixmap_to_numpy(QPixmap(img))

            if region is not None:
                img = img[int(region.y()):int(region.y() + region.height()),
                          int(region.x()):int(region.x() + region.width())]

                img = cv2.resize(img, (size.width(), size.height()),
                                 interpolation=cv2.INTER_CUBIC)

            cv2.imwrite(file_name, img)
            self.on_close()
        except Exception as e:
            log_error(e)
            pass