dynamic
dynamic

Reputation: 48101

MLESAC isntead of RANSAC with OpenCV

Is there any available code to use MLESAC instead of RANSAC with OpenCV to find a known object?

MLESAC should be much more robust than RANSAC. An example of use is provided here:

http://docs.opencv.org/doc/tutorials/features2d/feature_homography/feature_homography.html

enter image description here

Upvotes: 3

Views: 2520

Answers (1)

old-ufo
old-ufo

Reputation: 2850

You can use MLESAC (as well as PROSAC, etc.) from the PCL library. http://docs.pointclouds.org/trunk/a02954.html I don`t use PCL, so could not make an example.

I`m using LO-RANSAC from Karel Lebeda http://cmp.felk.cvut.cz/software/LO-RANSAC/index.xhtml

int do_lo = 1; //local optimization
unsigned int tent_size = tentatives.size();
double err_threshold = 2.0; //in pixels
double confidence = 0.99;
int max_samples = 100000;//max trials
int inl_limit = 0;//no limit
if (tent_size >= 5)
{
  double H[3*3];
  unsigned stats[3];
  double *u2Ptr = new double[tent_size*6], *u2; u2=u2Ptr;
  typedef unsigned char uchar;
  unsigned char *inl2 = new uchar[tent_size];

  for( int i = 0; i < tentatives.size(); i++ )
    {
      *u2Ptr =  keypoints_object[ tentatives[i].queryIdx ].pt.x;
      u2Ptr++;

      *u2Ptr =  keypoints_object[ tentatives[i].queryIdx ].pt.y;
      u2Ptr++;
      *u2Ptr =  1.;
      u2Ptr++;

      *u2Ptr =   keypoints_scene[ tentatives[i].trainIdx ].pt.x;
      u2Ptr++;

      *u2Ptr =   keypoints_scene[ tentatives[i].trainIdx ].pt.y;
      u2Ptr++;
      *u2Ptr =  1.;
      u2Ptr++;
    }
  ransacH(u2, tent_size, err_threshold*err_threshold, confidence, max_samples, do_lo, , H, inl2,stats);
  for(i=0; i < tent_size; i++)
    if (inl2[i])
      inliers.push_back(good_matches[i]);

  delete[] u2; delete[] inl2;

Upvotes: 3

Related Questions