Ask Your Question

Revision history [back]

Why Opencv ORB image matching fail randomly for a specific image?

My application is developed using Android and Opencv.

I'm trying to match 3 real time images with a 3 reference images using ORB (I should've mentioned the method of features matching because maybe it can be the source of problem).

The main image processing is done in c++ and call JNI function in java.

I noticed a native SIGSEGV crash that is generated randomly, and after a lot of debugging and observations I found that the issues is trying to access an index in an empty array, that array is the matches array.

A lot of other debugging, I found that after I perform a symmetry test the result is 0, that's why the RANSAC test gives 0 matches and the program fail.

So I moved the the next step, and performed the matching in each image seperately, I found that a single image cause the crash, and not always.

Here is the symmetry test function

void symmetryTest(
const std::vector<std::vector<cv::DMatch> > &matches1,
const std::vector<std::vector<cv::DMatch> > &matches2,
std::vector<cv::DMatch> &symMatches) {
 int count = 0;
 // for all matches image 1 -> image 2
for (std::vector<std::vector<cv::DMatch> >::
 const_iterator matchIterator1 = matches1.begin();
 matchIterator1 != matches1.end(); ++matchIterator1) {
// ignore deleted matches
if (matchIterator1->size() < 2)
    continue;
// for all matches image 2 -> image 1
for (std::vector<std::vector<cv::DMatch> >::
     const_iterator matchIterator2 = matches2.begin();
     matchIterator2 != matches2.end();
     ++matchIterator2) {

    // ignore deleted matches
    if (matchIterator2->size() < 2)
        continue;
    // Match symmetry test
    if ((*matchIterator1)[0].queryIdx ==
        (*matchIterator2)[0].trainIdx &&
        (*matchIterator2)[0].queryIdx ==
        (*matchIterator1)[0].trainIdx) {

        count++;
        // add symmetrical match
        symMatches.push_back(
                cv::DMatch((*matchIterator1)[0].queryIdx,
                           (*matchIterator1)[0].trainIdx,
                           (*matchIterator1)[0].distance));
        break; // next match in image 1 -> image 2
    }
}
}
}

Here is the image that cause fail

image description

I tried to clone the Mat objects before sending them to native processing.

I also performed tests to make sure if the images are valid and available.

I am stuck at this point for a week but I can't find any thing to start with.

Can the reason be that ORB can't detect matches in an image with low details ?