Issue with cv2.fiseye.calibrate :fisheye.cpp:742: error: (-215:Assertion failed) objectPoints.type() == CV_32FC3 || objectPoints.type() == CV_64FC3 in function 'calibrate'

Hi All,

being new to Python and openCV I struggle with the following problem: When calling the cv2.fisheye.calibrate function in the following code:


def determine_extrinsics_camera(world_points,ref_proj,K,dist,gray,Fisheye,DIM):
    imgpoints=np.zeros((1,world_points.shape[1],2),np.float32)
    imgpoints2=copy(imgpoints)
    vv=np.zeros([1,3])
    R_tot=np.zeros((3,3),np.float32)
    R_inv=np.zeros((3,3),np.float32)
    uv_raw=np.zeros((imgpoints.shape[0],imgpoints.shape[1],imgpoints.shape[2]),np.float32)
    rvecs = [np.zeros((1, 1, 3), dtype=np.float64) for i in range(imgpoints.shape[1])]
    tvecs = [np.zeros((1, 1, 3), dtype=np.float64) for i in range(imgpoints.shape[1])]
    print(imgpoints.shape[1])
    for i in range(0,(imgpoints.shape[1]),1):
        uv_raw[0][i][0]=ref_proj[i][0]
        uv_raw[0][i][1]=ref_proj[i][1]
        if not Fisheye:
            uitkomst=cv2.undistortPoints(uv_raw,K,dist)
            vv[0][:]=((uitkomst[i][0][0],uitkomst[i][0][1],1))
        else:
            newcameramtx = cv2.fisheye.estimateNewCameraMatrixForUndistortRectify(
            K, dist, DIM, None, balance=1)
            uitkomst=cv2.fisheye.undistortPoints(uv_raw,K,dist,None,newcameramtx)
            vv[0][:]=((uitkomst[0][i][0],uitkomst[0][i][1],1))
        img_undist=np.matmul(K,np.transpose(vv))
        imgpoints2[0][i][0]=img_undist[0][0]
        imgpoints2[0][i][1]=img_undist[1][0]

    imgpoints=copy(uv_raw)
    if not Fisheye:
        vlag, _, _, rvecs,tvecs = \
        cv2.calibrateCamera
        (world_points,imgpoints2,
        gray.shape[::-1], 
        K,
       None,
       rvecs,
       tvecs,flags=(cv2.CALIB_USE_INTRINSIC_GUESS))
    else:
        calibration_flags = \
        cv2.fisheye.CALIB_RECOMPUTE_EXTRINSIC+cv2.fisheye.CALIB_CHECK_COND
        vlag,_,_,rvecs,tvecs=cv2.fisheye.calibrate(world_points,imgpoints2,gray.shape[::-1],K,None,rvecs,tvecs,calibration_flags,(cv2.TERM_CRITERIA_EPS+cv2.TERM_CRITERIA_MAX_ITER, 30, 1e-6))

On the call cv2.fisheye.calibrate I get the following error message:

fisheye.cpp:742: error: (-215:Assertion failed) objectPoints.type() == CV_32FC3 || objectPoints.type() == CV_64FC3 in function ‘calibrate’

When not using the fisheye calibration but the ‘normal’ camera function(so the call cv2.calibrateCamera) everything works fine.

I’m working on macOS 12.2.1, python 3.10.3 with cv version 4.5.5

Any ideas, suggestions are welcome!

Thanks in advance

what’s the dtype and shape of that?

sorry I wasn’t finished yet, a bit struggling with the navigation…

The world_points are defined as:

world_points=np.zeros((1,10,3),np.float32)

if you have

then this assertion couldn’t have failed because that shape and dtype satisfies the assertion.

please check .shape and .dtype directly before the calibrate call.

Hi,

I did so, the result is
tye=numpy.ndarray (with dtype =float32) with shape (1,10,3), so I would expect this to work??? Not sure how to proceed…
kind regards

Francois

I’m out of ideas too. puzzling.

please prepare a “minimal reproducible example”. simplify the code. pack all required data into the code.

I ma experiencing the same issue. Did you find a solution to your issue?

I encountered a similar problem, and found this page helpful.

it says:

objpoints has to be resized in python from (<num points in set>, 3) to (<num points in set>, 1, 3) to pass the objectPoints.type() == CV_64FC3 check