Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # imports
- import sys
- import cv2
- import datetime
- from PyQt5.QtWidgets import *
- from PyQt5.QtGui import *
- from PyQt5.QtCore import *
- # custom imports
- import arconfig
- cam = cv2.VideoCapture(arconfig.cap1)
- app = QApplication([])
- screen_resolution = app.desktop().screenGeometry()
- winwidth, winheight = screen_resolution.width(), screen_resolution.height()
- vidwith = winwidth * 0.84
- vidheight = vidwith * 0.5625
- class Ui_MainWindow(object):
- def setupUi(self, MainWindow):
- MainWindow.setObjectName("MainWindow")
- MainWindow.setFixedSize(winwidth, winheight)
- MainWindow.setWindowTitle("ARCV")
- self.centralWidget = QWidget(MainWindow)
- self.centralWidget.setObjectName("Video")
- self.label = QLabel(self.centralWidget)
- self.label.setGeometry(winwidth*0.01, winwidth*0.01, vidwith, vidheight)
- self.label.setFixedSize(vidwith, vidheight)
- self.label.setScaledContents(True)
- self.label.setObjectName("Video")
- MainWindow.setCentralWidget(self.centralWidget)
- self.dockWidget = QDockWidget(MainWindow)
- self.dockWidget.setFixedSize(winwidth * 0.14, winheight)
- self.dockWidget.setLayoutDirection(Qt.LeftToRight)
- self.dockWidget.setFeatures(QDockWidget.DockWidgetMovable)
- self.dockWidget.setAllowedAreas(Qt.LeftDockWidgetArea|Qt.RightDockWidgetArea)
- self.dockWidget.setObjectName("dockWidget")
- self.dockWidgetContents = QWidget()
- self.dockWidgetContents.setObjectName("dockWidgetContents")
- self.groupBox = QGroupBox(self.dockWidgetContents)
- self.groupBox.setGeometry(QRect(winwidth * 0.01, winwidth * 0.01, winwidth * 0.12, winheight * 0.7))
- self.groupBox.setObjectName("groupBox")
- self.groupBox.setTitle("Options")
- self.startRecButton = QPushButton(self.groupBox)
- self.startRecButton.setGeometry(QRect(winwidth * 0.01, winwidth * 0.02, winwidth * 0.10, winwidth * 0.025))
- self.startRecButton.setObjectName("startRecButton")
- self.startRecButton.setText("Start Recording")
- self.stopRecButton = QPushButton(self.groupBox)
- self.stopRecButton.setGeometry(QRect(winwidth * 0.01, winwidth * 0.05, winwidth * 0.10, winwidth * 0.025))
- self.stopRecButton.setObjectName("stopRecButton")
- self.stopRecButton.setText("Stop Recording")
- self.settingsButton = QPushButton(self.groupBox)
- self.settingsButton.setGeometry(QRect(winwidth * 0.01, winwidth * 0.08, winwidth * 0.10, winwidth * 0.025))
- self.settingsButton.setObjectName("settingsButton")
- self.settingsButton.setText("Settings")
- self.cam1radioButton = QRadioButton(self.groupBox) ### Here the radiobuttons start
- self.cam1radioButton.setGeometry(QRect(winwidth * 0.02, winwidth * 0.12, winwidth * 0.10, winwidth * 0.02))
- self.cam1radioButton.setObjectName("cam1radioButton")
- self.cam1radioButton.toggle()
- self.cam1radioButton.clicked.connect(self.switchCam)
- self.cam1radioButton.setText("Camera 1")
- self.cam2radioButton = QRadioButton(self.groupBox)
- self.cam2radioButton.setGeometry(QRect(winwidth * 0.02, winwidth * 0.15, winwidth * 0.10, winwidth * 0.02))
- self.cam2radioButton.setObjectName("cam2radioButton")
- self.cam2radioButton.clicked.connect(self.switchCam)
- self.cam2radioButton.setText("Camera 2")
- self.cam3radioButton = QRadioButton(self.groupBox)
- self.cam3radioButton.setGeometry(QRect(winwidth * 0.02, winwidth * 0.18, winwidth * 0.10, winwidth * 0.02))
- self.cam3radioButton.setObjectName("cam3radioButton")
- self.cam3radioButton.clicked.connect(self.switchCam)
- self.cam3radioButton.setText("Camera 3")
- self.dockWidget.setWidget(self.dockWidgetContents)
- MainWindow.addDockWidget(Qt.DockWidgetArea(2), self.dockWidget)
- def switchCam(self): ###Here is where I try to switch cams
- global cam
- if self.cam1radioButton.isChecked():
- cam = cv2.VideoCapture(arconfig.cap1)
- elif self.cam2radioButton.isChecked():
- cam = cv2.VideoCapture(arconfig.cap2)
- elif self.cam3radioButton.isChecked():
- cam = cv2.VideoCapture(arconfig.cap3)
- class Thread(QThread):
- changePixmap = pyqtSignal(QImage)
- def __init__(self, *args, **kwargs):
- QThread.__init__(self, *args, **kwargs)
- self.flag = False
- def run(self):
- self.flag = True
- while self.flag:
- ret, frame = cam.read()
- if ret:
- cv2.putText(frame, datetime.datetime.now().strftime("%d-%m-%Y--%H-%M-%S"),
- (30, 60), arconfig.font, 3, (0, 0, 0), 4, cv2.LINE_AA)
- rgb_image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
- cvt2qt = QImage(rgb_image.data, rgb_image.shape[1], rgb_image.shape[0], QImage.Format_RGB888)
- self.changePixmap.emit(cvt2qt)
- def stop(self):
- cam.release()
- self.flag = False
- class Prog(QMainWindow, Ui_MainWindow):
- def __init__(self):
- super().__init__()
- self.setupUi(self)
- self.th = Thread(self)
- self.th.changePixmap.connect(self.setImage)
- self.th.start()
- @pyqtSlot(QImage)
- def setImage(self, image):
- self.label.setPixmap(QPixmap.fromImage(image))
- def closeEvent(self, event):
- reply = QMessageBox.question(self, "Close ARCV", "Are you sure to quit the ARCV user interface?",
- QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
- if reply == QMessageBox.Yes:
- event.accept()
- self.th.stop()
- quit()
- super().closeEvent(event)
- else:
- event.ignore()
- if __name__=='__main__':
- Program = QApplication(sys.argv)
- MyProg = Prog()
- MyProg.show()
- sys.exit(Program.exec_())
- # define video streams ### These are the file paths which are interchanged
- cap1 = "single.mp4"
- cap2 = "test1.mp4"
- cap3 = "test2.mp4"
- # define file destination for automatically saved videos
- auto_dest = "./captured/"
- # define file destination for manually recorded videos
- man_dest = "./records/"
- # define OpenCV system font
- font = cv2.FONT_HERSHEY_PLAIN
- # define output format and name format
- fourcc = cv2.VideoWriter_fourcc('a', 'v', 'c', '1')
- # pre-defined variables
- # in case of movement add (n) frames at beginning and end of video output
- lenPrequel = 90
- lenSequel = 120
- # minimum picture-area changing to detect movement
- min_area = 500
- # minimal difference between average and gray frame
- delta_thresh = 5
Add Comment
Please, Sign In to add comment