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

时间:2017-11-28 11:28:09

标签: opencv unity3d runtime-error

我正在使用OpenCV从Unity应用程序中取回帧中的数据。 我做了一个dll,它适用于大多数事情但是当我想研究两帧之间的匹配时,我得到一个运行时错误。

我使用了以下代码:

在使用OpenCV库的c ++中:

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; 
}

这个功能简单地从Unity调用,两个相机的渲染纹理相互靠近。 我尝试调试这个东西,似乎行matcher.match(descriptors_object, descriptors_scene, matches);是导致错误的原因。

错误是:

  

Microsoft Visual c + +运行时库

     

运行时错误!

     

程序:

     

此应用程序已请求运行时将其终止   不寻常的方式请联系应用程序的支持团队获取更多信息   信息。

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

0 个答案:

没有答案