List of usage examples for org.opencv.features2d ORB compute
public void compute(Mat image, MatOfKeyPoint keypoints, Mat descriptors)
From source file:io.github.jakejmattson.facialrecognition.FacialRecognition.java
License:Open Source License
private static int compareFaces(Mat currentImage, String fileName) { Mat compareImage = Imgcodecs.imread(fileName); ORB orb = ORB.create(); int similarity = 0; MatOfKeyPoint keypoints1 = new MatOfKeyPoint(); MatOfKeyPoint keypoints2 = new MatOfKeyPoint(); orb.detect(currentImage, keypoints1); orb.detect(compareImage, keypoints2); Mat descriptors1 = new Mat(); Mat descriptors2 = new Mat(); orb.compute(currentImage, keypoints1, descriptors1); orb.compute(compareImage, keypoints2, descriptors2); if (descriptors1.cols() == descriptors2.cols()) { MatOfDMatch matchMatrix = new MatOfDMatch(); DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING); matcher.match(descriptors1, descriptors2, matchMatrix); DMatch[] matches = matchMatrix.toArray(); for (DMatch match : matches) if (match.distance <= 50) similarity++;//from w ww . j av a 2 s. c om } return similarity; }