OpenCV::solvePNP() - Assertion failed

后端 未结 3 1763
臣服心动
臣服心动 2021-01-16 01:28

I am trying to get the pose of the camera with the help of solvePNP() from OpenCV.

After running my program I get the following errors:

OpenCV Error:         


        
3条回答
  •  失恋的感觉
    2021-01-16 01:49

    The types don't seem right, at least in the code that worked for me I used different types(as mentioned in the documentation).

    objectPoints – Array of object points in the object coordinate space, 3xN/Nx3 1-channel or 1xN/Nx1 3-channel, where N is the number of points. vector can be also passed here.

    imagePoints – Array of corresponding image points, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel, where N is the number of points. vector can be also passed here.

    cameraMatrix – Input camera matrix A = \vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1} .

    distCoeffs – Input vector of distortion coefficients (k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6]]) of 4, 5, or 8 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed.

    rvec – Output rotation vector (see Rodrigues() ) that, together with tvec , brings points from the model coordinate system to the camera coordinate system.

    tvec – Output translation vector.

    useExtrinsicGuess – If true (1), the function uses the provided rvec and tvec values as initial approximations of the rotation and translation vectors, respectively, and further optimizes them.

    Documentation from here.

    vector rvec, tvec should be Mat rvec, tvec instead.

    vector > imagePoints(1) should be vector imagePoints(1) instead.

    vector > boardPoints(1) should be vector boardPoints(1) instead.

    Note: I encountered the exact same problem, and this worked for me(It is a little bit confusing since calibrateCamera use vectors). Haven't tried it for imagePoints or boardPoints though.(but as it is documented in the link above, vector,vector should work, I thought I'd better mention it), but for rvec,trec I tried it myself.

提交回复
热议问题