OpenCV 3 + Python 3 + Firewire Cameras

asked 2018-11-14 04:53:18 -0500

Raki gravatar image

updated 2018-11-14 04:57:07 -0500

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'

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

edit retag flag offensive close merge delete

Comments

Did you try to debug the application? I think you can test more easily than us if the cameras are open and the frames are read...

E.g. check camOne.isOpened() and camTwo.isOpened()? frameOne.size? imshow("Left camera",frameOne) and so on...?

kbarni gravatar imagekbarni ( 2018-11-14 05:08:33 -0500 )edit

They return false, but that's the thing, I don't know if I use the proper OpenCV commands to get frames from a firewire camera. Like, is this even correct camOne = cv2.VideoCapture(cv2.CAP_FIREWIRE + 0) ?

Raki gravatar imageRaki ( 2018-11-14 05:17:15 -0500 )edit

please check cv2.getBuildInformation() (there's a VideoIO section)

ifyou installed cv2 via pip, or some other ppm, it's unlikely, that it has firewire support builtin

(you need to build from src, with the resp. sdk / dev packages installed)

berak gravatar imageberak ( 2018-11-14 05:56:42 -0500 )edit

Oh my... Why are such things not coming with pip or ros, now one needs to do everything from the scratch... Anyway, thanks for the information.

Raki gravatar imageRaki ( 2018-11-14 06:26:39 -0500 )edit

ittnotify libprotobuf libwebp libpng libtiff libjasper IlmImf\n\n OpenCV modules:\n To be built: aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dpm face features2d flann fuzzy hfs highgui img_hash imgcodecs imgproc java_bindings_generator line_descriptor ml objdetect optflow phase_unwrapping photo plot python3 python_bindings_generator reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab xfeatures2d ximgproc xobjdetect xphoto\n

here is the section related, I guess (at the end I see video related stuff)

Raki gravatar imageRaki ( 2018-11-14 06:34:44 -0500 )edit

it's an external dependancy, even if skvark builds it in, it might no more work on a box, which does not have it

berak gravatar imageberak ( 2018-11-14 06:34:46 -0500 )edit

imho, its this:

Video I/O:
  DC1394:                      NO
berak gravatar imageberak ( 2018-11-14 06:37:20 -0500 )edit

Ah yes, I have that DC1394: NO\n there too, now I saw. So okay this means it's not built, and one needs to install opencv from the source. Thanks

Raki gravatar imageRaki ( 2018-11-14 06:42:37 -0500 )edit