OpenCVForUnity icon indicating copy to clipboard operation
OpenCVForUnity copied to clipboard

I can not use solvePnP in Calib3d

Open kyaohoh opened this issue 3 years ago • 2 comments

Hi there,

I've been trying to use the below function.

public static bool solvePnP(MatOfPoint3f objectPoints, MatOfPoint2f imagePoints, Mat cameraMatrix, MatOfDouble distCoeffs, Mat rvec, Mat tvec, bool useExtrinsicGuess, int flags)

I thought that it would work, but I keep getting rvec, tvec only as 0, 0, 0.

I tried adding the "ref" keyword in front of rvec and tvec but it didn't work.

Could you tell me how to get the values?

Thank you, Kyaohoh.

kyaohoh avatar Sep 06 '22 03:09 kyaohoh

Perhaps there is some error on the opencv side. Enclose the point where the error occurs in Utils.setDebugMode() method, and the error on the C++ side will be displayed on the console.

Utils.setDebugMode (true);

solvePnP(MatOfPoint3f objectPoints, MatOfPoint2f imagePoints, Mat cameraMatrix, MatOfDouble distCoeffs, Mat rvec, Mat tvec, bool useExtrinsicGuess, int flags)

Utils.setDebugMode (false);

EnoxSoftware avatar Sep 06 '22 10:09 EnoxSoftware

Thank you for sharing debugging info. I found that I made a mistake when setting cameraMatrix.

I have one more question. Now solvePnP function is working, but not well. It looks like the axis settings are wrong. To fix it, I'm going to do a multiplication operation of the below matrix. (similar to invertYM 4x4 mat you used in sample unity code) 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0

Do you think it will work?

kyaohoh avatar Sep 19 '22 04:09 kyaohoh