Ask Your Question

Revision history [back]

opencv keypoint and histogram matching

I'm developing a project in android for image comparison. The images can be in any scale / rotation. I did some tests with my current project, but the results are not good. I thought to do beyond the keypoints matching, a histogram matching. Can anyone help me?

Images for comparison (example):

Image1:

image description

Image2:

image description

My Code:

FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);

Mat img1 = Imgcodecs.imread(teste,Imgcodecs.CV_LOAD_IMAGE_COLOR);
Mat descriptors1 = new Mat();
MatOfKeyPoint keypoints1 = new MatOfKeyPoint();

detector.detect(img1, keypoints1);
extractor.compute(img1, keypoints1, descriptors1);


Mat img2 = Imgcodecs.imread(file,Imgcodecs.CV_LOAD_IMAGE_COLOR);
Mat descriptors2 = new Mat();
MatOfKeyPoint keypoints2 = new MatOfKeyPoint();

detector.detect(img2, keypoints2);
extractor.compute(img2, keypoints2, descriptors2);

MatOfDMatch matches = new MatOfDMatch();
matcher.match(descriptors1,descriptors2,matches);

int distLimit = 80;
List<DMatch> matchesList = matches.toList();
List<DMatch> goodMatches= new ArrayList<DMatch>();

for(int i=0; i<matchesList.size(); i++) {
    if(matchesList.get(i).distance <= distLimit) {
        goodMatches.add(matches.toList().get(i));
    }
}

return goodMatches.size();