我制作了双目摄像头,现在在Python下使用OpenCV加载这两个摄像头,并排放置,实现双目摄像头效果:
自制硬件:
代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import cv2 import numpy cv2.namedWindow("left") cv2.namedWindow("right") cv2.moveWindow("left", 0, 0) cv2.moveWindow("right", 600, 0) left_camera = cv2.VideoCapture(1) #加载左摄像头 right_camera = cv2.VideoCapture(6) #加载右摄像头 while True: ret, left_frame = left_camera .read() #读取左摄像头 ret, right_frame = right_camera .read() #读取右摄像头 cv2.imshow("left", left_frame) cv2.imshow("right", right_frame) key = cv2.waitKey(1) if key == ord('q'): break left_camera.release() right_camera.release() cv2.destroyWindow("left") cv2.destroyWindow("right") |
效果:
视频: