def openVideo(self): if not os.path.exists(SystemInfo.default_dir): SystemInfo.default_dir = '' videoName, videoType = QFileDialog.getOpenFileName( self, "打开视频", SystemInfo.default_dir, # " *.jpg;;*.png;;*.jpeg;;*.bmp") " *.mp4;;*.avi;;All Files (*)") if videoName == "" or not videoName: SystemInfo.log("System", "未打开视屏!") return self.setWidgetsStatus(True) if SystemInfo.video_is_opened: try: SystemInfo.video.release() self.clearTime() except: print("Do not played") print("Open New Video") else: SystemInfo.log('user', "First open video") self.projectWidget.selectComboBox.addItem(videoName) SystemInfo.video_name.append([videoName, videoType]) self.getVideoInfo(videoName) self.videoOperateWidget.updateUI() self.setWidget.updateVideoInfoUI() self.setImage(self.readVideo(SystemInfo.video))
def getDetectSet(self): try: if SystemInfo.detect_area_flag: self.updateVideoArea() except: SystemInfo.log("System", '获取坐标失败!') # try: # if SystemInfo.detect_area_flag: # self.getVideoArea() # print(SystemInfo.detect_area) # except: # print("[System]Get Area Fail") SystemInfo.detect_set_step = int(self.setWidget.step.text())
def run(self): with QMutexLocker(self.mutex): self.stopped = False while SystemInfo.video.isOpened() == True: # start time time_start = time.time() # check if play to end if SystemInfo.video_total_fps == SystemInfo.video_now_fps: self._buttonSignal.emit(True) return if SystemInfo.video_mode: max_detect_pos = max(SystemInfo.detect_info['detect_frame']) # when comes to error value emit a signal to show message # self.warnSignal.emit("123","890") # return # SystemInfos.video.set(cv2.CAP_PROP_POS_FRAMES, v) success, frame = SystemInfo.video.read() if success: rgbImage = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) detect_index = int( SystemInfo.video_now_fps / SystemInfo.detect_step) * SystemInfo.detect_step if detect_index in SystemInfo.detect_info['detect_frame']: index = SystemInfo.detect_info['detect_frame'].index( detect_index) for i in range( 0, len(SystemInfo.detect_info['tag_label'] [index])): center = np.round( SystemInfo.detect_info['tag_center'][index] [i]).astype(int) cv2.putText( rgbImage, str(SystemInfo.detect_info['tag_label'][index] [i]), (center[0], center[1]), cv2.FONT_HERSHEY_COMPLEX, 2.0, (100, 200, 200), 5) convertToQtFormat = QtGui.QImage( rgbImage.data, rgbImage.shape[1], rgbImage.shape[0], QImage.Format_RGB888) # 在这里可以对每帧图像进行处理, self.videoImage.emit( convertToQtFormat.scaled( SystemInfo.video_label_hint_size[0], SystemInfo.video_label_hint_size[1], Qt.KeepAspectRatio)) else: success, frame = SystemInfo.video.read() if success: rgbImage = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) convertToQtFormat = QtGui.QImage( rgbImage.data, rgbImage.shape[1], rgbImage.shape[0], QImage.Format_RGB888) # 在这里可以对每帧图像进行处理, SystemInfo.log( "System", "Play {} frame".format(SystemInfo.video_now_fps)) self.videoImage.emit( convertToQtFormat.scaled( SystemInfo.video_label_hint_size[0], SystemInfo.video_label_hint_size[1], Qt.KeepAspectRatio)) # [!]add into cache # if SystemInfos.video_now_fps > SystemInfos.video_cache_fps: if SystemInfo.video_now_fps % SystemInfo.video_fps == 0: SystemInfo.video_now_time += 1 SystemInfo.video_now_fps += 1 time_end = time.time() self.timeSignal.emit() # deal operate button's status if SystemInfo.video_is_play == False: self._buttonSignal.emit(True) return else: self._buttonSignal.emit(False) if time_end - time_start < (1 / SystemInfo.video_fps): time.sleep(1 / SystemInfo.video_fps - (time_end - time_start))
SystemInfo.video_now_fps += 1 time_end = time.time() self.timeSignal.emit() # deal operate button's status if SystemInfo.video_is_play == False: self._buttonSignal.emit(True) return else: self._buttonSignal.emit(False) if time_end - time_start < (1 / SystemInfo.video_fps): time.sleep(1 / SystemInfo.video_fps - (time_end - time_start)) def videoStop(self): SystemInfo.video_is_play = False def resume(self): SystemInfo.video_is_play = True self.start() if __name__ == '__main__': app = QApplication(sys.argv) gui = MainWindow() SystemInfo.main_view = gui gui.showMaximized() # gui.showFullScreen() sys.exit(app.exec_()) SystemInfo.log("System", "Start")