1) Context
I'm using EmguCV's plugin for Unity, in order to call openCV functions from within my C# code. More precisely I need to call the SolvePnPRansac method.
Here is the documentation for the method SolvePnPRansac and the expected arguments:
http://www.emgu.com/wiki/files/3.1.0/document/html/36ff5d6b-498a-0587-5350-370bdecf64d7.htm
2) Problem:
The method call crashes the unity editor itself, leaving no exceptions, no stack trace, because the plugin crashes internally and unity doesn't seem to be able to handle it, despite my try-catch block.
from the logs that unity stores persistently, this is what I get, which clearly suggests a type mismatch:
Stacktrace: at (wrapper managed-to-native) Emgu.CV.CvInvoke.cveSolvePnPRansac (intptr,intptr,intptr,intptr,intptr,intptr,bool,int,single,double,intptr,Emgu.CV.CvEnum.SolvePnpMethod) at (wrapper managed-to-native) Emgu.CV.CvInvoke.cveSolvePnPRansac (intptr,intptr,intptr,intptr,intptr,intptr,bool,int,single,double,intptr,Emgu.CV.CvEnum.SolvePnpMethod) at Emgu.CV.CvInvoke.SolvePnPRansac (Emgu.CV.IInputArray,Emgu.CV.IInputArray,Emgu.CV.IInputArray,Emgu.CV.IInputArray,Emgu.CV.IOutputArray,Emgu.CV.IOutputArray,bool,int,single,double,Emgu.CV.IOutputArray,Emgu.CV.CvEnum.SolvePnpMethod) [0x00090] in /Users/user/Documents/dgunity-v2/Assets/Emgu.CV/Emgu.CV/PInvoke/CvInvokeCalib3d.cs:659 at ObjectLocalization.LocalToCameraMatrixFromPnP ...
3) What I tried :
I can successfully run:
CvInvoke.SolvePnP(objectPoints, imagePoints, cameraMatrix, distortionCoeffs, rvec, tvec, useIntrinsicGuess);
where
- objectPoints is of type Emgu.CV.Util.VectorOfPoint3D32F
- imagePoints is of type Emgu.CV.Util.VectorOfPointF
- cameraMatrix is 3X3 of type Emgu.CV.Matrix
- distortionCoeffs is 1X4 of type Emgu.CV.Util.VectorOfFloat
- rvec and tvec are of type Emgu.CV.Util.VectorOfFloat
- and useIntrinsicGuess is type bool
4) What doesn't work
now I try:
CvInvoke.SolvePnPRansac(ransacObjPoints, ransacImgPoints, cameraMatrix, distortionCoeffs, rvec, tvec, useIntrinsicGuess, iterationsCount, reprojectionError, confident, inliers, Emgu.CV.CvEnum.SolvePnpMethod.Iterative);
where
- iterationsCount is 100 of type int
- reprojectionError is 8f of type float
- confident is 0.99 of type double
- inliers is empty of type Emgu.CV.Util.VectorOfInt
It just crashes the unity editor. What am I doing wrong?