4
votes

I'am using ORB feature detector and extractor to get features from a list of grayscale images. The problem is that I get different features from the same image if I try to detect\extract it more than once. So it is impossible to use them for detection later.

The code:

bmp=BitmapFactory.decodeResource(getResources(),R.drawable.t1);
Utils.bitmapToMat(bmp, mat);
FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
detector.detect(mat, keypoints);
DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
extractor.compute(mat, keypoints, features);

Maybe someone have some insight into that?

1

1 Answers

2
votes

This should not be the case..you should get consistent performance. However I am sharing my code to use Orb Feature detector as well as Orb Descriptor Extractor on two images. You can use any matcher to match them. Hope this helps you...

#include "iostream"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/nonfree/nonfree.hpp>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/flann/flann.hpp>
#include <opencv2/legacy/legacy.hpp>
#include <vector>


using namespace cv;
using namespace std;

int main()
{
    Mat image1,image2;
    imageA = imread("C:\\lena.jpg",0);
    imageB = imread("C:\\lena1.bmp",0);

    vector<KeyPoint> keypointsA,keypointsB;
    Mat descriptorsA,descriptorsB;

    std::vector<DMatch> matches;

    OrbFeatureDetector detector;

    OrbDescriptorExtractor extractor;

    BruteForceMatcher<Hamming> matcher;

    detector.detect(imageA,keypointsA);
    detector.detect(imageB,keypointsB);

    extractor.compute(imageA,keypointsA,descriptorsA);
    extractor.compute(imageB,keypointsB,descriptorsB);

    return 0;
 }