EnoxSoftware / OpenCVForUnity

OpenCV for Unity (Untiy Asset Plugin)
https://assetstore.unity.com/packages/tools/integration/opencv-for-unity-21088
550 stars 172 forks source link

I can not use solvePnP in Calib3d #150

Open kyaohoh opened 1 year ago

kyaohoh commented 1 year ago

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.

EnoxSoftware commented 1 year ago

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);
kyaohoh commented 1 year ago

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?