42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
import sys
|
|
from PyQt5.QtWidgets import QApplication, QLabel, QVBoxLayout, QWidget
|
|
from PyQt5.QtGui import QPixmap, QImage
|
|
from PyQt5.QtCore import Qt
|
|
from CameraThread import CameraThread
|
|
from print_color import *
|
|
class MainWindow(QWidget):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.initUI()
|
|
|
|
def initUI(self):
|
|
self.setWindowTitle("Camera Test")
|
|
self.setGeometry(100, 100, 800, 600)
|
|
|
|
self.label = QLabel(self)
|
|
self.label.setAlignment(Qt.AlignCenter)
|
|
|
|
layout = QVBoxLayout()
|
|
layout.addWidget(self.label)
|
|
self.setLayout(layout)
|
|
|
|
self.camera_thread = CameraThread("rtsp://192.168.1.211:554")
|
|
self.camera_thread.image_signal.connect(self.update_image)
|
|
self.camera_thread.start()
|
|
|
|
def update_image(self, image):
|
|
q_image = QImage(image.data, image.shape[1], image.shape[0], QImage.Format_RGB888)
|
|
pixmap = QPixmap.fromImage(q_image)
|
|
self.label.setPixmap(pixmap.scaled(self.label.size(), Qt.KeepAspectRatio))
|
|
|
|
def closeEvent(self, event):
|
|
self.camera_thread.close()
|
|
self.camera_thread.wait()
|
|
event.accept()
|
|
|
|
if __name__ == "__main__":
|
|
app = QApplication(sys.argv)
|
|
window = MainWindow()
|
|
window.show()
|
|
sys.exit(app.exec_())
|