過了一段時間,我找到了解決方案。在這個例子中,我有一個我首先加載的.ui模板。在這個窗口中是一個名爲'label'的標籤,我想在其中加載我的流。你將需要openCV。
class videoThread(QThread):
def __init__(self,address):
super(videoThread,self).__init__()
self.ip = address
def run(self):
cap = cv2.VideoCapture("http://"+ str(self.ip) +
":8081/?action=stream?dummy=param.mjpg")
while cap.isOpened():
_,frame = cap.read()
# adjust width en height to the preferred values
image = QImage(frame.tostring(),640,480,QImage.Format_RGB888)
.rgbSwapped()
self.emit(SIGNAL('newImage(QImage)'), image)
class MyGui(QMainWindow):
"""
My gui implementation
"""
def __init__(self,template):
super(MyGui,self).__init__()
uic.loadUi(template,self)
#video stream
self.video = videoThread("192.168.1.100")
self.video.start()
#my label is named label
self.label.connect(self.video,SIGNAL('newImage(QImage)'),self.setFrame)
def setFrame(self,frame):
pixmap = QPixmap.fromImage(frame)
self.label.setPixmap(pixmap)