diff --git a/ui/RapidVideOCR.py b/ui/RapidVideOCR.py index 0455f7b..2d94692 100644 --- a/ui/RapidVideOCR.py +++ b/ui/RapidVideOCR.py @@ -30,13 +30,13 @@ def __init__( ): super(RapidVideOCRUI, self).__init__() - self.setting = QSettings('./config', QSettings.IniFormat) - self.setting.setIniCodec('UTF-8') + self.setting = QSettings("./config", QSettings.IniFormat) + self.setting.setIniCodec("UTF-8") - self.main_name = 'RapidVideOCR' - self.version = 'v0.0.3' + self.main_name = "RapidVideOCR" + self.version = "v0.0.4" - self.setWindowTitle(f'{self.main_name} {self.version}') + self.setWindowTitle(f"{self.main_name} {self.version}") self.resize(727, 379) font = QFont() @@ -61,9 +61,9 @@ def __init__( # ---------------调节参数 group box-------------- self.ocr_gb_params = QGroupBox(self) self.ocr_gb_params.setGeometry(QRect(30, 210, 651, 81)) - self.ocr_gb_params.setTitle('调节参数') + self.ocr_gb_params.setTitle("调节参数") self.ocr_gb_params.setFont(gb_font) - self.ocr_gb_params.setObjectName('ocr_gb_params') + self.ocr_gb_params.setObjectName("ocr_gb_params") # 单选框:是否叠图识别 self.widget_batch = QWidget(self.ocr_gb_params) @@ -77,12 +77,12 @@ def __init__( self.label_mode = QLabel(self.widget_batch) self.label_mode.setObjectName("label_mode") - self.label_mode.setText('是否叠图识别:') + self.label_mode.setText("是否叠图识别:") self.hl_batch.addWidget(self.label_mode) self.rb_rec_mode = QRadioButton(self.widget_batch) self.rb_rec_mode.setObjectName("rb_rec_mode") - self.rb_rec_mode.setText('叠图识别') + self.rb_rec_mode.setText("叠图识别") self.hl_batch.addWidget(self.rb_rec_mode) # 叠图识别下,batch个数 @@ -98,13 +98,13 @@ def __init__( self.label_batch = QLabel(self.ocr_gb_params) self.label_batch.setFont(font) self.label_batch.setObjectName("label_batch") - self.label_batch.setText('叠图个数:') + self.label_batch.setText("叠图个数:") self.hl_batch_num.addWidget(self.label_batch) self.le_batch = QLineEdit(self.ocr_gb_params) self.le_batch.setObjectName("le_batch") self.le_batch.setFont(font) - self.le_batch.setText('10') + self.le_batch.setText("10") self.le_batch.setValidator(QIntValidator()) self.hl_batch_num.addWidget(self.le_batch) @@ -132,7 +132,7 @@ def tab1UI(self, font): self.hl_img_dir = QHBoxLayout(self.img_dir_widget) self.hl_img_dir.setContentsMargins(0, 0, 0, 0) - self.hl_img_dir.setObjectName('hl_select_img_dir') + self.hl_img_dir.setObjectName("hl_select_img_dir") self.label_img_dir = QLabel(self.img_dir_widget) self.label_img_dir.setGeometry(QRect(30, 40, 581, 31)) @@ -145,7 +145,7 @@ def tab1UI(self, font): self.le_display_img_dir = QLineEdit(self.img_dir_widget) self.le_display_img_dir.setGeometry(QRect(100, 20, 421, 31)) self.le_display_img_dir.setObjectName("le_display_img_dir") - self.le_display_img_dir.setText(self.get_last_dir('LastDir')) + self.le_display_img_dir.setText(self.get_last_dir("LastDir")) self.le_display_img_dir.setFocus() self.hl_img_dir.addWidget(self.le_display_img_dir) @@ -165,7 +165,7 @@ def tab1UI(self, font): self.hl_srt_path = QHBoxLayout(self.srt_widget) self.hl_srt_path.setContentsMargins(0, 0, 0, 0) - self.hl_srt_path.setObjectName('hl_srt') + self.hl_srt_path.setObjectName("hl_srt") self.lable_save_name = QLabel(self.srt_widget) self.lable_save_name.setFont(font) @@ -175,7 +175,7 @@ def tab1UI(self, font): self.le_save_path = QLineEdit(self.srt_widget) self.le_save_path.setObjectName("le_save_path") - self.le_save_path.setText(self.get_last_dir('SRTDir')) + self.le_save_path.setText(self.get_last_dir("SRTDir")) self.hl_srt_path.addWidget(self.le_save_path) self.btn_save_result = QPushButton(self.srt_widget) @@ -184,7 +184,7 @@ def tab1UI(self, font): self.btn_save_result.clicked.connect(self.select_save_srt_dir) self.hl_srt_path.addWidget(self.btn_save_result) - self.tabWidget.addTab(self.tab_only_ocr, 'RapidVideOCR') + self.tabWidget.addTab(self.tab_only_ocr, "RapidVideOCR") def tab2UI(self, font): # ---------------VideoSubFinder + RapidVideOCR部分------------- @@ -200,7 +200,7 @@ def tab2UI(self, font): self.hl_vsf_path = QHBoxLayout(self.vsf_path_widget) self.hl_vsf_path.setContentsMargins(0, 0, 0, 0) - self.hl_vsf_path.setObjectName('hl_vsf_path') + self.hl_vsf_path.setObjectName("hl_vsf_path") self.label_vsf_path = QLabel(self.vsf_path_widget) self.label_vsf_path.setFont(font) @@ -211,7 +211,7 @@ def tab2UI(self, font): self.le_vsf_path = QLineEdit(self.vsf_path_widget) self.le_vsf_path.setObjectName("le_vsf_path") - self.le_vsf_path.setText(self.get_last_dir('VSFLastPath')) + self.le_vsf_path.setText(self.get_last_dir("VSFLastPath")) self.hl_vsf_path.addWidget(self.le_vsf_path) self.btn_vsf_path = QPushButton(self.vsf_path_widget) @@ -229,7 +229,7 @@ def tab2UI(self, font): self.hl_video_path = QHBoxLayout(self.video_path_widget) self.hl_video_path.setContentsMargins(0, 0, 0, 0) - self.hl_video_path.setObjectName('hl_video_path') + self.hl_video_path.setObjectName("hl_video_path") self.lable_video_dir = QLabel(self.video_path_widget) self.lable_video_dir.setFont(font) @@ -239,7 +239,7 @@ def tab2UI(self, font): self.le_video_path = QLineEdit(self.video_path_widget) self.le_video_path.setObjectName("le_save_path") - self.le_video_path.setText(self.get_last_dir('VideoLastDir')) + self.le_video_path.setText(self.get_last_dir("VideoLastDir")) self.hl_video_path.addWidget(self.le_video_path) self.btn_select_video = QPushButton(self.video_path_widget) @@ -257,7 +257,7 @@ def tab2UI(self, font): self.hl_save_res_path = QHBoxLayout(self.save_video_path_widget) self.hl_save_res_path.setContentsMargins(0, 0, 0, 0) - self.hl_save_res_path.setObjectName('hl_save_res_path') + self.hl_save_res_path.setObjectName("hl_save_res_path") self.save_res_dir = QLabel(self.save_video_path_widget) self.save_res_dir.setFont(font) @@ -267,7 +267,7 @@ def tab2UI(self, font): self.le_save_video_path = QLineEdit(self.save_video_path_widget) self.le_save_video_path.setObjectName("le_save_video_path") - self.le_save_video_path.setText(self.get_last_dir('SaveVideoLastDir')) + self.le_save_video_path.setText(self.get_last_dir("SaveVideoLastDir")) self.hl_save_res_path.addWidget(self.le_save_video_path) self.btn_select_save_video = QPushButton(self.save_video_path_widget) @@ -276,12 +276,12 @@ def tab2UI(self, font): self.btn_select_save_video.clicked.connect(self.select_save_video_dir) self.hl_save_res_path.addWidget(self.btn_select_save_video) - self.tabWidget.addTab(self.tab_vsf_ocr, 'VideoSubFinder + RapidVideOCR') + self.tabWidget.addTab(self.tab_vsf_ocr, "VideoSubFinder + RapidVideOCR") def get_last_dir(self, dir_name: str) -> str: last_dir = self.setting.value(dir_name) if last_dir is None: - last_dir = '' + last_dir = "" return last_dir def set_last_dir(self, dir_name: str, dir_path: str): @@ -291,10 +291,10 @@ def select_vsf_path( self, ) -> None: """选择VSF EXE 路径""" - path_key = 'VSFLastPath' + path_key = "VSFLastPath" vsf_full_path = self.get_last_dir(path_key) vsf_path, _ = QFileDialog.getOpenFileName( - None, caption='选择VSF exe路径', directory=vsf_full_path, filter="*.exe" + None, caption="选择VSF exe路径", directory=vsf_full_path, filter="*.exe" ) self.le_vsf_path.setText(vsf_path) self.set_last_dir(path_key, vsf_path) @@ -303,10 +303,10 @@ def select_video_dir( self, ) -> None: """选择Video 目录或文件""" - dir_key = 'VideoLastDir' + dir_key = "VideoLastDir" directory = self.get_last_dir(dir_key) select_dir = QFileDialog.getExistingDirectory( - None, caption='选择目录', directory=directory + None, caption="选择目录", directory=directory ) self.le_video_path.setText(select_dir) self.set_last_dir(dir_key, select_dir) @@ -315,10 +315,10 @@ def select_save_video_dir( self, ) -> None: """选择保存Video 目录或文件""" - dir_key = 'SaveVideoLastDir' + dir_key = "SaveVideoLastDir" directory = self.get_last_dir(dir_key) select_dir = QFileDialog.getExistingDirectory( - None, caption='选择目录', directory=directory + None, caption="选择目录", directory=directory ) self.le_save_video_path.setText(select_dir) self.set_last_dir(dir_key, select_dir) @@ -327,10 +327,10 @@ def select_img_dir( self, ) -> None: """选择RGBImages目录""" - dir_key = 'LastDir' + dir_key = "LastDir" directory = self.get_last_dir(dir_key) select_dir = QFileDialog.getExistingDirectory( - None, caption='选择目录', directory=directory + None, caption="选择目录", directory=directory ) self.le_display_img_dir.setText(select_dir) self.set_last_dir(dir_key, select_dir) @@ -338,10 +338,10 @@ def select_img_dir( def select_save_srt_dir( self, ) -> None: - srt_key = 'SRTDir' + srt_key = "SRTDir" save_srt_dir = self.get_last_dir(srt_key) file_path, _ = QFileDialog.getSaveFileName( - None, '选择保存路径', f'{save_srt_dir}/result.srt', 'srt(*.srt)' + None, "选择保存路径", f"{save_srt_dir}/result.srt", "srt(*.srt)" ) self.le_save_path.setText(file_path) self.set_last_dir(srt_key, file_path) @@ -360,7 +360,7 @@ def click_ok( elif cur_idx == 1: self.vsf_ocr(is_select_mode, batch_num) - question = QMessageBox.question(self, '识别完毕', '是否继续识别?(Yes → 继续,NO → 退出)') + question = QMessageBox.question(self, "识别完毕", "是否继续识别?(Yes → 继续,NO → 退出)") if question == QMessageBox.Yes: self.clear_input() else: @@ -371,11 +371,11 @@ def only_ocr(self, is_select_mode: bool, batch_num: str): save_full_path = self.le_save_path.text().strip() if not img_dir: - self.show_msg('图像路径不能为空') + self.show_msg("图像路径不能为空") return if not save_full_path: - self.show_msg('保存路径不能为空') + self.show_msg("保存路径不能为空") return is_select_mode = self.rb_rec_mode.isChecked() @@ -396,15 +396,15 @@ def vsf_ocr(self, is_select_mode: bool, batch_num: str): save_dir = self.le_save_video_path.text().strip() if not vsf_exe_path: - self.show_msg('VSF exe路径不能为空') + self.show_msg("VSF exe路径不能为空") return if not video_path: - self.show_msg('视频目录不能为空') + self.show_msg("视频目录不能为空") return if not save_dir: - self.show_msg('保存路径不能为空') + self.show_msg("保存路径不能为空") return extractor = RapidVideoSubFinderOCR( @@ -421,7 +421,7 @@ def click_cancel( self.exit() def show_msg(self, txt: str): - QMessageBox.information(self, '信息', txt) + QMessageBox.information(self, "信息", txt) def exit( self, @@ -431,12 +431,12 @@ def exit( def clear_input( self, ) -> None: - self.le_batch.setText('10') + self.le_batch.setText("10") self.rb_rec_mode.setChecked(False) self.le_display_img_dir.setFocus() -if __name__ == '__main__': +if __name__ == "__main__": app = QApplication(sys.argv) ui = RapidVideOCRUI() ui.show()