Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Problem with imshow() to get live disparity map of 2 videos

I'm following the tutorial here, to get a disparity map from 2 pictures:

import numpy as np
import cv2
from matplotlib import pyplot as plt

imgL = cv2.imread('tsukuba_l.png',0)
imgR = cv2.imread('tsukuba_r.png',0)

stereo = cv2.createStereoBM(numDisparities=16, blockSize=15)
disparity = stereo.compute(imgL,imgR)
plt.imshow(disparity,'gray')
plt.show()

Now, I would like to do the same thing for live video. Unfortunately, cv2.imshow is not working : No error message but only a grey window. code used :

import numpy as np
import cv2

cap_left = cv2.VideoCapture(1)
cap_left = cv2.VideoCapture(2)


# create windows
cv2.namedWindow('left_Webcam', cv2.WINDOW_NORMAL)
cv2.namedWindow('right_Webcam', cv2.WINDOW_NORMAL)
cv2.namedWindow('disparity', cv2.WINDOW_NORMAL)

while(cv2.waitKey(1) & 0xFF != ord('q')):
    ret1, frame_left = cap_left.read()
    ret2, frame_right = cap_left.read()
    # our operations on the frame come here
    gray_left = cv2.cvtColor(frame1, cv2.COLOR_BGR2GRAY)
    gray_left = cv2.cvtColor(frame2, cv2.COLOR_BGR2GRAY)
    cv2.imshow('left_Webcam', gray_left)
    cv2.imshow('right_Webcam', gray_right)
    disparity = cv2.createStereoBM(numDisparities=16, blockSize=15)
    disparity = stereo.compute(gray_left, gray_right)
    cv2.imshow('disparity', disparity)
# When everything done, release the capture
cap1.release()
cap2.release()
cv2.destroyAllWindows()

So how can I get a live disparity map? By the way, if I used a fixed image from my webcams, using matplotlib as in the example of the tutorial, it's working (but it's a fixed image so...)

Problem with imshow() to get live disparity map of 2 videos

I'm following the tutorial here, to get a disparity map from 2 pictures:

import numpy as np
import cv2
from matplotlib import pyplot as plt

imgL = cv2.imread('tsukuba_l.png',0)
imgR = cv2.imread('tsukuba_r.png',0)

stereo = cv2.createStereoBM(numDisparities=16, blockSize=15)
disparity = stereo.compute(imgL,imgR)
plt.imshow(disparity,'gray')
plt.show()

Now, I would like to do the same thing for live video. Unfortunately, cv2.imshow is not working : No error message but only a grey window. code used :

import numpy as np
import cv2

cap_left = cv2.VideoCapture(1)
cap_left = cv2.VideoCapture(2)


# create windows
cv2.namedWindow('left_Webcam', cv2.WINDOW_NORMAL)
cv2.namedWindow('right_Webcam', cv2.WINDOW_NORMAL)
cv2.namedWindow('disparity', cv2.WINDOW_NORMAL)

