Esempio n. 1
0
    def __init__(self, parent=None):
        super(MainDialog, self).__init__(parent)
        self.classifier = FlowerClassifier()
        self.file_good = open('good_image.txt', 'a')
        self.file_bad = open('bad_image.txt', 'a')
        self.file_unknown = open('unknown_image.txt', 'a')

        self.setWindowTitle(self.tr("图像打标工具"))
        self.setFixedSize(QSize(650, 450))

        self.current_non_label_image_path = ''
        self.current_reference_image_path = ''
        self.auto_image_path = ''
        self.auto_images = []
        self.all_images = []
        self.image_index = 0
        self.num_of_image = 0

        # show image label
        self.reference_image = QLabel()
        self.non_label_image = QLabel()

        radio_button_manual = QRadioButton(self.tr("手动"))
        radio_button_auto = QRadioButton(self.tr("自动"))
        radio_button_manual.setChecked(True)

        self.imageLabelQLabel = QLineEdit()
        self.current_path = QLabel()
        self.info_text = QTextEdit()

        # manual layout
        manual_layout_h_ = QHBoxLayout()
        self.manual_layout_reference_image = QPushButton(self.tr("参考图像"))
        self.manual_layout_non_label_image = QPushButton(self.tr("待识别图像"))
        manual_layout_h_.addWidget(self.manual_layout_reference_image)
        manual_layout_h_.addWidget(self.manual_layout_non_label_image)

        manual_layout_h = QHBoxLayout()
        self.manual_layout_line_edit = QLineEdit()
        self.manual_layout_line_edit_reference = QLineEdit()
        self.manual_layout_line_edit_reference.setEnabled(False)
        manual_layout_h.addWidget(QLabel(self.tr("参考标签")))
        manual_layout_h.addWidget(self.manual_layout_line_edit_reference)
        manual_layout_h.addWidget(QLabel(self.tr("标签")))
        manual_layout_h.addWidget(self.manual_layout_line_edit)

        self.manual_layout_previous_image = QPushButton(self.tr("上一张"))
        self.manual_layout_next_image = QPushButton(self.tr("下一张"))
        manual_layout_h_image_button = QHBoxLayout()
        manual_layout_h_image_button.addWidget(
            self.manual_layout_previous_image)
        manual_layout_h_image_button.addWidget(self.manual_layout_next_image)
        manual_layout = QVBoxLayout()
        manual_layout.addLayout(manual_layout_h_)
        manual_layout.addLayout(manual_layout_h)
        manual_layout.addLayout(manual_layout_h_image_button)

        # auto layout
        auto_layout = QVBoxLayout()
        self.auto_info_text = QTextEdit()
        self.set_path_button = QPushButton(self.tr("选择路径"))
        self.recognize_button = QPushButton(self.tr("识别"))
        auto_layout_button_h = QHBoxLayout()
        auto_layout_button_h.addWidget(self.set_path_button)
        auto_layout_button_h.addWidget(self.recognize_button)
        auto_layout.addWidget(self.auto_info_text)
        auto_layout.addLayout(auto_layout_button_h)

        grid_layout = QGridLayout()
        grid_layout.addWidget(self.reference_image, 0, 0)
        grid_layout.addWidget(self.non_label_image, 0, 1)
        grid_layout.addWidget(radio_button_auto, 1, 0)
        grid_layout.addWidget(radio_button_manual, 1, 1)
        grid_layout.addLayout(auto_layout, 2, 0)
        grid_layout.addLayout(manual_layout, 2, 1)

        vertical_layout = QVBoxLayout()
        vertical_layout.addLayout(grid_layout)
        # vertical_layout.addLayout(current_path_layout)
        vertical_layout.addWidget(self.current_path)
        vertical_layout.addWidget(self.info_text)

        self.setLayout(vertical_layout)
        self.set_init_image()

        # connect signal slot
        # self.connect(open_image_button, SIGNAL("clicked()"), self.open_file)
        self.connect(self.manual_layout_reference_image, SIGNAL("clicked()"),
                     self.set_reference_image)
        self.connect(self.manual_layout_non_label_image, SIGNAL("clicked()"),
                     self.set_image)
        self.connect(self.manual_layout_previous_image, SIGNAL("clicked()"),
                     self.open_previous_image)
        self.connect(self.manual_layout_next_image, SIGNAL("clicked()"),
                     self.open_next_image)
        self.connect(self.recognize_button, SIGNAL("clicked()"),
                     self.auto_label)
        self.connect(self.set_path_button, SIGNAL("clicked()"),
                     self.set_auto_path)
        self.classifier.result_signal.connect(self.show_result)
        self.classifier.image_path_signal.connect(self.show_image)