Skip to content

Instantly share code, notes, and snippets.

@lucabelluccini
Created May 8, 2014 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucabelluccini/a0fc09df33cbd10c6375 to your computer and use it in GitHub Desktop.
Save lucabelluccini/a0fc09df33cbd10c6375 to your computer and use it in GitHub Desktop.
Testing 2 webcams for stereo vision
import cv2, numpy
webcamL_index = 1
webcamR_index = 0
webcam_h = 640
webcam_v = 480
viewport_size = (1920, 1080)
webcamL = cv2.VideoCapture(webcamL_index)
webcamL.set(3, webcam_h)
webcamL.set(4, webcam_v)
webcamR = cv2.VideoCapture(webcamR_index)
webcamR.set(3, webcam_h)
webcamR.set(4, webcam_v)
WINDOW_NAME = "Preview"
cv2.namedWindow(WINDOW_NAME, cv2.cv.CV_WINDOW_NORMAL | cv2.cv.CV_WINDOW_AUTOSIZE)
cv2.setWindowProperty(WINDOW_NAME, cv2.WND_PROP_FULLSCREEN, cv2.cv.CV_WINDOW_FULLSCREEN)
if not webcamL.isOpened() or not webcamR.isOpened():
exit(1)
frame = numpy.zeros((webcam_v, webcam_h*2, 3), dtype=numpy.uint8)
while cv2.waitKey(1) == -1:
resultR, frameR = webcamR.read()
resultL, frameL = webcamL.read()
frame[:webcam_v, :webcam_h] = frameL
frame[:webcam_v, webcam_h:webcam_h*2] = frameR
viewport = cv2.resize(frame, viewport_size)
cv2.imshow(WINDOW_NAME, viewport)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment