Ask Your Question

MikeyMike's profile - activity

2016-02-29 08:37:47 -0600 asked a question Comparing two images if they are the same

I'm trying to compare two images using bfmatcher, however it is not working. The program is about comparing speed limit signs and see given speed limit sign is particular speed limit sign. I have given perspective corrected signs and a bigger image that contains speed sign(strictly one sign). I'm able to extract a sign from bigger image. What I need to do is, compare the two and see they are match. I'm not sure what's going on but my codes given me the same matching result for 40 limit sign vs 80 limit sign and 40 limit sign vs 40 limit sign. Am I using bfmatcher wrong? This is part of my code

    Point2f inputQuad[4];
    // Output Quadilateral or World plane coordinates
    Point2f outputQuad[4];

    Mat lambda;

    Mat output;

    // src_gray is an orignal(bigger) image and it's in 8 bit format
    lambda = Mat::zeros(src_gray.rows, src_gray.cols, src_gray.type());


    vector<Point> points;
    points = squares[0];
    //This custom method actually sort the contours spat out from findcontour method
            //so the image is in correct orientation
    points = SortContour(points);

    inputQuad[0] = Point2f(points[0].x, points[0].y);
    inputQuad[1] = Point2f(points[1].x, points[1].y);
    inputQuad[2] = Point2f(points[3].x, points[3].y);
    inputQuad[3] = Point2f(points[2].x, points[2].y);
    outputQuad[0] = Point2f(0, 0);
    outputQuad[1] = Point2f(src_gray.cols - 1, 0);
    outputQuad[2] = Point2f(src_gray.cols - 1, src_gray.rows - 1);
    outputQuad[3] = Point2f(0, src_gray.rows - 1);

    // Perspective transformation
    lambda = getPerspectiveTransform(inputQuad, outputQuad);
    // Apply transformation to source
    warpPerspective(src_gray, output, lambda, output.size());

    vector<KeyPoint> keypoints1, keypoints2, keypoints3;
    Mat descriptors1, descriptors2, descriptors3;
    vector<DMatch> dMatch40, dMatch80;
    Ptr<FeatureDetector> detector = ORB::create();

    detector->detect(output, keypoints1);
    detector->compute(output, keypoints1, descriptors1);
    detector->detect(speed_40, keypoints2);
    detector->compute(speed_40, keypoints2, descriptors2);
    detector->detect(speed_80, keypoints3);
    detector->compute(speed_80, keypoints3, descriptors3);

    BFMatcher bfm;
    dMatch40.clear();
    dMatch80.clear();
    bfm.match(descriptors1, descriptors2, dMatch40);
    bfm.match(descriptors1, descriptors3, dMatch80);
    cout << "D40 : "<<dMatch40.size();
    cout << "D80 : "<<dMatch80.size();

    namedWindow("matches", 1);
    Mat img_matches;
    drawMatches(speed_80, keypoints1, output, keypoints3, dMatch80, img_matches);
    imshow("matches", img_matches);
    waitKey(0);