import numpy as np
import cv2
import multiprocessing
from multiprocessing import Queue
import time
CAMERA_COUNT=4 #摄像头个数
url="http://admin:[email protected]:8081/"#外置摄像头地址及密码
video = "http://admin:[email protected]:8081/"
video1 = "http://admin:[email protected]:8081/"
# 不同进程不能共享内存,定义队列进行进程通信
q = Queue()
def video_read(id):
camera_id = id
#使用笔记本自带的摄像头
if camera_id == 0:
cap = cv2.VideoCapture(0)
#使用外置的摄像头
if camera_id == 1:
cap = cv2.VideoCapture(url)
if camera_id == 2:
cap = cv2.VideoCapture(video)
if camera_id == 3:
cap = cv2.VideoCapture(video1)
# 获取每一个视频的尺寸
width = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)))
height = (int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
print(width,height)
while (cap.isOpened()):
ret,frame = cap.read()
frame = cv2.resize(frame, (960, 720), interpolation=cv2.INTER_CUBIC)
isEmpty = q.empty()
print(isEmpty )
if isEmpty == True:
print('队列中无数据!')
#q.put(frame)
time.sleep(0.001)
else:
print('队列中有数据!')
#Frame = q.get(frame)
time.sleep(0.002)
#frameUp = np.hstack(frame, Frame)#左右合并
#frameUp = np.vstack((frameLeftUp, frameRightUp))#上下合并
cv2.imshow('camera'+str(id), frame )
key = cv2.waitKey(10)
if int(key) == 113:
break
cap.release()
#---------------------------------------------------------------------------------
if __name__ == '__main__':
print("主进程开始启动!")
for index in range(CAMERA_COUNT):
print('摄像头的索引号是:',index)
p = multiprocessing.Process(target = video_read, args = (index,))
p.start()
print('程序结束!')
python读取两路ip摄像头实时直播监控
猜你喜欢
转载自blog.csdn.net/babyai996/article/details/121486149
今日推荐
周排行