while(cv2.waitKey(1) & 0xFF != ord('q')):
    ret1, frame_left = cap_left.read()
    ret2, frame_right = cap_left.read()
    # our operations on the frame come here
    gray_left = cv2.cvtColor(frame1, cv2.cvtColor(frame_left, cv2.COLOR_BGR2GRAY)
    gray_left = cv2.cvtColor(frame2, cv2.cvtColor(frame_right, cv2.COLOR_BGR2GRAY)
    cv2.imshow('left_Webcam', gray_left)
    cv2.imshow('right_Webcam', gray_right)
    disparity = cv2.createStereoBM(numDisparities=16, blockSize=15)
    disparity = stereo.compute(gray_left, gray_right)
    cv2.imshow('disparity', disparity)
# When everything done, release the capture
cap1.release()
cap2.release()
cv2.destroyAllWindows()

So how can I get a live disparity map? By the way, if I used a fixed image from my webcams, using matplotlib as in the example of the tutorial, it's working (but it's a fixed image so...)

Problem with imshow() to get live disparity map of 2 videos

I'm following the tutorial here, to get a disparity map from 2 pictures:

import numpy as np
import cv2
from matplotlib import pyplot as plt

imgL = cv2.imread('tsukuba_l.png',0)
imgR = cv2.imread('tsukuba_r.png',0)

stereo = cv2.createStereoBM(numDisparities=16, blockSize=15)
disparity = stereo.compute(imgL,imgR)
plt.imshow(disparity,'gray')
plt.show()

Now, I would like to do the same thing for live video. Unfortunately, cv2.imshow is not working : No error message but only a grey window. code used :

import numpy as np
import cv2

cap_left = cv2.VideoCapture(1)
cap_left = cv2.VideoCapture(2)


# create windows
cv2.namedWindow('left_Webcam', cv2.WINDOW_NORMAL)
cv2.namedWindow('right_Webcam', cv2.WINDOW_NORMAL)
cv2.namedWindow('disparity', cv2.WINDOW_NORMAL)

while(cv2.waitKey(1) & 0xFF != ord('q')):
    ret1, frame_left = cap_left.read()
    ret2, frame_right = cap_left.read()
    # our operations on the frame come here
    gray_left = cv2.cvtColor(frame_left, cv2.COLOR_BGR2GRAY)
    gray_left = cv2.cvtColor(frame_right, cv2.COLOR_BGR2GRAY)
    cv2.imshow('left_Webcam', gray_left)
    cv2.imshow('right_Webcam', gray_right)
    disparity stereo = cv2.createStereoBM(numDisparities=16, blockSize=15)
    disparity = stereo.compute(gray_left, gray_right)
    cv2.imshow('disparity', disparity)
# When everything done, release the capture
cap1.release()
cap2.release()
cv2.destroyAllWindows()

So how can I get a live disparity map? By the way, if I used a fixed image from my webcams, using matplotlib as in the example of the tutorial, it's working (but it's a fixed image so...)

click to hide/show revision 4
retagged

updated 2014-05-05 01:33:50 -0600

berak gravatar image

Problem with imshow() to get live disparity map of 2 videos

I'm following the tutorial here, to get a disparity map from 2 pictures:

import numpy as np
import cv2
from matplotlib import pyplot as plt

imgL = cv2.imread('tsukuba_l.png',0)
imgR = cv2.imread('tsukuba_r.png',0)

stereo = cv2.createStereoBM(numDisparities=16, blockSize=15)
disparity = stereo.compute(imgL,imgR)
plt.imshow(disparity,'gray')
plt.show()

Now, I would like to do the same thing for live video. Unfortunately, cv2.imshow is not working : No error message but only a grey window. code used :

import numpy as np
import cv2

cap_left = cv2.VideoCapture(1)
cap_left = cv2.VideoCapture(2)


# create windows
cv2.namedWindow('left_Webcam', cv2.WINDOW_NORMAL)
cv2.namedWindow('right_Webcam', cv2.WINDOW_NORMAL)
cv2.namedWindow('disparity', cv2.WINDOW_NORMAL)

while(cv2.waitKey(1) & 0xFF != ord('q')):
    ret1, frame_left = cap_left.read()
    ret2, frame_right = cap_left.read()
    # our operations on the frame come here
    gray_left = cv2.cvtColor(frame_left, cv2.COLOR_BGR2GRAY)
    gray_left = cv2.cvtColor(frame_right, cv2.COLOR_BGR2GRAY)
    cv2.imshow('left_Webcam', gray_left)
    cv2.imshow('right_Webcam', gray_right)
    stereo = cv2.createStereoBM(numDisparities=16, blockSize=15)
    disparity = stereo.compute(gray_left, gray_right)
    cv2.imshow('disparity', disparity)
# When everything done, release the capture
cap1.release()
cap2.release()
cv2.destroyAllWindows()

So how can I get a live disparity map? By the way, if I used a fixed image from my webcams, using matplotlib as in the example of the tutorial, it's working (but it's a fixed image so...)