最近要做死鸡检测,公司光学同事给到了我这个红外双目摄像头,我一开始读的时候跟poe接口的网络摄像头的连接读取方式是一样的,但是读取出来的画面只有一个,并没有红外画面
查了半天资料,发现调用的时候要调用两个!
import cv2
ip_address = '192.168.254.5'
port = 554
username = 'admin'
password = '123456789'
stream_path_left = f'rtsp://{username}:{password}@{ip_address}:{port}/cam/realmonitor?channel=1&subtype=0'
stream_path_right = f'rtsp://{username}:{password}@{ip_address}:{port}/cam/realmonitor?channel=2&subtype=0'
cap_left = cv2.VideoCapture(stream_path_left, cv2.CAP_FFMPEG)
cap_right = cv2.VideoCapture(stream_path_right, cv2.CAP_FFMPEG)
if not cap_left.isOpened() or not cap_right.isOpened():
print('无法连接相机!')
exit()
while True:
ret_left, frame_left = cap_left.read()
ret_right, frame_right = cap_right.read()
if not ret_left or not ret_right:
print('无法读取帧!')
break
cv2.imshow('RGB camera', frame_left)
cv2.imshow('Infrared camera', frame_right)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap_left.release()
cap_right.release()
cv2.destroyAllWindows()
这样就可以同时打开RGB摄像头和红外摄像头了