Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# EmguCV中的solvePnPRansac期望什么参数类型(显式,而不是接口)?_C#_Opencv_Unity3d_Emgucv - Fatal编程技术网

C# EmguCV中的solvePnPRansac期望什么参数类型(显式,而不是接口)?

C# EmguCV中的solvePnPRansac期望什么参数类型(显式,而不是接口)?,c#,opencv,unity3d,emgucv,C#,Opencv,Unity3d,Emgucv,1) 上下文 我正在使用EmguCV的Unity插件,以便从我的C#代码中调用openCV函数。更准确地说,我需要调用SolvePnPRansac方法 以下是SolvePnPRansac方法和预期参数的文档: 2) 问题: 方法调用使unity编辑器本身崩溃,没有留下任何异常,没有堆栈跟踪,因为插件在内部崩溃,unity似乎无法处理它,尽管我使用了try-catch块 从unity持久存储的日志中,我得到了以下信息,这清楚地表明了类型不匹配: 堆栈跟踪: at(包装器管理为本机)Emgu.CV

1) 上下文

我正在使用EmguCV的Unity插件,以便从我的C#代码中调用openCV函数。更准确地说,我需要调用SolvePnPRansac方法

以下是SolvePnPRansac方法和预期参数的文档:

2) 问题:

方法调用使unity编辑器本身崩溃,没有留下任何异常,没有堆栈跟踪,因为插件在内部崩溃,unity似乎无法处理它,尽管我使用了try-catch块

从unity持久存储的日志中,我得到了以下信息,这清楚地表明了类型不匹配:

堆栈跟踪: at(包装器管理为本机)Emgu.CV.CvInvoke.cveSolvePnPRansac(intptr、intptr、intptr、intptr、intptr、bool、int、single、double、intptr、Emgu.CV.CvEnum.SolvePnpMethod) at(包装器管理为本机)Emgu.CV.CvInvoke.cveSolvePnPRansac(intptr、intptr、intptr、intptr、intptr、bool、int、single、double、intptr、Emgu.CV.CvEnum.SolvePnpMethod) 在Emgu.CV.CvInvoke.SolvePnPRansac(Emgu.CV.IInputArray、Emgu.CV.IInputArray、Emgu.CV.IInputArray、Emgu.CV.IOutputArray、Emgu.CV.IOutputArray、bool、int、single、double、Emgu.CV.CV.IOutputArray、Emgu.CvEnum.solvepnmethod)[0x00090]in/Users/user/Documents/dguy-v2/Assets/Emgu.CV/Emgu/Emgu/Emgu/Emgu.CV/libpinvoke/invokecacs:659中 在ObjectLocalization.LocalToCameraTrixFrompnp

3) 我尝试的是:

我可以成功运行:

        CvInvoke.SolvePnP(objectPoints, imagePoints, cameraMatrix, distortionCoeffs, rvec, tvec, useIntrinsicGuess);
在哪里

  • objectPoints的类型为Emgu.CV.Util.VectorOfPoint3D32F
  • imagePoints的类型为Emgu.CV.Util.VectorOfPointF
  • cameraMatrix是Emgu.CV.Matrix类型的3X3
  • 扭曲效应是Emgu.CV.Util.VectorOffload类型的1X4
  • rvec和tvec属于Emgu.CV.Util.VectorOffload类型
  • 而useIntrinsicGuess是bool类型
4) 什么不起作用

现在我试着:

CvInvoke.SolvePnPRansac(ransacObjPoints, ransacImgPoints, cameraMatrix, distortionCoeffs, rvec, tvec, useIntrinsicGuess, iterationsCount, reprojectionError, confident, inliers, Emgu.CV.CvEnum.SolvePnpMethod.Iterative);
在哪里

  • IterationCount是int类型的100
  • 重射器为8f型浮子
  • 自信是0.99的双精度类型
  • Inliner为空,类型为Emgu.CV.Util.VectorOfInt
它只是使unity编辑器崩溃。
我做错了什么?

在经历了无数个小时的挫折之后,我在这里回答了自己的问题:EmguCV期望Mat类型的参数。句号

它公开了接口类型iInputArray和iOutputArray的方法参数,但实现这些接口的某些类实际上只能在某些方法中的某些组合中处理

因此,安全的方法就是忘记实现所述接口的其他类,而只选择Mat类型;所以使用

  • Emgu.CV.Util.VectorOfPoint3D32F类型的objectPoints
  • Emgu.CV.Util.VectorOfPointF类型的图像点
  • cameraMatrix 3X3型垫
  • MAT型变形效应1X 5
  • MAT型rvec和tvec
  • 并使用intrinsicguess类型bool
  • int类型的迭代计数100
  • 浮子型重射器8f
  • 双精度0.99
  • MAT型进气口
要在mat类型的实例中获取或设置值,必须将它们转换为图像或矩阵。我使用CopyTo和SetTo方法通过Cv.Matrix类型的实例将值从Mat中取出并放入Mat中。请注意,只有SetTo(双[])对我有效。来自输入阵列的数据没有得到正确处理(如果你给它一个MAT,它可能会得到,但不是我尝试使用的iInputArray的那些实现)