Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Feature Detector

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?

(image description)

image description

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

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

Mat img_matches;
drawMatches(imsource2, keypoints_1, imquery, keypoints_2, matches, img_matches);

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

Thank you!

Feature Detector

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?

(image description)missing? image description 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);

BFMatcher matcher(NORM_L2);
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, imquery, keypoints_2, matches, img_matches);
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!

Feature Detector

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? image description missing?

UPDATES IMAGES

image description

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!