Python中用于视频捕获多摄像机的线程

2024-04-24 05:52:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Python中使用线程和opencv。
我想同时显示两个窗口。
但此时只能显示一个窗口。
这是我的代码。

import cv2, time
class Core:
    @staticmethod
    def detection(ip):
        capture = cv2.VideoCapture('rtsp://'+str(ip))
        while (capture.isOpened()):
            ret, frame = capture.read()
            cv2.imshow('Video',frame)

            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
        capture.release()
class Thread (threading.Thread):
    def __init__(self, threadID,ip):
        threading.Thread.__init__(self)
        self.threadID = threadID
        self.ip = ip

    def run(self):
        print("Start threadID" +str(self.threadID))
        Core.detection(self.ip)
        print("Exiting " + str(self.threadID))

threads = []
thread1 = Thread(1,'192.168.1.4:5554/playlist.m3u')
thread2 = Thread(2,'192.168.1.4:5554/playlist.m3u')
threads.append(thread1)
threads.append(thread2)
for i in threads:
    i.start()
print("Exit to main thread")

我想知道是否有解决这个问题的办法
非常感谢你


Tags: coreselfipdefcv2threadframeclass