多线程视频

import cv2
import threading
import numpy as np
import serial
flag=False
def mySerial():
global flag
port = serial.Serial(“com1”,9600)
if port.isOpen():
port.close()
port.open()

#port.open()
while True:
    dat = port.readline()
    if dat:
        flag=True
        print("start")
        print(dat.decode('utf-8'))

camera = cv2.VideoCapture(0)
ret,frame = camera.read()
def showcamer1():
global ret,frame
while ret:
ret,frame = camera.read()
#cv2.imshow(“s”,frame)
if cv2.waitKey(20) & 0xff ==27:
break
camera2 = cv2.VideoCapture(1)
ret2,frame2 = camera2.read()
def showcamer2():
global ret2
global frame2
while ret2:
ret2,frame2 = camera2.read()
#cv2.imshow(“camer2”,frame2)
if cv2.waitKey(10) & 0xff 27:
break
def showAllCamera():
global ret2,frame2
global ret,frame
global flag
while ret2:
result = np.hstack([frame,frame2])
if flag
True:
cv2.imshow(“camera2”,result)
flag = False
cv2.waitKey(10)
thread1 = threading.Thread(target=showcamer1)
thread1.start()
thread2 = threading.Thread(target=showcamer2)
thread2.start()
thread3 = threading.Thread(target=showAllCamera)
thread3.start()
thread4 = threading.Thread(target=mySerial())
thread4.start()

猜你喜欢

转载自blog.csdn.net/tel_1392/article/details/113785295