def Open(self): """打开视频原文件按钮响应函数""" self.fileName, self.fileType = QFileDialog.getOpenFileName( self.mainWnd, 'Choose file', '', '*.avi') if self.fileName is None or '.avi' not in self.fileName: return elif 'out' not in self.fileName: VedioDate = time.ctime(os.path.getctime(self.fileName)) VedioDate = VedioDate.replace(' ', "_").replace(':', '_').replace('__', '_') PATH.setValue('CVedioDate', VedioDate) self.ui.label_date_text.setText(PATH.get_VedioDate()) self.video_outname = PATH.run_a_red_light_vedio_path() #刷新信息显示 self.ui.label_roadinfo.setText(" 车流量信息展示区域") self.model = QStandardItemModel() #存储任意结构数据 self.model.setHorizontalHeaderLabels(['车牌号码', '违章类型']) self.ui.tableView.horizontalHeader().setSectionResizeMode( QHeaderView.Stretch) self.ui.tableView.setModel(self.model) # 创建视频显示线程 self.Vedioplayname = self.fileName th = threading.Thread(target=self.Display) th.start()
def Open(self): """打开视频原文件按钮响应函数""" self.fileName, self.fileType = QFileDialog.getOpenFileName( self.mainWnd, 'Choose file', '', '*.avi') if self.fileName is None or '.avi' not in self.fileName: return elif 'out' not in self.fileName: VedioDate = time.ctime(os.path.getctime(self.fileName)) VedioDate = VedioDate.replace(' ', "_").replace(':', '_').replace('__', '_') PATH.setValue('CVedioDate', VedioDate) self.ui.label_date_text.setText(PATH.get_VedioDate()) self.video_outname = PATH.run_a_red_light_vedio_path() # 创建视频显示线程 self.Vedioplayname = self.fileName th = threading.Thread(target=self.Display) th.start()
def display_info(self): """展示违法信息""" try: n, m = self.imgnames_list[self.current_img_index].split('_') m = str(m).replace('.jpg', '') self.ui.plate_number.setText(n) self.ui.illegal_type.setText(m) if PATH.bool_alltimes is True: Date = self.date_allroads_list[self.current_img_index] RoadName = PATH.get_roadname() self.current_img_dirpath = PATH.detect_result_path + RoadName + "\\" + Date + "\\illegal_imgs\\" self.ui.label_Road_Belong.setText(RoadName) self.ui.label_Time_Belong.setText(Date) self.ui.label.setPixmap(QPixmap(self.imgpaths[self.current_img_index])) else: self.current_img_dirpath = PATH.run_a_red_light_img_path() self.ui.label_Road_Belong.setText(PATH.get_roadname()) self.ui.label_Time_Belong.setText(PATH.get_VedioDate()) self.ui.label.setPixmap(QPixmap(PATH.run_a_red_light_img_path() + self.imgnames_list[self.current_img_index])) self.ui.label.setScaledContents(True) except: box = QMessageBox.warning(self.wnd, "提示", "库存为空", QMessageBox.Yes)
def out(self): choic_item = self.ui.comboBox.currentText() dirpath = '' if PATH.bool_alltimes == True: #若为所有时间 crutime = gmtime() VedioDate = str(crutime.tm_year) + "所有时间" else: #若为特定时间段 try: time = PATH.get_VedioDate() print(time) timelist = time.split('_') VedioDate = timelist[6] + '_' + timelist[2] + '_' + timelist[3] except: crutime = gmtime() VedioDate = str(crutime.tm_year) + "_" + str( crutime.tm_mon) + "_" + str(crutime.tm_mday) with open(PATH.run_a_red_lightpath(), 'r', encoding='UTF-8') as fp: data = [] data_dict = {} data = fp.readlines() if '\n' in data: data.remove('\n') data_row = len(data) for i in range(data_row): plate_number, ilegal_type = data[i].split(' ') ilegal_type = ilegal_type.replace('\n', '') data_dict[plate_number] = ilegal_type if choic_item == 'Excel文件': dirpath = QFileDialog.getSaveFileName( self.wnd, '选择保存路径', PATH.DeskTop_path + PATH.get_roadname() + "_" + VedioDate + '.xlsx', 'xlsx(*.xlsx)') if dirpath[0] != '': row, col = 1, 0 workbook = xlsxwriter.Workbook(dirpath[0]) worksheet = workbook.add_worksheet('违法记录') title = ['车牌号码', '违法类型'] worksheet.write(0, 0, title[0]) worksheet.write(0, 1, title[1]) for key in data_dict: worksheet.write(row, col, key) worksheet.write(row, col + 1, data_dict[key]) row = row + 1 workbook.close() else: return #退出窗口 self.ui.Quit.click() elif choic_item == 'Txt文件': dirpath = QFileDialog.getSaveFileName( self.wnd, '选择保存路径', PATH.DeskTop_path + PATH.get_roadname() + "_" + VedioDate + '.txt', 'Text Files(*.txt)') if dirpath[0] != '': with open(dirpath[0], 'w', newline='', encoding='UTF-8') as txt_file: title = ['车牌号码 ', '违法类型\n'] txt_file.writelines(title) txt_file.writelines(data) else: return #退出窗口 self.ui.Quit.click() try: os.system(dirpath[0]) except: box = QMessageBox.information(self.wnd, "提示", "创建文件失败", QMessageBox.Yes)