From e9d9bbb5d6786ec4fcfe5fbd5b998206130a9b7d Mon Sep 17 00:00:00 2001 From: Stevenson Chittumuri Date: Mon, 5 Dec 2022 15:43:51 -0500 Subject: [PATCH] added simple UI for RTSP --- views/functions/add_ip_camera_ui.py | 97 ++++++++++++++++++++++++ views/functions/assign_network_ptz_ui.py | 4 +- views/functions/test_rtsp_camera.py | 15 ++++ views/homepage/main_window.py | 6 ++ 4 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 views/functions/add_ip_camera_ui.py create mode 100644 views/functions/test_rtsp_camera.py diff --git a/views/functions/add_ip_camera_ui.py b/views/functions/add_ip_camera_ui.py new file mode 100644 index 0000000..c1b138a --- /dev/null +++ b/views/functions/add_ip_camera_ui.py @@ -0,0 +1,97 @@ +import cv2 +from PySide6 import QtCore, QtWidgets +from PySide6.QtWidgets import QDialog +from shared.message_prompts import show_critical_messagebox + + +class AddIPSourceUI(object): + def __init__(self): + self.username_line = None + self.password_line = None + self.ip_address_line = None + self.port_line = None + self.horizontalLayout_user = None + self.horizontalLayout_ip = None + self.horizontalLayout_btn = None + self.cancel_btn = None + self.submit = None + self.verticalLayout = None + self.window = None + self.count = 0 + + def setupUi(self, connect_to_ip): + self.window = connect_to_ip + connect_to_ip.setObjectName("connect_to_ip") + connect_to_ip.resize(300, 80) + self.verticalLayout = QtWidgets.QVBoxLayout(connect_to_ip) + self.verticalLayout.setObjectName("verticalLayout") + + self.horizontalLayout_user = QtWidgets.QHBoxLayout(connect_to_ip) + self.verticalLayout.addLayout(self.horizontalLayout_user) + self.username_line = QtWidgets.QLineEdit(connect_to_ip) + self.username_line.setPlaceholderText("username_line") + self.horizontalLayout_user.addWidget(self.username_line) + self.password_line = QtWidgets.QLineEdit(connect_to_ip) + self.password_line.setPlaceholderText("password_line") + self.horizontalLayout_user.addWidget(self.password_line) + + self.horizontalLayout_ip = QtWidgets.QHBoxLayout(connect_to_ip) + self.verticalLayout.addLayout(self.horizontalLayout_ip) + self.ip_address_line = QtWidgets.QLineEdit(connect_to_ip) + self.ip_address_line.setPlaceholderText("ip_address_line") + self.horizontalLayout_ip.addWidget(self.ip_address_line) + self.port_line = QtWidgets.QLineEdit(connect_to_ip) + self.port_line.setPlaceholderText("port_line") + self.horizontalLayout_ip.addWidget(self.port_line) + + self.horizontalLayout_btn = QtWidgets.QHBoxLayout() + self.horizontalLayout_btn.setObjectName("horizontalLayout_btn") + self.verticalLayout.addLayout(self.horizontalLayout_btn) + self.submit = QtWidgets.QPushButton(connect_to_ip) + self.submit.setObjectName("submit") + self.submit.clicked.connect(self.connect_to_ip_prompt) + self.horizontalLayout_btn.addWidget(self.submit) + self.cancel_btn = QtWidgets.QPushButton(connect_to_ip) + self.cancel_btn.setObjectName("cancel_btn") + self.cancel_btn.clicked.connect(self.window.close) + self.horizontalLayout_btn.addWidget(self.cancel_btn) + + self.translate_ui(connect_to_ip) + QtCore.QMetaObject.connectSlotsByName(connect_to_ip) + + def connect_to_ip_prompt(self): + vcap = cv2.VideoCapture( + f"rtsp://{self.username_line.text().strip()}:{self.password_line.text().strip()}@{self.ip_address_line.text().strip()}:{self.port_line.text().strip()}/live") + print(f"{self.username_line.text().strip()}:{self.password_line.text().strip()}@{self.ip_address_line.text().strip()}:{self.port_line.text().strip()}") + while True: + ret, frame = vcap.read() + if not ret: + show_critical_messagebox(window_title="IP Camera Source", + critical_message="Something went wrong.\nPlease try again!") + break + else: + self.window.close() + vcap.release() + + + def translate_ui(self, connect_to_ip): + _translate = QtCore.QCoreApplication.translate + connect_to_ip.setWindowTitle(_translate("connect_to_ip", "Connect to IP Camera")) + self.username_line.setPlaceholderText(_translate("username_line", "Enter Username")) + self.password_line.setPlaceholderText(_translate("password_line", "Enter Password")) + self.ip_address_line.setPlaceholderText(_translate("ip_address_line", "Enter IP Address")) + self.port_line.setPlaceholderText(_translate("port_line", "Enter Port")) + self.submit.setText(_translate("submit", "Submit")) + self.cancel_btn.setText(_translate("cancel_btn", "Cancel")) + + +class AddIPSourceDlg(QDialog): + """Setup Add Face Dialog""" + + def __init__(self, parent=None): + super().__init__(parent) + + # Create an instance of the GUI + self.ui = AddIPSourceUI() + # Run the .setupUi() method to show the GUI + self.ui.setupUi(self) diff --git a/views/functions/assign_network_ptz_ui.py b/views/functions/assign_network_ptz_ui.py index 15c258a..2c67e3f 100644 --- a/views/functions/assign_network_ptz_ui.py +++ b/views/functions/assign_network_ptz_ui.py @@ -82,13 +82,13 @@ def assign_net_ptz_prompt(self): "is enabled in your camera settings.") self.window.close() - def translate_ui(self, add_face): + def translate_ui(self, assign_net_ptz): """ Automatic Translation Locale :param add_face: """ _translate = QtCore.QCoreApplication.translate - add_face.setWindowTitle(_translate("assign_net_ptz", "Assign Network PTZ")) + assign_net_ptz.setWindowTitle(_translate("assign_net_ptz", "Assign Network PTZ")) self.allow_network_control.setText( _translate("allow_network_control", "VISCA Login for " + self.camera_widget.objectName() + ":")) self.port_line.setPlaceholderText(_translate("port_line", "Enter Port (Default=52381)")) diff --git a/views/functions/test_rtsp_camera.py b/views/functions/test_rtsp_camera.py new file mode 100644 index 0000000..922ae7e --- /dev/null +++ b/views/functions/test_rtsp_camera.py @@ -0,0 +1,15 @@ +import cv2 +import numpy as np +import os +# os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "rtsp_transport;udp" +vcap = cv2.VideoCapture("rtsp://ad:mi@192.168.1.6:554/live") + +while(True): + ret, frame = vcap.read() + if ret == False: + print("Frame is empty") + break + else: + cv2.imshow('VIDEO', frame) + cv2.waitKey(1) + vcap.release() \ No newline at end of file diff --git a/views/homepage/main_window.py b/views/homepage/main_window.py index 3f601a0..1861968 100644 --- a/views/homepage/main_window.py +++ b/views/homepage/main_window.py @@ -12,6 +12,7 @@ from libraries.visca.move_visca_ptz import ViscaPTZ from logic.camera_search.get_serial_cameras import COMPorts from shared.message_prompts import show_info_messagebox +from views.functions.add_ip_camera_ui import AddIPSourceDlg from views.functions.show_dialogs_ui import ShowDialog from views.functions.assign_network_ptz_ui import AssignNetworkPTZDlg from views.homepage.flow_layout import FlowLayout @@ -358,6 +359,7 @@ def __init__(self, *args, **kwargs): self.actionClose.setObjectName("actionClose") self.actionAdd_IP = QtWidgets.QWidgetAction(self) self.actionAdd_IP.setObjectName("actionAdd_IP") + self.actionAdd_IP.triggered.connect(self.addIPSource) self.menuAdd_NDI = QtWidgets.QMenu(self) self.menuAdd_NDI.setObjectName("menuAdd_NDI") self.menuAdd_Hardware = QtWidgets.QMenu(self) @@ -415,6 +417,10 @@ def __init__(self, *args, **kwargs): self.translateUi(self) QtCore.QMetaObject.connectSlotsByName(self) + def addIPSource(self): + dlg = AddIPSourceDlg(self) + dlg.exec() + def findHardwareSources(self): """Adds camera sources to the Hardware source list""" available_cameras = QMediaDevices.videoInputs()