PROSAC for OpenCV (2)

I made some changes to my code from last time. I won’t repost the whole thing, just snippets.

I removed typedef uint int and changed all uint to int, since the OpenCV coding standard seems not to be finicky about using unsigned ints.

In preparation for integrating into OpenCV (3.0), while retaining the ability to test standalone, I defined a macro for random integers:

#ifdef STANDALONE
// for testing outside opencv
#include <stdlib.h> // rand()
#include <math.h> // ceil()
#define rand_uint_less_than(limit) rand()%limit
#else
// for use inside opencv
#define rand_uint_less_than(limit) cvRandInt(&rng) % limit
#endif

In order to easily switch back and forth between PROSAC and RANSAC for comparative testing, I moved the contents of the constructor to an initPROSAC() method, and created a separate initRANSAC() method. All the initRANSAC() method does is set poolmax=N-1; which causes the preexisting randomSample() method to behave in a RANSAC way (i.e. sample m from the entire pool). The new constructor is empty. Perhaps a better pattern would be to have a SacHelper base class with the randomSample() method, and derive RansacHelper and ProsacHelper each with their specific constructors. Maybe I’ll do that at some point.

My test driver was updated to exercise both capabilities, like this:

ProsacHelper pro_or_ran;
#define EM 4
uint sample[EM];
for (int which=0; which<2; ++which) {
  switch(which) {
   case 0: pro_or_ran.initRANSAC(EM,100); break;
   case 1: pro_or_ran.initPROSAC(EM,100); break; }
 
  for (int it=0; it<100; ++it) {
 
    for (int mi=0; mi<EM; ++mi)
      sample[mi] = pro_or_ran.randomSample();
      cout << it << ":";
      for (int mi=0; mi<EM; ++mi)
        cout << " " << sample[mi];
      cout << endl;
    }
  }
}

And output looks something like this:

 0: 83 86 77 15
 1: 93 35 86 92
 2: 49 21 62 27
 3: 90 59 63 26
 4: 40 26 72 36
 5: 11 68 67 29
 ...
 0: 0 1 2 3
 1: 3 1 0 4
 2: 0 4 2 5
 3: 0 2 3 6
 4: 2 0 5 6
 5: 5 4 6 7
 6: 2 6 3 7
 7: 5 4 6 8
 8: 5 0 4 8
 9: 7 4 5 8
 10: 0 4 3 9
 ...

I have cloned the git repository of OpenCV (3.0) and the opencv_extra with testdata, “cmake . ; make” was sufficient to build perfectly first time, and the unit test suites opencv_test_features2d and opencv_test_calib3d are passing. Next post I hope to show first results of slapping this class into the calib3d source code, into RANSACPointSetRegistrator::getSubset() in function modules/calib3d/src/ptsetreg.cpp. This class is used to conduct RANSAC for cv::findHomography() and cv::findFundamentalMatrix(). Hopefully I can slap my ProsacHelper in and not break the test suite.

Advertisements

8 Responses

  1. hello , can you help me please, about, Prosac algorithm, I need to implement it with two images, in C ++ language.

  2. Hi, I kind of dropped this project that I started, but I think I understand the principle of PROSAC (and I’ve coded RANSAC before) and might be able to help. Do you have a specific question?

    • YEAH, I have two images I want to apply Prosac in them, but, I applied ORB in each one, I have the characteristic points of them, I do not know how to continue. To apply PRosac :( .

  3. Why do you want to apply PROSAC, instead of, say, the more basic RANSAC? I recommend you filter your candidate ORB matches with either findHomography or findFundamentalMat, both of which use RANSAC to screen out incorrect matches. Then if you find RANSAC is too slow for you, look into implementing PROSAC. (Note: use findHomography if the scene content in your two pictures is basically planar, or findFundamentalMat if the matches do not lie flatly in a planar surface)

    • thank you very much for help me, i want to implement PRosac, but ,i don’t know , how i must implement it, i read the paper(chum and matas) , but, unfortunately , i dont understand, apologies me ,How do i do the implementation whit the two images. i go to try whit the findHomography function, i m using opencv 2.4.9. again. thank you.

  4. I’m starting to think you are trying to run before you can walk. Do you have a working implementation of RANSAC? PROSAC is just a small change from RANSAC, but building RANSAC (and a transform for RANSAC to search, like homography or fundamental matrix) is a much larger project. Once you have RANSAC/homography or RANSAC/fundamentalMatrix working, then switching to PROSAC is a matter of, instead of just choosing candidate subsets of points completely randomly (RANsac), choose them progressively (PROsac) according to the schedule described in Chum&Matas. This is why the project that I took up (and then let drop), was not to implement PROSAC from scratch, but to modify the existing RANSAC implementation in OpenCV so it could also optionally do PROSAC.

    For just two images, I really think that findHomography and findFundamentalMatrix already implemented in OpenCV are good enough. PROSAC is not better than RANSAC, just faster.

    But I’m also getting the sense that you don’t just have a practical need to run orb on two images, but a homework assignment to implement prosac in C++, in which case, you gotta start with an exact transform, then implement ransac to iterate that exact transform over randomly-selected subsets of points, and then upgrade ransac to use the prosac schedule of selecting subsets.

    • thank you, for help me, i gonna review , much better , Ransac algorithm , for after try to make change for to PRosac, because i understand more whit your hint. apologies for my english, i speak spanish and portuguese.

  5. Your English is way better than my Spanish or Portuguese! Good luck, I hope the review of RANSAC will get you up to speed so you can understand the Chum&Matas paper better.

    I still think if you just use OpenCV’s findHomography or findFundamentalMatrix (with RANSAC already built in, it will tell you which of your ORB points are a self-consistent consensus of matches and which are outliers), you will find it is good enough and you don’t need to actually step up to PROSAC.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: