Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV 3 + Python 3 + Firewire Cameras

I am trying to activate my 2 firewire cameras plugged in to build a depth image from them, but I cannot seem to activate even one:

    import numpy as np
from sklearn.preprocessing import normalize
import cv2

    # SGBM Parameters -----------------
    window_size = 3                     # wsize default 3; 5; 7 for SGBM reduced size image; 15 for SGBM full size image (1300px and above); 5 Works nicely

left_matcher = cv2.StereoSGBM_create(
    minDisparity=0,


 numDisparities=160,             # max_disp has to be dividable by 16 f. E. HH 192, 256
    blockSize=5,
    P1=8 * 3 * window_size ** 2,    # wsize default 3; 5; 7 for SGBM reduced size image; 15 for SGBM full size image (1300px and above); 5 Works nicely
    P2=32 * 3 * window_size ** 2,
    disp12MaxDiff=1,
    uniquenessRatio=15,
    speckleWindowSize=0,
    speckleRange=2,
    preFilterCap=63,

    mode=cv2.STEREO_SGBM_MODE_SGBM_3WAY
)

right_matcher = cv2.ximgproc.createRightMatcher(left_matcher)

# FILTER Parameters
lmbda = 80000
sigma = 1.2
visual_multiplier = 1.0

wls_filter = cv2.ximgproc.createDisparityWLSFilter(matcher_left=left_matcher)
wls_filter.setLambda(lmbda)
wls_filter.setSigmaColor(sigma)

camOne = cv2.VideoCapture(cv2.CAP_FIREWIRE + 0)
camTwo = cv2.VideoCapture(cv2.CAP_FIREWIRE + 1) 

while(True):
    # Capture frame-by-frame
    retOne, frameOne = camOne.read()
    retTwo, frameTwo = camTwo.read()

    # Display the resulting frame
    print('computing disparity...')
    displ = left_matcher.compute(frameOne, frameTwo)  # .astype(np.float32)/16
    dispr = right_matcher.compute(frameTwo, frameOne)  # .astype(np.float32)/16
    displ = np.int16(displ)
    dispr = np.int16(dispr)
    filteredImg = wls_filter.filter(displ, frameOne, None, dispr)  # important to put "frameOne" here!!!
    filteredImg = cv2.normalize(src=filteredImg, dst=filteredImg, beta=0, alpha=255, norm_type=cv2.NORM_MINMAX);
    filteredImg = np.uint8(filteredImg)
    cv2.imshow('Disparity Map', filteredImg)

cv2.waitKey()
cv2.destroyAllWindows()

which does not work, throwing an error as:

Traceback (most recent call last):
  File "camera.py", line 43, in <module>
    displ = left_matcher.compute(frameOne, frameTwo)  # .astype(np.float32)/16
cv2.error: OpenCV(3.4.3) /io/opencv/modules/core/src/parallel.cpp:240: error: (-2:Unspecified error) in function 'finalize'
> Exception in parallel_for() body: OpenCV(3.4.3) /io/opencv/modules/core/src/matrix.cpp:669: error: (-215:Assertion failed) nelems <= size_t(INT_MAX)*size_t(INT_MAX) in function 'reserveBuffer'

howver, I strongly suspect that cameras aren't even opening. Does anyone know how to make firewire cameras work with OpenCV?

OpenCV 3 + Python 3 + Firewire Cameras

I am trying to activate my 2 firewire cameras plugged in to build a depth image from them, but I cannot seem to activate even one:

    import numpy as np
from sklearn.preprocessing import normalize
import cv2

    # SGBM Parameters -----------------
    window_size = 3                     # wsize default 3; 5; 7 for SGBM reduced size image; 15 for SGBM full size image (1300px and above); 5 Works nicely

left_matcher = cv2.StereoSGBM_create(
    minDisparity=0,


 numDisparities=160,             # max_disp has to be dividable by 16 f. E. HH 192, 256
    blockSize=5,
    P1=8 * 3 * window_size ** 2,    # wsize default 3; 5; 7 for SGBM reduced size image; 15 for SGBM full size image (1300px and above); 5 Works nicely
    P2=32 * 3 * window_size ** 2,
    disp12MaxDiff=1,
    uniquenessRatio=15,
    speckleWindowSize=0,
    speckleRange=2,
    preFilterCap=63,

    mode=cv2.STEREO_SGBM_MODE_SGBM_3WAY
)

right_matcher = cv2.ximgproc.createRightMatcher(left_matcher)

# FILTER Parameters
lmbda = 80000
sigma = 1.2
visual_multiplier = 1.0

wls_filter = cv2.ximgproc.createDisparityWLSFilter(matcher_left=left_matcher)
wls_filter.setLambda(lmbda)
wls_filter.setSigmaColor(sigma)

camOne = cv2.VideoCapture(cv2.CAP_FIREWIRE + 0)
camTwo = cv2.VideoCapture(cv2.CAP_FIREWIRE + 1) 

while(True):
    # Capture frame-by-frame
    retOne, frameOne = camOne.read()
    retTwo, frameTwo = camTwo.read()

    # Display the resulting frame
    print('computing disparity...')
    displ = left_matcher.compute(frameOne, frameTwo)  # .astype(np.float32)/16
    dispr = right_matcher.compute(frameTwo, frameOne)  # .astype(np.float32)/16
    displ = np.int16(displ)
    dispr = np.int16(dispr)
    filteredImg = wls_filter.filter(displ, frameOne, None, dispr)  # important to put "frameOne" here!!!
    filteredImg = cv2.normalize(src=filteredImg, dst=filteredImg, beta=0, alpha=255, norm_type=cv2.NORM_MINMAX);
    filteredImg = np.uint8(filteredImg)
    cv2.imshow('Disparity Map', filteredImg)

cv2.waitKey()
cv2.destroyAllWindows()

which does not work, throwing an error as:

Traceback (most recent call last):
  File "camera.py", line 43, in <module>
    displ = left_matcher.compute(frameOne, frameTwo)  # .astype(np.float32)/16
cv2.error: OpenCV(3.4.3) /io/opencv/modules/core/src/parallel.cpp:240: error: (-2:Unspecified error) in function 'finalize'
> Exception in parallel_for() body: OpenCV(3.4.3) /io/opencv/modules/core/src/matrix.cpp:669: error: (-215:Assertion failed) nelems <= size_t(INT_MAX)*size_t(INT_MAX) in function 'reserveBuffer'

howver, however, I strongly suspect that cameras aren't even opening. Does anyone know how to make firewire cameras work with OpenCV?