在Unity dll中使用OpenCV中的matcher.match时,为什么会出现运行时错误?

在Unity dll中使用OpenCV中的matcher.match时,为什么会出现运行时错误?,opencv,unity3d,runtime-error,Opencv,Unity3d,Runtime Error,我使用OpenCV从Unity应用程序的框架中获取数据。 我制作了一个dll,它在大多数情况下都可以正常工作,但是当我想研究两个帧之间的匹配时,我得到了一个运行时错误 我使用了下面的代码: C++中使用OpenCV库的: int* Correction3DMasks(Color32* raw, int width, int height, Color32* VirtualCamRaw, int VirtualCamwidth, int VirtualCamheight, int minimalL

我使用OpenCV从Unity应用程序的框架中获取数据。 我制作了一个dll,它在大多数情况下都可以正常工作,但是当我想研究两个帧之间的匹配时,我得到了一个运行时错误

我使用了下面的代码:

C++中使用OpenCV库的

int* Correction3DMasks(Color32* raw, int width, int height, Color32* VirtualCamRaw, int VirtualCamwidth, int VirtualCamheight, int minimalLength, int MaxiLineGap)
{    
      int minHessian = 20;

  FastFeatureDetector  detector( minHessian );

  std::vector<KeyPoint> keypoints_1, keypoints_2;


    RealCamFeed = Mat(height, width, CV_8UC4, raw);
    VirtualCamFeed = Mat(VirtualCamheight, VirtualCamwidth, CV_8UC4, VirtualCamRaw);



    Canny(RealCamFeed, RealCamFeed, 200, 200, 3);
    cvtColor(RealCamFeed, RealCdst, CV_GRAY2BGR);

    Canny(VirtualCamFeed, VirtualCamFeed, 200, 200, 3);
    cvtColor(VirtualCamFeed, VirtualCdst, CV_GRAY2BGR);

  //-- Step 1: Detect the keypoints using SURF Detector

  detector.detect( RealCamFeed, keypoints_1 );
  detector.detect( VirtualCamFeed, keypoints_2 );

  //-- Draw keypoints
  Mat img_keypoints_1; Mat img_keypoints_2;

  cv::drawKeypoints( RealCamFeed, keypoints_1, img_keypoints_1, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
  drawKeypoints( VirtualCamFeed, keypoints_2, img_keypoints_2, Scalar::all(-1), DrawMatchesFlags::DEFAULT );

  //-- Show detected (drawn) keypoints
  imshow("Keypoints 1", img_keypoints_1 );
  imshow("Keypoints 2", img_keypoints_2 );

       //-- Step 2: Calculate descriptors (feature vectors)
     SurfDescriptorExtractor extractor;

          Mat descriptors_object, descriptors_scene;

  extractor.compute( RealCamFeed, keypoints_1, descriptors_object );
  extractor.compute( VirtualCamFeed, keypoints_2, descriptors_scene );

    //-- Step 3: Matching descriptor vectors using FLANN matcher
   FlannBasedMatcher matcher (new flann::LshIndexParams(20, 10, 2));
  std::vector< DMatch > matches;

  matcher.match(descriptors_object, descriptors_scene, matches);




  //-- Localize the object
  std::vector<Point2f> obj;
  std::vector<Point2f> scene;

  for( int i = 0; i < matches.size(); i++ )
  {
    //-- Get the keypoints from the good matches
    obj.push_back( keypoints_1[ matches[i].queryIdx ].pt );
    scene.push_back( keypoints_2[ matches[i].trainIdx ].pt );
  } 

  if(matches.size() > 0)
  Mat H = findHomography( obj, scene, CV_RANSAC );

   //deal with H to put it in res

       return res; 
}
int*Correction3DMasks(Color32*raw、int-width、int-height、Color32*VirtualCamRaw、int-VirtualCamwidth、int-VirtualCamheight、int-minimalength、int-MaxiLineGap)
{    
int minHessian=20;
FastFeatureDetector检测器(minHessian);
std::向量关键点1,关键点2;
RealCamFeed=垫(高度、宽度、CV_8UC4、原始);
VirtualCamFeed=Mat(VirtualCamheight、VirtualCamwidth、CV_8UC4、VirtualCamRaw);
Canny(RealCamFeed,RealCamFeed,200200,3);
CVT颜色(RealCamFeed、RealCdst、CV_GRAY2BGR);
Canny(VirtualCamFeed,VirtualCamFeed,200200,3);
cvtColor(VirtualCamFeed、VirtualCdst、CV_GRAY2BGR);
//--步骤1:使用SURF检测器检测关键点
检测器。检测(RealCamFeed,关键点1);
检测器。检测(VirtualCamFeed,关键点2);
//--画关键点
Mat img_关键点_1;Mat img_关键点_2;
cv::drawKeypoints(RealCamFeed、keypoints_1、img_keypoints_1、Scalar::all(-1)、DrawMatchesFlags::DEFAULT);
drawKeypoints(VirtualCamFeed、keypoints_2、img_keypoints_2、Scalar::all(-1)、DrawMatchesFlags::DEFAULT);
//--显示检测(绘制)的关键点
imshow(“关键点1”,img_关键点1);
imshow(“关键点2”,img_关键点2);
//--步骤2:计算描述符(特征向量)
表面描述符牵引器;
Mat描述符\u对象,描述符\u场景;
compute(RealCamFeed、keypoints\u 1、描述符\u对象);
计算(VirtualCamFeed、关键点、描述符、场景);
//--步骤3:使用FLANN匹配器匹配描述符向量
FlannBasedMatcher匹配器(新的flann::lshindeParams(20,10,2));
标准::向量匹配;
匹配(描述符\对象、描述符\场景、匹配);
//--定位对象
std::向量obj;
矢量场景;
for(int i=0;i0)
Mat H=findHomography(obj、场景、CV_RANSAC);
//处理H以将其放入res
返回res;
}
此函数仅从两个彼此位置相近的摄影机的渲染纹理的统一中调用。 我试着调试这件事,似乎行
matcher.match(descriptors\u object,descriptors\u scene,matches)是错误的原因

错误是:

微软Visual C++运行库< /P> 运行时错误

节目:

此应用程序已请求运行时在 不寻常的方式。请联系应用程序的支持团队以了解更多信息 信息

我希望我足够清楚。 非常感谢您的帮助

我添加了“imshow”指令运行并显示关键点。我添加了“imshow”指令运行并显示关键点。