class videoPlayer(QWidget): # 视频播放类 def __init__(self, parent=None): # 构造函数 super(videoPlayer, self).__init__(parent=parent) # 类的继承 self.mainwindow = parent self.length = 0 # 视频总时长 self.position = 0 # 视频当前时长 self.count = 0 self.player_status = -1 # 设置窗口 self.setGeometry(300, 50, 800, 600) #大小,与桌面放置位置 # self.setWindowIcon(QIcon(':/images/video_player_icon.png')) # 程序图标 # self.setWindowTitle(titleName) # 窗口名称 # self.setWindowFlags(Qt.WindowCloseButtonHint | Qt.WindowMinimizeButtonHint) # 设置窗口背景 self.palette = QPalette() self.palette.setColor(QPalette.Background, Qt.black) self.setPalette(self.palette) self.now_position = QLabel("/ 00:00") # 目前时间进度 self.all_duration = QLabel('00:00') # 总的时间进度 self.all_duration.setStyleSheet('''QLabel{color:#000000}''') self.now_position.setStyleSheet('''QLabel{color:#000000}''') #视频插件 self.video_widget = QVideoWidget(self) self.video_widget.setGeometry(QRect(0, 0, 1200, 700)) #大小,与桌面放置位置 #self.video_widget.resize(1200, 700) # 设置插件宽度与高度 #self.video_widget.move(0, 30) # 设置插件放置位置 self.video_palette = QPalette() self.video_palette.setColor(QPalette.Background, Qt.black) # 设置播放器背景 self.video_widget.setPalette(self.video_palette) video_widget_color = "background-color:#000000" self.video_widget.setStyleSheet(video_widget_color) #布局容器 self.verticalLayout = QVBoxLayout() self.verticalLayout.setSpacing(0) #self.verticalLayout.setContentsMargins(0, 5, 0, 10) self.layout = QHBoxLayout() self.layout.setSpacing(15) # 各个插件的间距 # 设置播放器 self.player = QMediaPlayer(self) self.player.setVideoOutput(self.video_widget) #设置播放按钮事件 self.player.durationChanged.connect(self.get_duration_func) # self.player.positionChanged.connect(self.progress) # 媒体播放时发出信号 self.player.mediaStatusChanged.connect(self.playerStatusChanged) self.player.error.connect(self.player_error) # 播放按钮 self.play_btn = QPushButton(self) self.play_btn.setIcon(QIcon(':/images/play_btn_icon.png')) # 设置按钮图标,下同 self.play_btn.setIconSize(QSize(35, 35)) self.play_btn.setStyleSheet( '''QPushButton{border:none;}QPushButton:hover{border:none;border-radius:35px;}''' ) self.play_btn.setCursor(QCursor(Qt.PointingHandCursor)) self.play_btn.setToolTip("播放") self.play_btn.setFlat(True) #self.play_btn.hide() #isHidden() #判定控件是否隐藏 #isVisible() 判定控件是否显示 self.play_btn.clicked.connect(self.start_button) #音量条 self.volume_slider = QSlider(Qt.Horizontal) # 声音设置 self.volume_slider.setMinimum(0) # 音量0到100 self.volume_slider.setMaximum(100) self.volume_slider.valueChanged.connect(self.volumes_change) self.volume_slider.setStyleSheet('''QSlider{} QSlider::sub-page:horizontal:disabled{background: #00009C; border-color: #999; } QSlider::add-page:horizontal:disabled{background: #eee; border-color: #999; } QSlider::handle:horizontal:disabled{background: #eee; border: 1px solid #aaa; border-radius: 4px; } QSlider::add-page:horizontal{background: #575757; border: 0px solid #777; height: 10px;border-radius: 2px; } QSlider::handle:horizontal:hover{background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.6 #2A8BDA, stop:0.778409 rgba(255, 255, 255, 255)); width: 11px; margin-top: -3px; margin-bottom: -3px; border-radius: 5px; } QSlider::sub-page:horizontal{background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #B1B1B1, stop:1 #c4c4c4); background: qlineargradient(x1: 0, y1: 0.2, x2: 1, y2: 1,stop: 0 #5DCCFF, stop: 1 #1874CD); border: 1px solid #4A708B; height: 10px; border-radius: 2px; } QSlider::groove:horizontal{border: 1px solid #4A708B; background: #C0C0C0; height: 5px; border-radius: 1px; padding-left:-1px; padding-right:-1px;} QSlider::handle:horizontal{background: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.6 #45ADED, stop:0.778409 rgba(255, 255, 255, 255)); width: 11px; margin-top: -3px; margin-bottom: -3px; border-radius: 5px; }''' ) #视频播放进度条 self.video_slider = QSlider(Qt.Horizontal, self) # 视频进度拖拖动 self.video_slider.setMinimum(0) # 视频进度0到100% #self.video_slider.setMaximum(100) self.video_slider.setSingleStep(1) self.video_slider.setGeometry(QRect(0, 0, 200, 10)) self.video_slider.sliderReleased.connect(self.video_silder_released) self.video_slider.sliderPressed.connect(self.video_silder_pressed) self.video_slider.setStyleSheet('''QSlider{} QSlider::sub-page:horizontal:disabled{background: #00009C; border-color: #999; } QSlider::add-page:horizontal:disabled{background: #eee; border-color: #999; } QSlider::handle:horizontal:disabled{background: #eee; border: 1px solid #aaa; border-radius: 4px; } QSlider::add-page:horizontal{background: #575757; border: 0px solid #777; height: 10px;border-radius: 2px; } QSlider::handle:horizontal:hover{background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.6 #2A8BDA, stop:0.778409 rgba(255, 255, 255, 255)); width: 11px; margin-top: -3px; margin-bottom: -3px; border-radius: 5px; } QSlider::sub-page:horizontal{background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #B1B1B1, stop:1 #c4c4c4); background: qlineargradient(x1: 0, y1: 0.2, x2: 1, y2: 1,stop: 0 #5DCCFF, stop: 1 #1874CD); border: 1px solid #4A708B; height: 10px; border-radius: 2px; } QSlider::groove:horizontal{border: 1px solid #4A708B; background: #C0C0C0; height: 5px; border-radius: 1px; padding-left:-1px; padding-right:-1px;} QSlider::handle:horizontal{background: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.6 #45ADED, stop:0.778409 rgba(255, 255, 255, 255)); width: 11px; margin-top: -3px; margin-bottom: -3px; border-radius: 5px; }''' ) #静音按钮 self.mute_button = QPushButton('') self.mute_button.clicked.connect(self.mute) self.mute_button.setIconSize(QSize(30, 30)) self.mute_button.setStyleSheet( '''QPushButton{border:none;}QPushButton:hover{border:none;}''') self.mute_button.setCursor(QCursor(Qt.PointingHandCursor)) self.mute_button.setToolTip("播放") self.mute_button.setFlat(True) self.mute_button.setIcon(QIcon(':/images/sound_btn_icon.png')) #暂停按钮 self.pause_btn = QPushButton('') self.pause_btn.setIcon(QIcon(':/images/stop_btn_icon.png')) self.pause_btn.clicked.connect(self.stop_button) self.pause_btn.setIconSize(QSize(35, 35)) self.pause_btn.setStyleSheet( '''QPushButton{border:none;}QPushButton:hover{border:none;}''') self.pause_btn.setCursor(QCursor(Qt.PointingHandCursor)) self.pause_btn.setToolTip("播放") self.pause_btn.setFlat(True) self.pause_btn.hide() #音量值和音量显示标签 self.volume_value = QLabel() self.volume_value.setText(' ' * 5) self.volume_value.setStyleSheet('''QLabel{color:#000000;}''') self.volume_t = QLabel() self.volume_t.setStyleSheet('''QLabel{color:#000000;}''') #视频文件打开按钮 self.open_btn = QPushButton('Open') self.open_btn.clicked.connect(self.getfile) #全屏按钮 self.screen_btn = QPushButton('') self.screen_btn.setIcon( QIcon(QPixmap(':/images/fullsrceen_btn_icon.png'))) self.screen_btn.setIconSize(QSize(38, 38)) self.screen_btn.setStyleSheet( '''QPushButton{border:none;}QPushButton:hover{border:1px solid #F3F3F5;border-radius:35px;}''' ) self.screen_btn.setCursor(QCursor(Qt.PointingHandCursor)) self.screen_btn.setToolTip("播放") self.screen_btn.setFlat(True) self.screen_btn.clicked.connect(self.fullscreen) #添加按钮组件 self.verticalLayout.addStretch() self.layout.addWidget(self.play_btn, 0, Qt.AlignCenter | Qt.AlignVCenter) self.layout.addWidget(self.pause_btn, 0, Qt.AlignCenter | Qt.AlignVCenter) # 插件,与前一个模块的距离,位置 self.layout.addWidget(self.all_duration, 0, Qt.AlignCenter | Qt.AlignVCenter) self.layout.addWidget(self.now_position, 0, Qt.AlignCenter | Qt.AlignVCenter) self.layout.addWidget(self.video_slider, 15, Qt.AlignVCenter | Qt.AlignVCenter) self.layout.addWidget(self.mute_button, 0, Qt.AlignCenter | Qt.AlignVCenter) self.layout.addWidget(self.volume_slider, 0, Qt.AlignCenter | Qt.AlignVCenter) self.layout.addWidget(self.volume_value, 0, Qt.AlignCenter | Qt.AlignVCenter) #self.layout.addWidget(self.screen_btn) #self.layout.addWidget(self.open_btn) self.verticalLayout.addLayout(self.layout) #self.verticalLayout.addLayout(self.layout) self.setLayout(self.verticalLayout) def player_error(self, errorCode): print('error = ' + str(errorCode)) try: if errorCode == 0: pass elif errorCode == 1: self.showAlertWindow('errorCode:1 \n\n无效视频源。') elif errorCode == 2: self.showAlertWindow('errorCode:2 \n\n不支持的媒体格式') elif errorCode == 3: self.showAlertWindow('errorCode:3 \n\n网络错误') elif errorCode == 4: self.showAlertWindow('errorCode:4 \n\n没有权限播放该视频') elif errorCode == 5: self.showAlertWindow('errorCode:5 \n\n视频服务不存在,无法继续播放。') else: self.showAlertWindow('未知错误') except: self.showAlertWindow('视频加载异常') def video_silder_pressed(self): if self.player.state != 0: self.player.pause() def playerStatusChanged(self, status): self.player_status = status if status == 7: self.play_btn.show() self.pause_btn.hide() #print('playerStatusChanged =' + str(status) + '...............') def resizeEvent(self, e): #print(e.size().width(), e.size().height()) newSize = e.size() self.video_widget.setGeometry(0, 0, newSize.width(), newSize.height() - 50) #self.video_widget.setGeometry(0, 0, 0, 0) def closeEvent(self, e): self.player.stop() def get_duration_func(self, d): try: end_number = int(d / 1000 / 10) + 1 #print('end_number = ' + str(end_number)) sum = 0 for n in range(1, end_number): sum = sum + n vv = int((100 / (d / 1000)) * (d / 1000)) self.video_slider.setMaximum(d) #self.video_slider.setMaximum(vv + sum) #print(100 + sum) all_second = int(d / 1000 % 60) # 视频播放时间 all_minute = int(d / 1000 / 60) if all_minute < 10: if all_second < 10: self.all_duration.setText('0' + str(all_minute) + ':0' + str(all_second)) else: self.all_duration.setText('0' + str(all_minute) + ':' + str(all_second)) else: if all_second < 10: self.all_duration.setText( str(all_minute) + ':0' + str(all_second)) else: self.all_duration.setText( str(all_minute) + ':' + str(all_second)) except Exception as e: pass def mouseDoubleClickEvent(self, e): try: #print('mouseDoubleClickEvent................... = ' + str(self.player.state())) if self.player.state() == 2: #视频暂停 self.player.play() self.play_btn.hide() self.pause_btn.show() elif self.player.state() == 1: # 正在播放 self.player.pause() self.play_btn.show() self.pause_btn.hide() else: #视频停止 self.play_btn.hide() self.pause_btn.show() self.player.setPosition(0) self.video_slider.setValue(0) self.player.play() except Exception as e: pass def start_button(self): # 视频播放按钮 try: self.play_btn.hide() self.pause_btn.show() if self.player_status == 7: self.video_slider.setValue(0) self.player.setPosition(0) self.player.play() except Exception as e: pass def stop_button(self): # 视频暂停按钮 self.play_btn.show() self.pause_btn.hide() self.player.pause() def getfile(self, filepath): # 打开视频文件 try: #print(str(filepath)) url = QUrl.fromLocalFile(filepath) if url.isValid(): self.player.setMedia(QMediaContent(url)) # 返回该文件地址,并把地址放入播放内容中 self.player.setVolume(50) # 设置默认打开音量即为音量条大小 self.volume_value.setText(str(50)) self.volume_slider.setValue(50) else: self.showAlertWindow('视频地址无效') except Exception as e: self.showAlertWindow() def clearVolumeValue(): self.volume_value.setText(' ' * 5) def volumes_change(self): # 拖动进度条设置声音 try: size = self.volume_slider.value() if size: # 但进度条的值不为0时,此时音量不为静音,音量值即为进度条值 self.player.setMuted(False) self.player.setVolume(size) volume_value = str(size) + ' ' * 4 self.volume_value.setText(volume_value) #print(size) self.mute_button.setIcon(QIcon(':/images/sound_btn_icon.png')) else: self.player.setMuted(True) self.mute_button.setIcon(QIcon(':/images/mute_btn_icon.png')) self.player.setVolume(0) volume_value = '0' + ' ' * 4 self.volume_value.setText(volume_value) if len(str(size)) == 1: volume_value = str(size) + ' ' * 4 elif len(str(size)) == 2: volume_value = str(size) + ' ' * 3 else: volume_value = str(size) + ' ' * 2 self.volume_value.setText(volume_value) except Exception as e: pass def mute(self): try: if self.player.isMuted(): self.mute_button.setIcon(QIcon(':/images/sound_btn_icon.png')) self.player.setMuted(False) self.volume_slider.setValue(50) volume_value = '50' + ' ' * 4 self.volume_value.setText(volume_value) else: self.mute_button.setIcon(QIcon(':/images/mute_btn_icon.png')) self.player.setMuted(True) # 若不为静音,则设置为静音,音量置为0 self.volume_slider.setValue(0) volume_value = '0' + ' ' * 4 self.volume_value.setText(volume_value) except Exception as e: pass def progress(self): # 视频进度条自动释放与播放时间 try: self.length = self.player.duration() + 1 self.position = self.player.position() #print(str(self.length) + ':' + str(self.position)) self.count += 1 video_silder_maximum = self.video_slider.maximum() #video_silder_value = int(((video_silder_maximum / (self.length / 1000)) * (self.position / 1000))) #self.video_slider.setValue(video_silder_value + self.count) self.video_slider.setValue(self.position) #print('video_slider_value = ' + str(video_silder_value + self.count)) now_second = int(self.position / 1000 % 60) now_minute = int(self.position / 1000 / 60) self.mainwindow.resultlist2.addItem("{0:02d} : {1:02d}".format( now_minute, now_second)) #print(str(now_minute) + ':' + str(now_second)) if now_minute < 10: if now_second < 10: self.now_position.setText('/ 0' + str(now_minute) + ':0' + str(now_second)) else: self.now_position.setText('/ 0' + str(now_minute) + ':' + str(now_second)) else: #print('now_minute < 10' + str(now_minute) + ':' + str(now_second)) if now_second < 10: #print('now_second < 10' + str(now_minute) + ':' + str(now_second)) #self.now_position.setText(str(now_minute) + ':0' + str(now_second)) self.now_position.setText('/ ' + str(now_minute) + ':0' + str(now_second)) else: #print('now_second > 10' + str(now_minute) + ':' + str(now_second)) self.now_position.setText('/ ' + str(now_minute) + ':' + str(now_second)) except Exception as e: pass def video_silder_released(self): # 释放滑条时,改变视频播放进度 try: #print('video_silder_released......') if self.player.state() != 0: self.player.setPosition(self.video_slider.value()) self.player.play() else: #如果视频是停止状态,则拖动进度条无效 self.video_slider.setValue(0) except Exception as e: pass def fullscreen(self): self.showFullScreen() def keyPressEvent(self, event): # 重新改写按键 if event.key() == Qt.Key_Escape: self.winquit() def winquit(self): # 退出窗口 self.showNormal() def showAlertWindow(self, msg='视频加载出错!'): reply = QMessageBox.information(self, "消息框标题", msg, QMessageBox.Yes) def setWindowTitleName(self, titleName): self.setWindowTitle(titleName) # 窗口名称
class Ui_NewProject(object): def setupUi(self, NewProject): NewProject.setObjectName("NewProject") NewProject.resize(736, 625) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/plugins/Video_UAV_Tracker/icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) NewProject.setWindowIcon(icon) self.gridLayout_2 = QtWidgets.QGridLayout(NewProject) self.gridLayout_2.setObjectName("gridLayout_2") self.gridLayout = QtWidgets.QGridLayout() self.gridLayout.setObjectName("gridLayout") self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.video_frame_2 = QVideoWidget(NewProject) p = self.video_frame_2.palette() p.setColor(QtGui.QPalette.Window, QtCore.Qt.black) self.video_frame_2.setPalette(p) self.video_frame_2.setAttribute(QtCore.Qt.WA_OpaquePaintEvent) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.video_frame_2.sizePolicy().hasHeightForWidth()) self.video_frame_2.setSizePolicy(sizePolicy) self.video_frame_2.setStyleSheet("background-color: rgb(0, 0, 0);") self.video_frame_2.setObjectName("video_frame_2") self.horizontalLayout.addWidget(self.video_frame_2) self.gridLayout.addLayout(self.horizontalLayout, 0, 0, 1, 15) self.horizontalSlider = QtWidgets.QSlider(NewProject) self.horizontalSlider.setOrientation(QtCore.Qt.Horizontal) self.horizontalSlider.setObjectName("horizontalSlider") self.gridLayout.addWidget(self.horizontalSlider, 1, 0, 1, 15) self.replayPlay_pushButton = QtWidgets.QPushButton(NewProject) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.replayPlay_pushButton.sizePolicy().hasHeightForWidth()) self.replayPlay_pushButton.setSizePolicy(sizePolicy) self.replayPlay_pushButton.setCheckable(False) self.replayPlay_pushButton.setChecked(False) self.replayPlay_pushButton.setObjectName("replayPlay_pushButton") self.gridLayout.addWidget(self.replayPlay_pushButton, 3, 1, 1, 1) self.replayPosition_label = QtWidgets.QLabel(NewProject) self.replayPosition_label.setObjectName("replayPosition_label") self.gridLayout.addWidget(self.replayPosition_label, 3, 4, 1, 1) self.muteButton = QtWidgets.QToolButton(NewProject) self.muteButton.setText("") self.muteButton.setObjectName("muteButton") self.gridLayout.addWidget(self.muteButton, 3, 2, 1, 1) self.comboBox = QtWidgets.QComboBox(NewProject) self.comboBox.setObjectName("comboBox") self.gridLayout.addWidget(self.comboBox, 3, 14, 1, 1) self.pushButton_2 = QtWidgets.QPushButton(NewProject) self.pushButton_2.setObjectName("pushButton_2") self.gridLayout.addWidget(self.pushButton_2, 3, 12, 1, 1) self.toolButton_3 = QtWidgets.QToolButton(NewProject) icon1 = QtGui.QIcon() icon1.addPixmap(QtGui.QPixmap(":/plugins/Video_UAV_Tracker/mIconFormSelect.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.toolButton_3.setIcon(icon1) self.toolButton_3.setObjectName("toolButton_3") self.gridLayout.addWidget(self.toolButton_3, 3, 11, 1, 1) self.toolButton_2 = QtWidgets.QToolButton(NewProject) icon2 = QtGui.QIcon() icon2.addPixmap(QtGui.QPixmap(":/VgisIcon/mActionAtlasNext.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.toolButton_2.setIcon(icon2) self.toolButton_2.setObjectName("toolButton_2") self.gridLayout.addWidget(self.toolButton_2, 3, 9, 1, 1) self.SkipFortoolButton_8 = QtWidgets.QToolButton(NewProject) self.SkipFortoolButton_8.setStyleSheet("") icon3 = QtGui.QIcon() icon3.addPixmap(QtGui.QPixmap(":/VgisIcon/mActionArrowRight.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.SkipFortoolButton_8.setIcon(icon3) self.SkipFortoolButton_8.setObjectName("SkipFortoolButton_8") self.gridLayout.addWidget(self.SkipFortoolButton_8, 3, 8, 1, 1) self.SkipBacktoolButton_7 = QtWidgets.QToolButton(NewProject) self.SkipBacktoolButton_7.setStyleSheet("") icon4 = QtGui.QIcon() icon4.addPixmap(QtGui.QPixmap(":/VgisIcon/mActionArrowLeft.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.SkipBacktoolButton_7.setIcon(icon4) self.SkipBacktoolButton_7.setObjectName("SkipBacktoolButton_7") self.gridLayout.addWidget(self.SkipBacktoolButton_7, 3, 7, 1, 1) self.toolButton = QtWidgets.QToolButton(NewProject) icon5 = QtGui.QIcon() icon5.addPixmap(QtGui.QPixmap(":/VgisIcon/mActionAtlasPrev.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.toolButton.setIcon(icon5) self.toolButton.setObjectName("toolButton") self.gridLayout.addWidget(self.toolButton, 3, 6, 1, 1) self.pushButton = QtWidgets.QPushButton(NewProject) self.pushButton.setObjectName("pushButton") self.gridLayout.addWidget(self.pushButton, 3, 0, 1, 1) self.gridLayout_2.addLayout(self.gridLayout, 0, 0, 1, 1) self.retranslateUi(NewProject) QtCore.QMetaObject.connectSlotsByName(NewProject) def retranslateUi(self, NewProject): _translate = QtCore.QCoreApplication.translate NewProject.setWindowTitle(_translate("NewProject", "Video UAV Tracker - New Project")) self.replayPlay_pushButton.setText(_translate("NewProject", "Play/Pause")) self.replayPosition_label.setText(_translate("NewProject", "-:- / -:-")) self.pushButton_2.setToolTip(_translate("NewProject", "<html><head/><body><p>Synchronize actual video frame with selected GPS time</p></body></html>")) self.comboBox.setToolTip(_translate("NewProject", "<html><head/><body><p> GPS time</p></body></html>")) self.pushButton_2.setText(_translate("NewProject", "Synchronize!")) self.toolButton_3.setToolTip(_translate("NewProject", "<html><head/><body><p>Add point shape database to project</p></body></html>")) #self.toolButton_3.setText(_translate("NewProject", "DB")) self.toolButton_2.setToolTip(_translate("NewProject", "<html><head/><body><p>Next second</p></body></html>")) self.toolButton_2.setText(_translate("NewProject", ">>")) self.SkipFortoolButton_8.setToolTip(_translate("NewProject", "<html><head/><body><p>Next frame</p></body></html>")) self.SkipFortoolButton_8.setText(_translate("NewProject", ">")) self.SkipBacktoolButton_7.setToolTip(_translate("NewProject", "<html><head/><body><p>Previous frame</p></body></html>")) self.SkipBacktoolButton_7.setText(_translate("NewProject", "<")) self.toolButton.setToolTip(_translate("NewProject", "<html><head/><body><p>Previous second</p></body></html>")) self.toolButton.setText(_translate("NewProject", "<<")) self.pushButton.setToolTip(_translate("NewProject", "<html><head/><body><p>Select video and relative gpx</p></body></html>")) self.pushButton.setText(_translate("NewProject", "Select Video and GPX"))
class Ui_NewProject(object): def setupUi(self, NewProject): NewProject.setObjectName("NewProject") NewProject.resize(736, 625) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/plugins/VideoGis/icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) NewProject.setWindowIcon(icon) self.gridLayout_2 = QtWidgets.QGridLayout(NewProject) self.gridLayout_2.setObjectName("gridLayout_2") self.gridLayout = QtWidgets.QGridLayout() self.gridLayout.setObjectName("gridLayout") self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.video_frame_2 = QVideoWidget(NewProject) p = self.video_frame_2.palette() p.setColor(QtGui.QPalette.Window, QtCore.Qt.black) self.video_frame_2.setPalette(p) self.video_frame_2.setAttribute(QtCore.Qt.WA_OpaquePaintEvent) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.video_frame_2.sizePolicy().hasHeightForWidth()) self.video_frame_2.setSizePolicy(sizePolicy) self.video_frame_2.setStyleSheet("background-color: rgb(0, 0, 0);") self.video_frame_2.setObjectName("video_frame_2") self.horizontalLayout.addWidget(self.video_frame_2) self.gridLayout.addLayout(self.horizontalLayout, 0, 0, 1, 16) self.horizontalSlider = QtWidgets.QSlider(NewProject) self.horizontalSlider.setOrientation(QtCore.Qt.Horizontal) self.horizontalSlider.setObjectName("horizontalSlider") self.gridLayout.addWidget(self.horizontalSlider, 1, 0, 1, 16) self.replayPlay_pushButton = QtWidgets.QPushButton(NewProject) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.replayPlay_pushButton.sizePolicy().hasHeightForWidth()) self.replayPlay_pushButton.setSizePolicy(sizePolicy) self.replayPlay_pushButton.setCheckable(False) self.replayPlay_pushButton.setChecked(False) self.replayPlay_pushButton.setObjectName("replayPlay_pushButton") self.gridLayout.addWidget(self.replayPlay_pushButton, 3, 1, 1, 1) self.replayPosition_label = QtWidgets.QLabel(NewProject) self.replayPosition_label.setObjectName("replayPosition_label") self.gridLayout.addWidget(self.replayPosition_label, 3, 4, 1, 1) self.muteButton = QtWidgets.QToolButton(NewProject) self.muteButton.setText("") self.muteButton.setObjectName("muteButton") self.gridLayout.addWidget(self.muteButton, 3, 2, 1, 1) self.comboBox = QtWidgets.QComboBox(NewProject) self.comboBox.setObjectName("comboBox") self.gridLayout.addWidget(self.comboBox, 3, 15, 1, 1) self.pushButton_2 = QtWidgets.QPushButton(NewProject) self.pushButton_2.setObjectName("pushButton_2") self.gridLayout.addWidget(self.pushButton_2, 3, 13, 1, 1) self.toolButton_3 = QtWidgets.QToolButton(NewProject) icon1 = QtGui.QIcon() icon1.addPixmap( QtGui.QPixmap(":/plugins/VideoGis/mIconFormSelect.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.toolButton_3.setIcon(icon1) self.toolButton_3.setObjectName("toolButton_3") self.gridLayout.addWidget(self.toolButton_3, 3, 11, 1, 1) self.toolButton_2 = QtWidgets.QToolButton(NewProject) icon2 = QtGui.QIcon() icon2.addPixmap(QtGui.QPixmap(":/VgisIcon/mActionAtlasNext.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.toolButton_2.setIcon(icon2) self.toolButton_2.setObjectName("toolButton_2") self.gridLayout.addWidget(self.toolButton_2, 3, 9, 1, 1) self.SkipFortoolButton_8 = QtWidgets.QToolButton(NewProject) self.SkipFortoolButton_8.setStyleSheet("") icon3 = QtGui.QIcon() icon3.addPixmap(QtGui.QPixmap(":/VgisIcon/mActionArrowRight.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.SkipFortoolButton_8.setIcon(icon3) self.SkipFortoolButton_8.setObjectName("SkipFortoolButton_8") self.gridLayout.addWidget(self.SkipFortoolButton_8, 3, 8, 1, 1) self.SkipBacktoolButton_7 = QtWidgets.QToolButton(NewProject) self.SkipBacktoolButton_7.setStyleSheet("") icon4 = QtGui.QIcon() icon4.addPixmap(QtGui.QPixmap(":/VgisIcon/mActionArrowLeft.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.SkipBacktoolButton_7.setIcon(icon4) self.SkipBacktoolButton_7.setObjectName("SkipBacktoolButton_7") self.gridLayout.addWidget(self.SkipBacktoolButton_7, 3, 7, 1, 1) self.toolButton = QtWidgets.QToolButton(NewProject) icon5 = QtGui.QIcon() icon5.addPixmap(QtGui.QPixmap(":/VgisIcon/mActionAtlasPrev.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.toolButton.setIcon(icon5) self.toolButton.setObjectName("toolButton") self.gridLayout.addWidget(self.toolButton, 3, 6, 1, 1) self.pushButton = QtWidgets.QPushButton(NewProject) self.pushButton.setObjectName("pushButton") self.gridLayout.addWidget(self.pushButton, 3, 0, 1, 1) self.toolButton_4 = QtWidgets.QToolButton(NewProject) self.toolButton_4.setObjectName("toolButton_4") self.gridLayout.addWidget(self.toolButton_4, 3, 12, 1, 1) self.checkBox = QtWidgets.QCheckBox(NewProject) self.checkBox.setObjectName("checkBox") self.gridLayout.addWidget(self.checkBox, 3, 14, 1, 1) self.gridLayout_2.addLayout(self.gridLayout, 0, 0, 1, 1) self.retranslateUi(NewProject) QtCore.QMetaObject.connectSlotsByName(NewProject) def retranslateUi(self, NewProject): _translate = QtCore.QCoreApplication.translate NewProject.setWindowTitle( _translate("NewProject", "Video UAV Tracker - New Project")) self.replayPlay_pushButton.setText( _translate("NewProject", "Play/Pause")) self.replayPosition_label.setText(_translate("NewProject", "-:- / -:-")) self.pushButton_2.setToolTip( _translate( "NewProject", "<html><head/><body><p>Synchronize actual video frame with selected GPS time</p></body></html>" )) self.comboBox.setToolTip( _translate("NewProject", "<html><head/><body><p> GPS time</p></body></html>")) self.pushButton_2.setText(_translate("NewProject", "Synchronize!")) self.toolButton_3.setToolTip( _translate( "NewProject", "<html><head/><body><p>Add point shape database to project</p></body></html>" )) #self.toolButton_3.setText(_translate("NewProject", "DB")) self.toolButton_2.setToolTip( _translate("NewProject", "<html><head/><body><p>Next second</p></body></html>")) self.toolButton_2.setText(_translate("NewProject", ">>")) self.SkipFortoolButton_8.setToolTip( _translate("NewProject", "<html><head/><body><p>Next frame</p></body></html>")) self.SkipFortoolButton_8.setText(_translate("NewProject", ">")) self.SkipBacktoolButton_7.setToolTip( _translate( "NewProject", "<html><head/><body><p>Previous frame</p></body></html>")) self.SkipBacktoolButton_7.setText(_translate("NewProject", "<")) self.toolButton.setToolTip( _translate( "NewProject", "<html><head/><body><p>Previous second</p></body></html>")) self.toolButton.setText(_translate("NewProject", "<<")) self.pushButton.setToolTip( _translate( "NewProject", "<html><head/><body><p>Select video and relative gpx</p></body></html>" )) self.pushButton.setText( _translate("NewProject", "Select Video and GPX")) self.toolButton_4.setText(_translate("NewProject", "3D")) self.checkBox.setToolTip( _translate( "NewProject", "<html><head/><body><p>Activate Pixel value conversion and display (see README)</p></body></html>" ))
class VideoWindow(QMainWindow): def __init__(self, parent=None): super(VideoWindow, self).__init__(parent) self.setFixedSize(900, 600) self.setWindowTitle( "Automatic mosaic editing of videos using deep learning") self.setWindowIcon(QIcon('kwicon.jpg')) #self._mutex = QtCore.QMutex() self.mediaPlayer = QMediaPlayer(None, QMediaPlayer.VideoSurface) self.mediaPlayer_1 = QMediaPlayer(None, QMediaPlayer.VideoSurface) self.videoWidget = QVideoWidget() self.videoWidget_1 = QVideoWidget() p = self.videoWidget.palette() p_1 = self.videoWidget_1.palette() p.setColor(self.backgroundRole(), Qt.black) p_1.setColor(self.backgroundRole(), Qt.black) self.videoWidget.setPalette(p) self.videoWidget_1.setPalette(p_1) self.video_path = video_path self.tmp_result_name = 'tmp_result.mp4' self.tmp_result_path = "C:/Users/mmlab/PycharmProjects/UI_pyqt/" + self.tmp_result_name self.playButton = QPushButton() self.playButton.setEnabled(True) self.playButton.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay)) self.playButton.clicked.connect(self.play) self.playButton.setStyleSheet('background:white') self.pauseButton = QPushButton() self.pauseButton.setEnabled(True) self.pauseButton.setIcon(self.style().standardIcon( QStyle.SP_MediaPause)) self.pauseButton.clicked.connect(self.pause) self.pauseButton.setStyleSheet('background:white') self.stopButton = QPushButton() self.stopButton.setEnabled(True) self.stopButton.setIcon(self.style().standardIcon(QStyle.SP_MediaStop)) self.stopButton.clicked.connect(self.stop) self.stopButton.setStyleSheet('background:white') self.openButton = QPushButton() self.openButton.setEnabled(True) self.openButton.setText("OPEN") self.openButton.setFixedHeight(25) self.openButton.setFixedWidth(50) self.openButton.clicked.connect(lambda: self.openFile(self.grid)) self.openButton.setStyleSheet('background:white') self.saveButton = QPushButton() self.saveButton.setEnabled(True) self.saveButton.setText("SAVE") self.saveButton.setFixedHeight(25) self.saveButton.setFixedWidth(50) self.saveButton.clicked.connect(self.saveFile) self.saveButton.setStyleSheet('background:white') self.positionSlider = QSlider(Qt.Horizontal) self.positionSlider.setRange(0, 0) self.positionSlider.sliderMoved.connect(self.setPosition) # Image ScrollArea self.grid = QtWidgets.QGridLayout() # Create Grid Layout self.bg = QtWidgets.QButtonGroup(self) # Create Button Group flen = len( os.listdir( 'C:/Users/mmlab/PycharmProjects/UI_pyqt/cluster_people')) self.f = [] self.cont01 = 0 mod = sys.modules[__name__] for i in range(0, flen): self.f.append( 'C:/Users/mmlab/PycharmProjects/UI_pyqt/cluster_people/{}'. format(i) + 'human/{}'.format(i) + 'human1.png') a = 0 check = [] vBox = QtWidgets.QHBoxLayout() self._databases_checked = [] positions = [(0, j) for j in range(flen)] for position, title in zip(positions, self.f): if title == '': continue QLabel = QtWidgets.QLabel() QLabel.setFixedWidth(150) QLabel.setFixedHeight(150) image = self.f[self.cont01] num = [] num.append(self.cont01) self.qp = QPixmap() self.qp.load(image) self.qp = self.qp.scaled(150, 150) QLabel.setPixmap(self.qp) vBox.addWidget(QLabel) cb = QCheckBox(str(a)) cb.stateChanged.connect(self.on_stateChanged) vBox.addWidget(cb) self.grid.addLayout(vBox, *position) self.cont01 += 1 a += 1 setattr #RUN 버튼 self.okButton = QPushButton() self.okButton.setEnabled(True) self.okButton.clicked.connect(self.RunFile) self.okButton.setFixedWidth(50) self.okButton.setFixedHeight(25) self.okButton.setText("RUN") self.okButton.setStyleSheet('background:yellow') self.okButton.setFont(QFont("굴림", 10, QFont.Bold)) # 확인버튼 # grid2 = QtWidgets.QGridLayout() wid = QWidget(self) self.setCentralWidget(wid) # CREATION OF SCROLL AREA frame = QFrame() frame.setLayout(self.grid) scroll = QScrollArea() scroll.setWidget(frame) scroll.setWidgetResizable(False) scroll.setFixedHeight(210) self.scrollbar = scroll.verticalScrollBar() # Create a QVBoxLayout layout_scroll = QVBoxLayout(self) # Add the Widget QScrollArea to the QVBoxLayout layout_scroll.addWidget(scroll) # Create new action openAction = QAction(QIcon('open.png'), '&Open', self) openAction.setShortcut('Ctrl+O') openAction.setStatusTip('Open video') openAction.triggered.connect(self.openFile) # Create save action saveAction = QAction(QIcon('save.png'), '&Save', self) saveAction.setShortcut('Ctrl+S') saveAction.setStatusTip('Save video') saveAction.triggered.connect(self.saveFile) # Create exit action exitAction = QAction(QIcon('exit.png'), '&Exit', self) exitAction.setShortcut('Ctrl+Q') exitAction.setStatusTip('Exit application') exitAction.triggered.connect(self.exitCall) # Create menu bar and add action menuBar = self.menuBar() fileMenu = menuBar.addMenu('&File') fileMenu.addAction(openAction) fileMenu.addAction(saveAction) fileMenu.addAction(exitAction) editMenu = menuBar.addMenu('&Edit') viewMenu = menuBar.addMenu('&View') toolMenu = menuBar.addMenu('&Tools') helpMenu = menuBar.addMenu('&Help') # Create a widget for window contents wid = QWidget(self) self.setCentralWidget(wid) # Create layouts to place inside widget controlLayout = QHBoxLayout() controlLayout.setContentsMargins(0, 0, 0, 0) controlLayout.addWidget(self.playButton) controlLayout.addWidget(self.pauseButton) controlLayout.addWidget(self.stopButton) controlLayout.addWidget(self.positionSlider) controlLayout.addWidget(self.openButton) controlLayout.addWidget(self.okButton) controlLayout.addWidget(self.saveButton) self.videoLayout = QHBoxLayout() self.videoLayout.setContentsMargins(0, 0, 0, 0) self.videoLayout.addWidget(self.videoWidget) self.videoLayout.addWidget(self.videoWidget_1) #bLayout = QHBoxLayout() #bLayout.setContentsMargins(0, 0, 0, 0) #bLayout.addWidget(self.okButton) layout = QVBoxLayout() layout.addLayout(self.videoLayout) layout.addLayout(controlLayout) layout.addLayout(layout_scroll) #layout.addLayout(bLayout) #layout.addWidget(self.errorLabel) # Set widget to contain window contents wid.setLayout(layout) self.mediaPlayer.setVideoOutput(self.videoWidget) self.mediaPlayer.positionChanged.connect(self.positionChanged) self.mediaPlayer.durationChanged.connect(self.durationChanged) # self.mediaPlayer.error.connect(self.handleError) self.mediaPlayer_1.setVideoOutput(self.videoWidget_1) self.mediaPlayer_1.positionChanged.connect(self.positionChanged) self.mediaPlayer_1.durationChanged.connect(self.durationChanged) # self.mediaPlayer_1.error.connect(self.handleError) fileName2 = "C:/Users/mmlab/PycharmProjects/UI_pyqt/tmp_result1.mp4" self.mediaPlayer.setMedia(QMediaContent( QUrl.fromLocalFile(video_path))) self.mediaPlayer_1.setMedia( QMediaContent(QUrl.fromLocalFile(fileName2))) def on_stateChanged(self, state): checkbox = self.sender() text = checkbox.text() + 'human' if state == Qt.Checked: self._databases_checked.append(text) else: self._databases_checked.remove(text) print(self._databases_checked) def model_image(self, grid): flen = len( os.listdir( 'C:/Users/mmlab/PycharmProjects/UI_pyqt/cluster_people')) self.f = [] self.cont01 = 0 for i in range(0, flen): self.f.append( 'C:/Users/mmlab/PycharmProjects/UI_pyqt/cluster_people/{}'. format(i) + 'human/{}'.format(i) + 'human1.png') a = 0 self.check = [] positions = [(0, j) for j in range(flen)] for position, title in zip(positions, self.f): if title == '': continue vBox = QtWidgets.QVBoxLayout() QLabel = QtWidgets.QLabel() QLabel.setFixedWidth(150) QLabel.setFixedHeight(150) image = self.f[self.cont01] num = [] num.append(self.cont01) self.qp = QPixmap() self.qp.load(image) self.qp = self.qp.scaled(150, 150) QLabel.setPixmap(self.qp) vBox.addWidget(QLabel) self.check.append(QCheckBox()) vBox.addWidget(self.check[a]) self.check[a].setText(str(a)) self.check[a].clicked.connect(self.c(self.check[a])) grid.addLayout(vBox, *position) self.cont01 += 1 a += 1 # if self.check.isChecked(): # print(self.check.text()) # print(self.check.text()) self.mediaPlayer = QMediaPlayer(None, QMediaPlayer.VideoSurface) self.mediaPlayer_1 = QMediaPlayer(None, QMediaPlayer.VideoSurface) p = self.videoWidget.palette() p_1 = self.videoWidget_1.palette() p.setColor(self.backgroundRole(), Qt.black) p_1.setColor(self.backgroundRole(), Qt.black) self.videoWidget.setPalette(p) self.videoWidget_1.setPalette(p_1) self.video_path = '' self.tmp_result_name = 'tmp_result.mp4' self.tmp_result_path = "C:/Users/mmlab/PycharmProjects/UI_pyqt/" + self.tmp_result_name self.playButton = QPushButton() self.playButton.setEnabled(True) self.playButton.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay)) self.playButton.clicked.connect(self.play) self.playButton.setStyleSheet('background:white') self.pauseButton = QPushButton() self.pauseButton.setEnabled(True) self.pauseButton.setIcon(self.style().standardIcon( QStyle.SP_MediaPause)) self.pauseButton.clicked.connect(self.pause) self.pauseButton.setStyleSheet('background:white') self.stopButton = QPushButton() self.stopButton.setEnabled(True) self.stopButton.setIcon(self.style().standardIcon(QStyle.SP_MediaStop)) self.stopButton.clicked.connect(self.stop) self.stopButton.setStyleSheet('background:white') self.openButton = QPushButton() self.openButton.setEnabled(True) self.openButton.setText("OPEN") self.openButton.setFixedHeight(25) self.openButton.setFixedWidth(50) self.openButton.clicked.connect(lambda: self.openFile(grid)) self.openButton.setStyleSheet('background:white') self.saveButton = QPushButton() self.saveButton.setEnabled(True) self.saveButton.setText("SAVE") self.saveButton.setFixedHeight(25) self.saveButton.setFixedWidth(50) self.saveButton.clicked.connect(self.saveFile) self.saveButton.setStyleSheet('background:white') self.positionSlider = QSlider(Qt.Horizontal) self.positionSlider.setRange(0, 0) self.positionSlider.sliderMoved.connect(self.setPosition) self.bg = QtWidgets.QButtonGroup(self) # Create Button Group self.okButton = QPushButton() self.okButton.setEnabled(True) self.okButton.clicked.connect(self.RunFile) self.okButton.setFixedWidth(50) self.okButton.setFixedHeight(25) self.okButton.setText("RUN") self.okButton.setStyleSheet('background:yellow') self.okButton.setFont(QFont("굴림", 10, QFont.Bold)) wid = QWidget(self) self.setCentralWidget(wid) frame = QFrame() frame.setLayout(grid) scroll = QScrollArea() scroll.setWidget(frame) scroll.setWidgetResizable(False) scroll.setFixedHeight(210) self.scrollbar = scroll.verticalScrollBar() layout_scroll = QVBoxLayout(self) layout_scroll.addWidget(scroll) controlLayout = QHBoxLayout() controlLayout.setContentsMargins(0, 0, 0, 0) controlLayout.addWidget(self.playButton) controlLayout.addWidget(self.pauseButton) controlLayout.addWidget(self.stopButton) controlLayout.addWidget(self.positionSlider) controlLayout.addWidget(self.openButton) controlLayout.addWidget(self.okButton) controlLayout.addWidget(self.saveButton) self.videoLayout = QHBoxLayout() self.videoLayout.setContentsMargins(0, 0, 0, 0) self.videoLayout.addWidget(self.videoWidget) self.videoLayout.addWidget(self.videoWidget_1) layout = QVBoxLayout() layout.addLayout(self.videoLayout) layout.addLayout(controlLayout) layout.addLayout(layout_scroll) # Set widget to contain window contents wid.setLayout(layout) self.mediaPlayer.setVideoOutput(self.videoWidget) self.mediaPlayer.positionChanged.connect(self.positionChanged) self.mediaPlayer.durationChanged.connect(self.durationChanged) self.mediaPlayer_1.setVideoOutput(self.videoWidget_1) self.mediaPlayer_1.positionChanged.connect(self.positionChanged) self.mediaPlayer_1.durationChanged.connect(self.durationChanged) def openFile(self, grid): if os.path.exists( 'C:/Users/mmlab/PycharmProjects/UI_pyqt/src/test_file'): for file in os.scandir( 'C:/Users/mmlab/PycharmProjects/UI_pyqt/src/test_file'): os.remove(file.path) if os.path.exists( 'C:/Users/mmlab/PycharmProjects/UI_pyqt/src/out_dir'): for file in os.scandir( 'C:/Users/mmlab/PycharmProjects/UI_pyqt/src/out_dir'): os.remove(file.path) window2 = MyWindow() window2.OnOpenDocument() video_p(window2.video_path) tmp_result_name = 'tmp_result.mp4' tmp_result_path = "C:/Users/mmlab/PycharmProjects/UI_pyqt/" + tmp_result_name if video_path != "": print(video_path) # make.main(video_path) # clu.main() # classifier.main() # mosaic2.main(video_path, tmp_result_name) player.close() player2 = VideoWindow() player2.show() def RunFile(self): checkdemo() def saveFile(self, grid): fileName1 = QFileDialog.getSaveFileName(self, "Save Video", "*.mp4", QDir.homePath()) def exitCall(self): sys.exit(app.exec_()) def play(self): if self.mediaPlayer.state() == QMediaPlayer.PlayingState: self.mediaPlayer.pause() self.mediaPlayer_1.pause() else: self.mediaPlayer.play() self.mediaPlayer_1.play() def pause(self): if self.mediaPlayer.state() == QMediaPlayer.PausedState: self.mediaPlayer.play() self.mediaPlayer_1.play() else: self.mediaPlayer.pause() self.mediaPlayer_1.pause() def stop(self): if self.mediaPlayer.state() == QMediaPlayer.StoppedState: self.mediaPlayer.play() self.mediaPlayer_1.play() else: self.mediaPlayer.stop() self.mediaPlayer_1.stop() def positionChanged(self, position): self.positionSlider.setValue(position) def durationChanged(self, duration): self.positionSlider.setRange(0, duration) def setPosition(self, position): self.mediaPlayer.setPosition(position) self.mediaPlayer_1.setPosition(position) def handleError(self): self.playButton.setEnabled(False) self.errorLabel.setText("Error: " + self.mediaPlayer.errorString())
def initUI(self): menu = self.menuBar() # create menu bar file_menu = menu.addMenu('File') # create file button options_menu = menu.addMenu('Options') # create options button wid = QWidget() self.setCentralWidget(wid) # create 'Open FIle' actions, add to 'File' button open_file = QAction('Open File', self) open_file.triggered.connect(self.openFile) open_file.setShortcut("Ctrl+O") file_menu.addAction(open_file) # create 'Close File' action, add to 'File' button close_file = QAction('Close File', self) close_file.triggered.connect(self.exit) close_file.setShortcut("Ctrl+W") file_menu.addAction(close_file) # create 'Exit' action, add to 'File' button exit_file = QAction('Close File', self) exit_file.triggered.connect(self.exit) exit_file.setShortcut("Ctrl+W") file_menu.addAction(exit_file) # create 'Color' action, add to 'Options' button color_option = QAction('Color', self) color_option.triggered.connect(self.show_color_dialog) color_option.setShortcut("Ctrl+2") options_menu.addAction(color_option) # create 'Shape' action, add to 'Options' button shape_option = QAction('Shape', self) # shape_option.triggered.connect() shape_option.setShortcut("Ctrl+3") options_menu.addAction(shape_option) # create 'Foliage' action, add to 'Options' button foliage_option = QAction('Foliage', self) # foliage_option.triggered.connect() foliage_option.setShortcut("Ctrl+3") options_menu.addAction(foliage_option) # Creating button for pause/play self.player = QMediaPlayer() self.playlist = QMediaPlaylist() videoWidget = QVideoWidget() self.pal = QPalette() self.pal.setColor(QPalette.Foreground, Qt.green) videoWidget.setPalette(self.pal) self.playButton = QPushButton() self.playButton.setEnabled(False) self.playButton.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay)) self.playButton.clicked.connect(self.play) self.positionSlider = QSlider(Qt.Horizontal) self.positionSlider.setRange(0, 0) self.positionSlider.sliderMoved.connect(self.setPosition) self.errorLabel = QLabel() self.errorLabel.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Maximum) self.songLabel = QLabel() self.songLabel.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Maximum) controlLayout = QHBoxLayout() controlLayout.setContentsMargins(0, 0, 0, 0) self.playButton.setShortcut("Space") controlLayout.addWidget(self.playButton) controlLayout.addWidget(self.positionSlider) layout = QVBoxLayout() layout.addWidget(videoWidget) layout.addLayout(controlLayout) layout.addWidget(self.songLabel) layout.addWidget(self.errorLabel) # Set widget to contain window contents wid.setLayout(layout) # self.mediaPlayer.setVideoOutput(videoWidget) self.player.stateChanged.connect(self.mediaStateChanged) self.player.positionChanged.connect(self.positionChanged) self.player.durationChanged.connect(self.durationChanged) self.player.error.connect(self.handleError)
class Ui_Form(object): def setupUi(self, Form): Form.setObjectName("Form") Form.resize(706, 493) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/plugins/Video_UAV_Tracker/icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) Form.setWindowIcon(icon) self.verticalLayout_3 = QtWidgets.QVBoxLayout(Form) self.verticalLayout_3.setObjectName("verticalLayout_3") self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.pushButton_3 = QtWidgets.QPushButton(Form) font = QtGui.QFont() font.setKerning(True) self.pushButton_3.setFont(font) icon1 = QtGui.QIcon() icon1.addPixmap(QtGui.QPixmap(":/VgisIcon/Hand-icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.On) self.pushButton_3.setIcon(icon1) self.pushButton_3.setAutoExclusive(False) self.pushButton_3.setAutoDefault(False) self.pushButton_3.setDefault(False) self.pushButton_3.setFlat(False) self.pushButton_3.setObjectName("pushButton_3") self.horizontalLayout.addWidget(self.pushButton_3) self.toolButton_6 = QtWidgets.QToolButton(Form) icon2 = QtGui.QIcon() icon2.addPixmap(QtGui.QPixmap(":/plugins/Video_UAV_Tracker/iconNewTabEditorConsole.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.toolButton_6.setIcon(icon2) self.toolButton_6.setObjectName("toolButton_6") self.horizontalLayout.addWidget(self.toolButton_6) spacerItem = QtWidgets.QSpacerItem(23, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem) self.toolButton_4 = QtWidgets.QToolButton(Form) self.toolButton_4.setStyleSheet("background: url(/mnt/574916AB2EEEC400/LAVORO/Sviluppo_VUT_StandAlone/Progetto_VUT/115757-magic-marker-icon-people-things-hand22-sc48.png)") self.toolButton_4.setObjectName("toolButton_4") self.horizontalLayout.addWidget(self.toolButton_4) self.toolButton_5 = QtWidgets.QToolButton(Form) self.toolButton_5.setObjectName("toolButton_5") self.horizontalLayout.addWidget(self.toolButton_5) self.verticalLayout_3.addLayout(self.horizontalLayout) self.dockWidget_2 = QtWidgets.QDockWidget(Form) self.dockWidget_2.setFeatures(QtWidgets.QDockWidget.NoDockWidgetFeatures) self.dockWidget_2.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea|QtCore.Qt.RightDockWidgetArea) self.dockWidget_2.setObjectName("dockWidget_2") self.dockWidgetContents_7 = QtWidgets.QWidget() self.dockWidgetContents_7.setObjectName("dockWidgetContents_7") self.gridLayout_2 = QtWidgets.QGridLayout(self.dockWidgetContents_7) self.gridLayout_2.setObjectName("gridLayout_2") self.verticalLayout = QtWidgets.QVBoxLayout() self.verticalLayout.setObjectName("verticalLayout") self.video_frame = QVideoWidget(Form) p = self.video_frame.palette() p.setColor(QtGui.QPalette.Window, QtCore.Qt.black) self.video_frame.setPalette(p) self.video_frame.setAttribute(QtCore.Qt.WA_OpaquePaintEvent) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.video_frame.sizePolicy().hasHeightForWidth()) self.video_frame.setSizePolicy(sizePolicy) self.video_frame.setMinimumSize(QtCore.QSize(200, 200)) self.video_frame.setStyleSheet("background-color: rgb(0, 0, 0);") self.video_frame.setObjectName("video_frame") self.verticalLayout.addWidget(self.video_frame) self.horizontalSlider = QtWidgets.QSlider(self.dockWidgetContents_7) self.horizontalSlider.setOrientation(QtCore.Qt.Horizontal) self.horizontalSlider.setObjectName("horizontalSlider") self.verticalLayout.addWidget(self.horizontalSlider) self.horizontalLayout_3 = QtWidgets.QHBoxLayout() self.horizontalLayout_3.setObjectName("horizontalLayout_3") spacerItem1 = QtWidgets.QSpacerItem(98, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.horizontalLayout_3.addItem(spacerItem1) self.toolButton_11 = QtWidgets.QToolButton(self.dockWidgetContents_7) icon3 = QtGui.QIcon() icon3.addPixmap(QtGui.QPixmap(":/VgisIcon/mActionArrowLeft.svg"), QtGui.QIcon.Normal, QtGui.QIcon.On) self.toolButton_11.setIcon(icon3) self.toolButton_11.setObjectName("toolButton_11") self.horizontalLayout_3.addWidget(self.toolButton_11) self.SkipBacktoolButton_8 = QtWidgets.QToolButton(self.dockWidgetContents_7) self.SkipBacktoolButton_8.setStyleSheet("") icon4 = QtGui.QIcon() icon4.addPixmap(QtGui.QPixmap(":/VgisIcon/mActionAtlasPrev.svg"), QtGui.QIcon.Normal, QtGui.QIcon.On) self.SkipBacktoolButton_8.setIcon(icon4) self.SkipBacktoolButton_8.setObjectName("SkipBacktoolButton_8") self.horizontalLayout_3.addWidget(self.SkipBacktoolButton_8) self.playButton = QtWidgets.QToolButton(self.dockWidgetContents_7) self.playButton.setObjectName("playButton") self.horizontalLayout_3.addWidget(self.playButton) self.muteButton = QtWidgets.QToolButton(self.dockWidgetContents_7) self.muteButton.setText("") self.muteButton.setObjectName("muteButton") self.horizontalLayout_3.addWidget(self.muteButton) self.replayPosition_label = QtWidgets.QLabel(self.dockWidgetContents_7) self.replayPosition_label.setObjectName("replayPosition_label") self.horizontalLayout_3.addWidget(self.replayPosition_label) self.SkipFortoolButton_9 = QtWidgets.QToolButton(self.dockWidgetContents_7) self.SkipFortoolButton_9.setStyleSheet("") icon5 = QtGui.QIcon() icon5.addPixmap(QtGui.QPixmap(":/VgisIcon/mActionAtlasNext.svg"), QtGui.QIcon.Normal, QtGui.QIcon.On) self.SkipFortoolButton_9.setIcon(icon5) self.SkipFortoolButton_9.setObjectName("SkipFortoolButton_9") self.horizontalLayout_3.addWidget(self.SkipFortoolButton_9) self.toolButton_12 = QtWidgets.QToolButton(self.dockWidgetContents_7) icon6 = QtGui.QIcon() icon6.addPixmap(QtGui.QPixmap(":/VgisIcon/mActionArrowRight.svg"), QtGui.QIcon.Normal, QtGui.QIcon.On) self.toolButton_12.setIcon(icon6) self.toolButton_12.setObjectName("toolButton_12") self.horizontalLayout_3.addWidget(self.toolButton_12) spacerItem2 = QtWidgets.QSpacerItem(98, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.horizontalLayout_3.addItem(spacerItem2) self.verticalLayout.addLayout(self.horizontalLayout_3) self.gridLayout_2.addLayout(self.verticalLayout, 0, 0, 1, 1) self.dockWidget_2.setWidget(self.dockWidgetContents_7) self.verticalLayout_3.addWidget(self.dockWidget_2) self.dockWidget_4 = QtWidgets.QDockWidget(Form) self.dockWidget_4.setMaximumSize(QtCore.QSize(524287, 121)) self.dockWidget_4.setFeatures(QtWidgets.QDockWidget.NoDockWidgetFeatures) self.dockWidget_4.setAllowedAreas(QtCore.Qt.BottomDockWidgetArea) self.dockWidget_4.setObjectName("dockWidget_4") self.dockWidgetContents_6 = QtWidgets.QWidget() self.dockWidgetContents_6.setObjectName("dockWidgetContents_6") self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.dockWidgetContents_6) self.verticalLayout_2.setObjectName("verticalLayout_2") self.label = QtWidgets.QLabel(self.dockWidgetContents_6) self.label.setObjectName("label") self.verticalLayout_2.addWidget(self.label) self.horizontalLayout_2 = QtWidgets.QHBoxLayout() self.horizontalLayout_2.setSizeConstraint(QtWidgets.QLayout.SetFixedSize) self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.pushButtonCutA_6 = QtWidgets.QPushButton(self.dockWidgetContents_6) self.pushButtonCutA_6.setEnabled(True) self.pushButtonCutA_6.setObjectName("pushButtonCutA_6") self.horizontalLayout_2.addWidget(self.pushButtonCutA_6) self.pushButtonCutB_6 = QtWidgets.QPushButton(self.dockWidgetContents_6) self.pushButtonCutB_6.setObjectName("pushButtonCutB_6") self.horizontalLayout_2.addWidget(self.pushButtonCutB_6) self.label_7 = QtWidgets.QLabel(self.dockWidgetContents_6) self.label_7.setObjectName("label_7") self.horizontalLayout_2.addWidget(self.label_7) self.doubleSpinBox_2 = QtWidgets.QDoubleSpinBox(self.dockWidgetContents_6) self.doubleSpinBox_2.setObjectName("doubleSpinBox_2") self.horizontalLayout_2.addWidget(self.doubleSpinBox_2) self.comboBox_6 = QtWidgets.QComboBox(self.dockWidgetContents_6) self.comboBox_6.setObjectName("comboBox_6") self.comboBox_6.addItem("") self.comboBox_6.addItem("") self.horizontalLayout_2.addWidget(self.comboBox_6) self.pushButton_5 = QtWidgets.QPushButton(self.dockWidgetContents_6) self.pushButton_5.setObjectName("pushButton_5") self.horizontalLayout_2.addWidget(self.pushButton_5) self.pushButtonCut_2 = QtWidgets.QPushButton(self.dockWidgetContents_6) self.pushButtonCut_2.setObjectName("pushButtonCut_2") self.horizontalLayout_2.addWidget(self.pushButtonCut_2) self.verticalLayout_2.addLayout(self.horizontalLayout_2) self.progressBar = QtWidgets.QProgressBar(self.dockWidgetContents_6) self.progressBar.setProperty("value", 24) self.progressBar.setObjectName("progressBar") self.verticalLayout_2.addWidget(self.progressBar) self.dockWidget_4.setWidget(self.dockWidgetContents_6) self.verticalLayout_3.addWidget(self.dockWidget_4) self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form) def retranslateUi(self, Form): _translate = QtCore.QCoreApplication.translate Form.setWindowTitle(_translate("Form", "Video UAV Tracker - Player")) self.pushButton_3.setToolTip(_translate("Form", "<html><head/><body><p>Move along Video directly clicking on gps track</p></body></html>")) self.pushButton_3.setText(_translate("Form", "MapTool ")) self.toolButton_6.setToolTip(_translate("Form", "<html><head/><body><p>Add point</p></body></html>")) self.toolButton_6.setText(_translate("Form", "o")) self.toolButton_4.setToolTip(_translate("Form", "<html><head/><body><p>Enable extract frames toolbox</p><p><br/></p></body></html>")) self.toolButton_4.setText(_translate("Form", "Extract frames")) self.toolButton_5.setText(_translate("Form", "Close")) self.toolButton_11.setText(_translate("Form", "<<")) self.SkipBacktoolButton_8.setText(_translate("Form", "<")) self.playButton.setText(_translate("Form", "> / ||")) self.replayPosition_label.setText(_translate("Form", "-:- / -:-")) self.SkipFortoolButton_9.setText(_translate("Form", ">")) self.toolButton_12.setText(_translate("Form", ">>")) self.label.setText(_translate("Form", "Export Frames Tool")) self.pushButtonCutA_6.setToolTip(_translate("Form", "<html><head/><body><p>Export from actual Video Frame</p></body></html>")) self.pushButtonCutA_6.setText(_translate("Form", "From A")) self.pushButtonCutB_6.setToolTip(_translate("Form", "<html><head/><body><p>Export to actual Video Frame</p></body></html>")) self.pushButtonCutB_6.setText(_translate("Form", "To B")) self.label_7.setText(_translate("Form", "Pick one frame every")) self.comboBox_6.setItemText(0, _translate("Form", "meters")) self.comboBox_6.setItemText(1, _translate("Form", "seconds")) self.pushButton_5.setText(_translate("Form", "Cancel")) self.pushButtonCut_2.setText(_translate("Form", "Extract!"))
class Window(QWidget): def __init__(self): super().__init__() self.setWindowTitle("PyQt5 Media Player") self.setGeometry(0, 0, 700, 600) self.setWindowIcon(QIcon('player.png')) p = self.palette() p.setColor(QPalette.Window, Qt.black) self.setPalette(p) self.init_ui() self.show() self.audio_process = False self.position = 0 self.filename = '.' def init_ui(self): #create media player object self.mediaPlayer = QMediaPlayer(None, QMediaPlayer.VideoSurface) #create videowidget object videoHboxLayout = QHBoxLayout() self.videowidget = QVideoWidget() self.videowidget.setFixedHeight(300) self.videowidget.setFixedWidth(352) self.imagewidget = QLabel() self.imagewidget.setFixedWidth(352) self.imagewidget.setFixedHeight(300) videoHboxLayout.addWidget(self.videowidget) videoHboxLayout.addWidget(self.imagewidget) videoHboxLayout.setContentsMargins(0, 0, 0, 0) videoHboxLayout.setSpacing(0) #create open button openBtn = QPushButton('Open Video') openBtn.clicked.connect(self.open_file) #create button for playing self.playBtn = QPushButton() self.playBtn.setEnabled(False) self.playBtn.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay)) self.playBtn.clicked.connect(self.play_video) self.stopBtn = QPushButton() self.stopBtn.setEnabled(False) self.stopBtn.setIcon(self.style().standardIcon(QStyle.SP_MediaStop)) self.stopBtn.clicked.connect(self.reset_video) #create label self.label = QLabel() self.label.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Maximum) #create hbox layout hboxLayout = QHBoxLayout() hboxLayout.setContentsMargins(0, 0, 0, 0) #set widgets to the hbox layout hboxLayout.addWidget(openBtn) hboxLayout.addWidget(self.playBtn) hboxLayout.addWidget(self.stopBtn) synopLayout = QVBoxLayout() synopLayout.setContentsMargins(0, 0, 0, 0) synopLayout.setSpacing(0) self.generate_synopsis_video(synopLayout) self.generate_synopsis_image(synopLayout) # image1 = ClickLabel() # pixmap = QPixmap('../test.jpg') # image1.setPixmap(pixmap) # image1.setFixedSize(100, 50) # # image1.clicked.connect(self.synopsis_click_handler) # synopImageLayout.addWidget(image1) #create vbox layout vboxLayout = QVBoxLayout() vboxLayout.addLayout(videoHboxLayout) vboxLayout.addLayout(hboxLayout) vboxLayout.addWidget(self.label) vboxLayout.addLayout(synopLayout) self.setLayout(vboxLayout) self.mediaPlayer.setVideoOutput(self.videowidget) pal = self.palette() pal.setBrush(QPalette.Window, QBrush(QPixmap("../keyimages/1.png"))) self.videowidget.setPalette(pal) #media player signals self.mediaPlayer.stateChanged.connect(self.mediastate_changed) self.mediaPlayer.positionChanged.connect(self.position_changed) self.imagewidget.hide() def generate_synopsis_video(self, synopLayout): frame_folder = os.path.join(parent_dir, 'keyframes') image_dir = os.listdir(frame_folder) image_dir.remove('.gitignore') image_dir.remove('.DS_Store') image_dir.sort(key=lambda img: (int(img.split('_')[0][-1]) * 10000 + int(img.split('_')[1].split('.')[0]))) images = [image for image in image_dir] count = 0 synopImageLayout = QHBoxLayout() synopImageLayout.setContentsMargins(0, 0, 0, 0) synopImageLayout.setSpacing(0) for imageName in images: # frame_time = int(imageName.split('_')[1].split('.')[0]) video_no = int(imageName.split('_')[0][-1]) timestamp = (int(imageName.split('_')[1].split('.')[0])) image_label = ClickLabel() pixmap = QPixmap(os.path.join(parent_dir, 'keyframes', imageName))\ .scaled(44, 36, Qt.KeepAspectRatio, Qt.FastTransformation) image_label.setPixmap(pixmap) image_label.clicked.connect(lambda t=timestamp, n=video_no: self. synopsis_click_handler(t, n)) synopImageLayout.addWidget(image_label) count += 1 if count == 17: synopLayout.addLayout(synopImageLayout) synopImageLayout = QHBoxLayout() synopImageLayout.setContentsMargins(0, 0, 0, 0) synopImageLayout.setSpacing(0) count = 0 def generate_synopsis_image(self, synopLayout): image_folder = os.path.join(parent_dir, 'keyimages') image_dir = os.listdir(image_folder) image_dir.remove('.DS_Store') image_dir.sort(key=lambda img: int(img.split('.')[0])) images = [image for image in image_dir] count = 0 rowcount = 0 synopImageLayout = QHBoxLayout() synopImageLayout.setContentsMargins(0, 0, 0, 0) synopImageLayout.setSpacing(0) for imageName in images: image_no = int(imageName.split('.')[0]) image_label = ClickLabel() pixmap = QPixmap(os.path.join(image_folder, imageName)) \ .scaled(44, 36, Qt.KeepAspectRatio, Qt.FastTransformation) image_label.setPixmap(pixmap) image_label.clicked.connect( lambda filename=os.path.join(image_folder, imageName): self. image_synopsis_click_handler(filename)) synopImageLayout.addWidget(image_label) count += 1 if count == 17: synopLayout.addLayout(synopImageLayout) rowcount += 1 if rowcount > 3: return synopImageLayout = QHBoxLayout() synopImageLayout.setContentsMargins(0, 0, 0, 0) synopImageLayout.setSpacing(0) count = 0 def open_video_file(self, filename): path = os.path.join(parent_dir, 'videos') mp4_path = os.path.join(path, 'mp4') avi_path = os.path.join(path, 'avi') mp4_name = filename + '.mp4' avi_name = filename + '.avi' mp4_dir = os.listdir(mp4_path) for mp4 in mp4_dir: if mp4_name == mp4: self.mediaPlayer.setMedia( QMediaContent( QUrl.fromLocalFile(os.path.join(mp4_path, mp4_name)))) self.stopBtn.setEnabled(True) self.playBtn.setEnabled(True) self.filename = mp4_name return convert_avi_to_mp4(os.path.join(avi_path, avi_name), os.path.join(mp4_path, mp4_name)) self.mediaPlayer.setMedia( QMediaContent(QUrl.fromLocalFile(os.path.join(mp4_path, mp4_name)))) self.playBtn.setEnabled(True) self.stopBtn.setEnabled(True) self.filename = mp4_name def open_file(self): filename, _ = QFileDialog.getOpenFileName(self, "Open Video") if os.path.splitext(filename)[1] == '.avi': output_name = os.path.dirname(filename) + '/output.mp4' convert_avi_to_mp4(filename, output_name) self.mediaPlayer.setMedia( QMediaContent(QUrl.fromLocalFile(output_name))) self.playBtn.setEnabled(True) elif filename != '': self.mediaPlayer.setMedia( QMediaContent(QUrl.fromLocalFile(filename))) self.playBtn.setEnabled(True) def play_video(self): if self.mediaPlayer.state() == QMediaPlayer.PlayingState: self.mediaPlayer.pause() if self.audio_process: self.audio_process.kill() self.audio_process = False else: self.mediaPlayer.play() self.create_audio_process( '../videos/{filename}/audio.wav'.format( filename=self.filename.split('.')[0]), self.position / 1000) def reset_video(self): self.mediaPlayer.pause() self.mediaPlayer.setPosition(0) if self.audio_process: self.audio_process.kill() self.audio_process = False def mediastate_changed(self, state): if self.mediaPlayer.state() == QMediaPlayer.PlayingState: self.playBtn.setIcon(self.style().standardIcon( QStyle.SP_MediaPause)) else: self.playBtn.setIcon(self.style().standardIcon( QStyle.SP_MediaPlay)) def create_audio_process(self, filename, start_time): if self.audio_process: self.audio_process.kill() cmd = "python3 audio.py {filename} {start}".format(filename=filename, start=start_time) self.audio_process = subprocess.Popen(cmd, shell=True) def position_changed(self, position): self.position = position def duration_changed(self, duration): self.slider.setRange(0, duration) def set_position(self, position): self.play_video() self.mediaPlayer.setPosition(position) def handle_errors(self): self.playBtn.setEnabled(False) self.label.setText("Error: " + self.mediaPlayer.errorString()) def stop_video(self): if self.mediaPlayer.state() == QMediaPlayer.PlayingState: self.play_video() def image_synopsis_click_handler(self, filename): self.imagewidget.show() self.videowidget.hide() self.stop_video() self.playBtn.setEnabled(False) self.stopBtn.setEnabled(False) pixmap = QPixmap(filename) self.imagewidget.setPixmap(pixmap) def synopsis_click_handler(self, frame, video_no): self.imagewidget.hide() self.videowidget.show() self.playBtn.setEnabled(True) self.stopBtn.setEnabled(True) new_filename = 'video' + str(video_no) if self.filename.split('.')[0] != new_filename: self.open_video_file(new_filename) time = frame / 30 * 1000 self.mediaPlayer.setPosition(time) self.position = time self.stop_video()
class Ui_Form(object): def setupUi(self, Form): Form.setObjectName("Form") Form.resize(706, 493) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/plugins/VideoGis/icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) Form.setWindowIcon(icon) self.verticalLayout_3 = QtWidgets.QVBoxLayout(Form) self.verticalLayout_3.setObjectName("verticalLayout_3") self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.pushButton_3 = QtWidgets.QPushButton(Form) font = QtGui.QFont() font.setKerning(True) self.pushButton_3.setFont(font) icon1 = QtGui.QIcon() icon1.addPixmap(QtGui.QPixmap(":/VgisIcon/Hand-icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.On) self.pushButton_3.setIcon(icon1) self.pushButton_3.setAutoExclusive(False) self.pushButton_3.setAutoDefault(False) self.pushButton_3.setDefault(False) self.pushButton_3.setFlat(False) self.pushButton_3.setObjectName("pushButton_3") self.horizontalLayout.addWidget(self.pushButton_3) self.toolButton_6 = QtWidgets.QToolButton(Form) icon2 = QtGui.QIcon() icon2.addPixmap( QtGui.QPixmap(":/plugins/VideoGis/iconNewTabEditorConsole.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.toolButton_6.setIcon(icon2) self.toolButton_6.setObjectName("toolButton_6") self.horizontalLayout.addWidget(self.toolButton_6) self.toolButton_7 = QtWidgets.QToolButton(Form) self.toolButton_7.setEnabled(False) self.toolButton_7.setCheckable(True) self.toolButton_7.setObjectName("toolButton_7") self.horizontalLayout.addWidget(self.toolButton_7) self.pushButton = QtWidgets.QPushButton(Form) self.pushButton.setEnabled(False) self.pushButton.setCheckable(True) self.pushButton.setObjectName("pushButton") self.horizontalLayout.addWidget(self.pushButton) self.label_2 = QtWidgets.QLabel(Form) self.label_2.setEnabled(False) self.label_2.setObjectName("label_2") self.horizontalLayout.addWidget(self.label_2) self.spinBox = QtWidgets.QSpinBox(Form) self.spinBox.setEnabled(False) self.spinBox.setMinimum(1) self.spinBox.setSingleStep(10) self.spinBox.setProperty("value", 25) self.spinBox.setObjectName("spinBox") self.horizontalLayout.addWidget(self.spinBox) spacerItem = QtWidgets.QSpacerItem(23, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem) self.toolButton_4 = QtWidgets.QToolButton(Form) self.toolButton_4.setObjectName("toolButton_4") self.horizontalLayout.addWidget(self.toolButton_4) self.toolButton_5 = QtWidgets.QToolButton(Form) self.toolButton_5.setObjectName("toolButton_5") self.horizontalLayout.addWidget(self.toolButton_5) self.verticalLayout_3.addLayout(self.horizontalLayout) self.dockWidget_2 = QtWidgets.QDockWidget(Form) self.dockWidget_2.setFeatures( QtWidgets.QDockWidget.NoDockWidgetFeatures) self.dockWidget_2.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea) self.dockWidget_2.setObjectName("dockWidget_2") self.dockWidgetContents_7 = QtWidgets.QWidget() self.dockWidgetContents_7.setObjectName("dockWidgetContents_7") self.gridLayout_2 = QtWidgets.QGridLayout(self.dockWidgetContents_7) self.gridLayout_2.setObjectName("gridLayout_2") self.verticalLayout = QtWidgets.QVBoxLayout() self.verticalLayout.setObjectName("verticalLayout") self.video_frame = QVideoWidget(Form) p = self.video_frame.palette() p.setColor(QtGui.QPalette.Window, QtCore.Qt.black) self.video_frame.setPalette(p) self.video_frame.setAttribute(QtCore.Qt.WA_OpaquePaintEvent) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.video_frame.sizePolicy().hasHeightForWidth()) self.video_frame.setSizePolicy(sizePolicy) self.video_frame.setMinimumSize(QtCore.QSize(200, 200)) self.video_frame.setStyleSheet("background-color: rgb(0, 0, 0);") self.video_frame.setObjectName("video_frame") self.verticalLayout.addWidget(self.video_frame) self.horizontalSlider = QtWidgets.QSlider(self.dockWidgetContents_7) self.horizontalSlider.setOrientation(QtCore.Qt.Horizontal) self.horizontalSlider.setObjectName("horizontalSlider") self.verticalLayout.addWidget(self.horizontalSlider) self.horizontalLayout_3 = QtWidgets.QHBoxLayout() self.horizontalLayout_3.setObjectName("horizontalLayout_3") spacerItem1 = QtWidgets.QSpacerItem(98, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.horizontalLayout_3.addItem(spacerItem1) self.toolButton_11 = QtWidgets.QToolButton(self.dockWidgetContents_7) icon3 = QtGui.QIcon() icon3.addPixmap(QtGui.QPixmap(":/VgisIcon/mActionArrowLeft.svg"), QtGui.QIcon.Normal, QtGui.QIcon.On) self.toolButton_11.setIcon(icon3) self.toolButton_11.setObjectName("toolButton_11") self.horizontalLayout_3.addWidget(self.toolButton_11) self.SkipBacktoolButton_8 = QtWidgets.QToolButton( self.dockWidgetContents_7) self.SkipBacktoolButton_8.setStyleSheet("") icon4 = QtGui.QIcon() icon4.addPixmap(QtGui.QPixmap(":/VgisIcon/mActionAtlasPrev.svg"), QtGui.QIcon.Normal, QtGui.QIcon.On) self.SkipBacktoolButton_8.setIcon(icon4) self.SkipBacktoolButton_8.setObjectName("SkipBacktoolButton_8") self.horizontalLayout_3.addWidget(self.SkipBacktoolButton_8) self.playButton = QtWidgets.QToolButton(self.dockWidgetContents_7) self.playButton.setObjectName("playButton") self.horizontalLayout_3.addWidget(self.playButton) self.muteButton = QtWidgets.QToolButton(self.dockWidgetContents_7) self.muteButton.setText("") self.muteButton.setObjectName("muteButton") self.horizontalLayout_3.addWidget(self.muteButton) self.replayPosition_label = QtWidgets.QLabel(self.dockWidgetContents_7) self.replayPosition_label.setObjectName("replayPosition_label") self.horizontalLayout_3.addWidget(self.replayPosition_label) self.SkipFortoolButton_9 = QtWidgets.QToolButton( self.dockWidgetContents_7) self.SkipFortoolButton_9.setStyleSheet("") icon5 = QtGui.QIcon() icon5.addPixmap(QtGui.QPixmap(":/VgisIcon/mActionAtlasNext.svg"), QtGui.QIcon.Normal, QtGui.QIcon.On) self.SkipFortoolButton_9.setIcon(icon5) self.SkipFortoolButton_9.setObjectName("SkipFortoolButton_9") self.horizontalLayout_3.addWidget(self.SkipFortoolButton_9) self.toolButton_12 = QtWidgets.QToolButton(self.dockWidgetContents_7) icon6 = QtGui.QIcon() icon6.addPixmap(QtGui.QPixmap(":/VgisIcon/mActionArrowRight.svg"), QtGui.QIcon.Normal, QtGui.QIcon.On) self.toolButton_12.setIcon(icon6) self.toolButton_12.setObjectName("toolButton_12") self.horizontalLayout_3.addWidget(self.toolButton_12) spacerItem2 = QtWidgets.QSpacerItem(98, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.horizontalLayout_3.addItem(spacerItem2) self.lcdNumber = QtWidgets.QLCDNumber(self.dockWidgetContents_7) self.lcdNumber.setObjectName("lcdNumber") self.horizontalLayout_3.addWidget(self.lcdNumber) self.verticalLayout.addLayout(self.horizontalLayout_3) self.gridLayout_2.addLayout(self.verticalLayout, 0, 0, 1, 1) self.dockWidget_2.setWidget(self.dockWidgetContents_7) self.verticalLayout_3.addWidget(self.dockWidget_2) self.dockWidget_4 = QtWidgets.QDockWidget(Form) self.dockWidget_4.setMaximumSize(QtCore.QSize(524287, 121)) self.dockWidget_4.setFeatures( QtWidgets.QDockWidget.NoDockWidgetFeatures) self.dockWidget_4.setAllowedAreas(QtCore.Qt.BottomDockWidgetArea) self.dockWidget_4.setObjectName("dockWidget_4") self.dockWidgetContents_6 = QtWidgets.QWidget() self.dockWidgetContents_6.setObjectName("dockWidgetContents_6") self.verticalLayout_2 = QtWidgets.QVBoxLayout( self.dockWidgetContents_6) self.verticalLayout_2.setObjectName("verticalLayout_2") self.label = QtWidgets.QLabel(self.dockWidgetContents_6) self.label.setObjectName("label") self.verticalLayout_2.addWidget(self.label) self.horizontalLayout_2 = QtWidgets.QHBoxLayout() self.horizontalLayout_2.setSizeConstraint( QtWidgets.QLayout.SetFixedSize) self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.pushButtonCutA_6 = QtWidgets.QPushButton( self.dockWidgetContents_6) self.pushButtonCutA_6.setEnabled(True) self.pushButtonCutA_6.setObjectName("pushButtonCutA_6") self.horizontalLayout_2.addWidget(self.pushButtonCutA_6) self.pushButtonCutB_6 = QtWidgets.QPushButton( self.dockWidgetContents_6) self.pushButtonCutB_6.setObjectName("pushButtonCutB_6") self.horizontalLayout_2.addWidget(self.pushButtonCutB_6) self.label_7 = QtWidgets.QLabel(self.dockWidgetContents_6) self.label_7.setObjectName("label_7") self.horizontalLayout_2.addWidget(self.label_7) self.doubleSpinBox_2 = QtWidgets.QDoubleSpinBox( self.dockWidgetContents_6) self.doubleSpinBox_2.setObjectName("doubleSpinBox_2") self.horizontalLayout_2.addWidget(self.doubleSpinBox_2) self.comboBox_6 = QtWidgets.QComboBox(self.dockWidgetContents_6) self.comboBox_6.setObjectName("comboBox_6") self.comboBox_6.addItem("") self.comboBox_6.addItem("") self.horizontalLayout_2.addWidget(self.comboBox_6) self.pushButton_5 = QtWidgets.QPushButton(self.dockWidgetContents_6) self.pushButton_5.setObjectName("pushButton_5") self.horizontalLayout_2.addWidget(self.pushButton_5) self.pushButtonCut_2 = QtWidgets.QPushButton(self.dockWidgetContents_6) self.pushButtonCut_2.setObjectName("pushButtonCut_2") self.horizontalLayout_2.addWidget(self.pushButtonCut_2) self.verticalLayout_2.addLayout(self.horizontalLayout_2) self.progressBar = QtWidgets.QProgressBar(self.dockWidgetContents_6) self.progressBar.setProperty("value", 24) self.progressBar.setObjectName("progressBar") self.verticalLayout_2.addWidget(self.progressBar) self.dockWidget_4.setWidget(self.dockWidgetContents_6) self.verticalLayout_3.addWidget(self.dockWidget_4) self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form) def retranslateUi(self, Form): _translate = QtCore.QCoreApplication.translate Form.setWindowTitle(_translate("Form", "Video UAV Tracker - Player")) self.pushButton_3.setToolTip( _translate( "Form", "<html><head/><body><p>Move along Video directly clicking on gps track</p></body></html>" )) self.pushButton_3.setText(_translate("Form", "MapTool ")) self.label_2.setText(_translate("Form", "Overlap %")) self.toolButton_6.setToolTip( _translate("Form", "<html><head/><body><p>Add point</p></body></html>")) self.toolButton_6.setText(_translate("Form", "o")) self.toolButton_4.setToolTip( _translate( "Form", "<html><head/><body><p>Enable extract frames toolbox</p><p><br/></p></body></html>" )) self.toolButton_4.setText(_translate("Form", "Extract frames")) self.toolButton_5.setText(_translate("Form", "Close")) self.toolButton_11.setText(_translate("Form", "<<")) self.SkipBacktoolButton_8.setText(_translate("Form", "<")) self.playButton.setText(_translate("Form", "> / ||")) self.replayPosition_label.setText(_translate("Form", "-:- / -:-")) self.SkipFortoolButton_9.setText(_translate("Form", ">")) self.toolButton_12.setText(_translate("Form", ">>")) self.label.setText(_translate("Form", "Export Frames Tool")) self.pushButtonCutA_6.setToolTip( _translate( "Form", "<html><head/><body><p>Export from actual Video Frame</p></body></html>" )) self.pushButtonCutA_6.setText(_translate("Form", "From A")) self.pushButtonCutB_6.setToolTip( _translate( "Form", "<html><head/><body><p>Export to actual Video Frame</p></body></html>" )) self.pushButtonCutB_6.setText(_translate("Form", "To B")) self.label_7.setText(_translate("Form", "Pick one frame every")) self.comboBox_6.setItemText(0, _translate("Form", "meters")) self.comboBox_6.setItemText(1, _translate("Form", "seconds")) self.pushButton_5.setText(_translate("Form", "Cancel")) self.pushButtonCut_2.setText(_translate("Form", "Extract!")) self.toolButton_7.setText(_translate("Form", "3D")) self.pushButton.setText(_translate("Form", "Create Mosaic"))