def delet_info(self): """删除展示车辆的违法信息""" box = QMessageBox.warning(self.wnd, "提示", "确定删除该车辆的违法信息?", QMessageBox.Yes | QMessageBox.No) if box == QMessageBox.No: return else: try: del_name_path = self.imgnames_list.pop(self.current_img_index) del_name = del_name_path[0:7] if PATH.bool_alltimes is True: os.remove(self.imgpaths[self.current_img_index]) _ = self.imgpaths[self.current_img_index].split("\\") txtpath = PATH.Road_ROOTpath() + _[4] + "\\illegal_car_info.txt" else: os.remove(PATH.run_a_red_light_img_path() + del_name_path) txtpath = PATH.run_a_red_lightpath() with open(txtpath, 'r', encoding='UTF-8') as fp: lines = fp.readlines() for i in range(len(lines)): if del_name in lines[i]: lines[i] = '' fp.close() with open(txtpath, 'w', encoding='UTF-8') as fp: fp.writelines(lines) box = QMessageBox.warning(self.wnd, "提示", "删除成功!", QMessageBox.Yes) except: box = QMessageBox.warning(self.wnd, "提示", "删除错误", QMessageBox.Yes) self.current_img_index = 0 self.display_info()
def show_processed_vedio(self): """显示detected视频以及违法信息""" #违章表格初始化 with open(PATH.run_a_red_lightpath(), 'r', encoding='UTF-8') as fp: data = [] data = fp.readlines() if '\n' in data: data.remove('\n') row_lenth = len(data) self.ui.label_roadinfo.setPixmap(QPixmap(PATH.infomation_path())) self.ui.label_roadinfo.setScaledContents(True) self.model = QStandardItemModel() #存储任意结构数据 self.model.setHorizontalHeaderLabels(['车牌号码', '违章类型']) self.ui.tableView.horizontalHeader().setSectionResizeMode( QHeaderView.Stretch) for row in range(row_lenth): plate_number, ilegal_type = data[row].split(' ') ilegal_type = ilegal_type.replace('\n', '') i = QStandardItem(plate_number) j = QStandardItem(ilegal_type) self.model.setItem(row, 0, i) self.model.setItem(row, 1, j) self.ui.tableView.setModel(self.model) # 创建视频显示线程 if self.specialroad is not True: self.Vedioplayname = self.video_outname self.th1 = threading.Thread(target=self.Display) self.th1.start()
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)