I am writing a program which displays a security console for all my rtsp streams from my ip cameras. Each stream plays in a different window, I want it all to be merged into one window.
Here is my code:
import cv2
import threading
class camThread(threading.Thread):
def __init__(self, previewName, camID):
threading.Thread.__init__(self)
self.previewName = previewName
self.camID = camID
def run(self):
camPreview(self.previewName, self.camID)
def camPreview(previewName, camID):
# global frame
cv2.namedWindow(previewName)
cam = cv2.VideoCapture(camID)
if cam.isOpened(): # try to get the first frame
rval, frame = cam.read()
else:
rval = False
while rval:
frame = cv2.resize(frame, (620,400))
cv2.imshow(previewName, frame)
rval, frame = cam.read()
cv2.waitKey(20)
thread1 = camThread("Camera 1", 'my-rtsp-link')
thread2 = camThread("Camera 2", "my-second-rtsp-link")
thread1.start()
thread2.start()
I've tried multiproccessing and it doesn't work since I have a while loop in my function. Any help would be greatly appreciated.
I used np.hstack
to combine my rtsp streams however this makes the streams freeze. So I got both streams working by multithreading. But now each stream is playing in its individual window which is very messy if I add multiple cameras. How can I merge it all into one big window?