Feature Detector

asked 2015-10-12 03:14:01 -0600

Bloc123 gravatar image

updated 2015-10-12 04:25:07 -0600

Hello, I am trying to compare two objects between each other, but am actually I am having a god at folowing this.

In the iamges I have uploaded beloew, the first one shows some similarities which is good, but when I run another image throrugh that looks nothing like the each other, I also get these matching lines? Is there something I am missing?

UPDATES IMAGES

image description

image description

UPDATED

    Mat imsource2;
Mat imquery2;

imsource_crop.copyTo(imsource2);
imquery.copyTo(imquery2);

Ptr<SURF> detector = SURF::create();
detector->setHessianThreshold(threshHaus);

std::vector<KeyPoint> keypoints_1, keypoints_2;
Mat descriptors_1, descriptors_2;

detector->detect(imsource2, keypoints_1, imsource_mask);
detector->detect(imquery2, keypoints_2, imquery_mask);

detector->compute(imsource2, keypoints_1, descriptors_1);
detector->compute(imquery2, keypoints_2, descriptors_2);

FlannBasedMatcher matcher;
std::vector< DMatch > matches;
matcher.match(descriptors_1, descriptors_2, matches);

double max_dist = 0; double min_dist = 100;

//-- Quick calculation of max and min distances between keypoints
for (int i = 0; i < descriptors_1.rows; i++)
{
    double dist = matches[i].distance;
    if (dist < min_dist) min_dist = dist;
    if (dist > max_dist) max_dist = dist;
}

printf("-- Max dist : %f \n", max_dist);
printf("-- Min dist : %f \n", min_dist);

//-- Draw only "good" matches (i.e. whose distance is less than 3*min_dist )
std::vector< DMatch > good_matches;

for (int i = 0; i < descriptors_1.rows; i++)
{
    if (matches[i].distance < 3 * min_dist)
    {
        good_matches.push_back(matches[i]);
    }
}

Mat img_matches;
drawMatches(imsource2, keypoints_1, imquery2, keypoints_2,
    good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
    vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);


//-- Show detected matches
imshow("Feature", img_matches);

Thank you!

edit retag flag offensive close merge delete

Comments

1

You should use matches[i].distance to have matching quality and threshold this value to have good matches

LBerger gravatar imageLBerger ( 2015-10-12 03:29:04 -0600 )edit

Hey Berger! thanks for your quick reply, I have tried adding in the distance mathicng like you suggested using this as my guide. But now it seems to have made it a harder to detect, although as I increase the thresh to 4000, I get around 3 mathcing lines. but those matches are really really accurate, while with the 2nd image (skull), I am still getting a lot of matches :S

Bloc123 gravatar imageBloc123 ( 2015-10-12 04:04:39 -0600 )edit
1

In given link threshold is 3min_dist if you have got a very good match dist is near 0 and 30 =0 I think it's better to use mean value or sort distance or a mixed between sort and mean.

But in your last example best match is not very good so distance is very high so 3*high value and you've got all match and my previous answer won't be good.

you can try match first image with second image and match second image with first image and only keep good match. good match is when match12[i]==j and match21[j]==i

LBerger gravatar imageLBerger ( 2015-10-12 04:17:59 -0600 )edit
1

Oh I see, I think I've got it now thanks you so much! I really appreciated your time and effort to help me. So basically what the URL i was following was doing was pretty much straining itself to match something, even though there wast a clear match right? I feel silly for not seeing that earlier. thank you again!

Bloc123 gravatar imageBloc123 ( 2015-10-12 04:38:03 -0600 )edit