1

I'm using opencv-contrib-python (4.5.4.60) to calibrate stereovision emulated by 2 pictures taken with one camera (for now I only have one of them) like there are two cameras for stereo depth estimation in future. I find intrinsic parameters of camera from several photos and trying to pass ChAruCo markers points from two photos into stereoCalibrate, but get assertion failed:

ret, M1, d1, M2, d2, R, T, E, F = cv2.stereoCalibrate(objpoints_L, imgpoints_L, imgpoints_R, camera_matrix, distortion_coefficients0, camera_matrix, distortion_coefficients0,img_r1.shape[:2], F = F)
cv2.error: OpenCV(4.5.4) D:\a\opencv-python\opencv-python\opencv\modules\calib3d\src\calibration.cpp:1088: error: (-215:Assertion failed) (count >= 4) || (count == 3 && useExtrinsicGuess) in function 'cvFindExtrinsicCameraParams2'

I have checked input type of object points and image points with cv2.utils.dumpInputArray()

InputArray: empty()=false kind=0x00010000 flags=0x01010000 total(-1)=40 dims(-1)=2 size(-1)=1x40 type(-1)=CV_32FC3
InputArray: empty()=false kind=0x00010000 flags=0x01010000 total(-1)=40 dims(-1)=2 size(-1)=1x40 type(-1)=CV_32FC2
InputArray: empty()=false kind=0x00010000 flags=0x01010000 total(-1)=40 dims(-1)=2 size(-1)=1x40 type(-1)=CV_32FC2

sorted them so I pass only matching on both photos, but still get assertion failed and can't figure out what I'm doing wrong.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • wrong shape, possibly. reshape to `(-1, 1, 2)` or `(-1, 1, 3)` – Christoph Rackwitz Dec 30 '21 at 12:23
  • @ChristophRackwitz the shape of points I pass is (n,1,3) for object and (n,1,2) for image. If I try to reshape it, for example, with```objpoints_L = np.reshape(objpoints_L, (objpoints_L.shape[0], objpoints_L.shape[2]))``` to (n,3) I get another assertion fail: ```error: (-210:Unsupported format or combination of formats) objectPoints should contain vector of vectors of points of type Point3f in function 'cv::collectCalibrationData'```, that is called before the stated issue. Is that the shape you suggest? – Vladislav D Dec 30 '21 at 13:47
  • I'm not sure how to read output of `dumpInputArray`, but `size(-1)=1x40` suggests it's a row vector, not a column vector. either *should* be accepted by opencv in that instance. what is the `.shape` of the numpy array? – Christoph Rackwitz Dec 30 '21 at 16:30
  • oh and `stereoCalibrate` needs *lists* of arrays. each array describes one object/view, and the list contains all objects or all views. please look up other questions on `stereoCalibrate` that show its usage. – Christoph Rackwitz Dec 30 '21 at 16:32
  • @ChristophRackwitz The problem was that ChAruCo markers are returned as array of objects with single point. Everything is good until you try to pass them into `cv2.stereoCalibrate`, which checks for every object to have more then 3 points. I reshaped array to single object with ChAruCo points (1,n,2) and (1,n,3) and it worked. Still didn't understand how to use results fro rectification but it's another question. Thanks. – Vladislav D Jan 11 '22 at 09:15

1 Answers1

0

The problem was that ChAruCo markers are returned as array of objects with single point (n, 1, 2) by cv2.aruco.detectMarkers. Functions accept this points format (for example cv2.solvePnP or cv2.findFundamentalMat) but if you try to pass them into cv2.stereoCalibrate, which checks for every object to have more then 3 points but get n objects with single point instead, you would get assertion failed. To use this points you have to reshape array to single object with all ChAruCo points (1,n,2). Do the same reshape to (1, n, 3) to object points obtained by cv2.aruco.getBoardObjectAndImagePoints.