I want to find similar images in gallery using OpenCv java Android
and what should be the parameter of BOWImgDescriptorExtractor extractor = BOWImgDescriptorExtractor.__fromPtr__(matches.nativeObj);
or how to create object of this class
BOWImgDescriptorExtractor
private boolean compareMats(Mat img1, Mat img2) {
FastFeatureDetector detector = FastFeatureDetector.create();
//matcher image descriptors
MatOfDMatch matches = new MatOfDMatch();
// bowDe = new BOWImgDescriptorExtractor(_detector, _matcher);
BOWImgDescriptorExtractor extractor = BOWImgDescriptorExtractor.__fromPtr__(matches.nativeObj);
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
Mat descriptors1 = new Mat();
MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
detector.detect(img1, keypoints1);
try {
extractor.compute(img1, keypoints1, descriptors1);
} catch (Exception e) {
e.printStackTrace();
Log.d(TAG, "compareMats_: " + e.getMessage());
}
//second image
// Mat img2 = Imgcodecs.imread(path2);
//BOWImgDescriptorExtractor extractor1 = BOWImgDescriptorExtractor.__fromPtr__(img2.getNativeObjAddr());
Mat descriptors2 = new Mat();
MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
detector.detect(img2, keypoints2);
try {
extractor.compute(img2, keypoints2, descriptors2);
} catch (Exception e) {
e.printStackTrace();
Log.d(TAG, "compareMats: " + e.getMessage());
}
matcher.match(descriptors1, descriptors2, matches);
// Filter matches by distance
MatOfDMatch filtered = filterMatchesByDistance(matches);
int total = (int) matches.size().height;
int Match = (int) filtered.size().height;
Log.d("LOG", "total:" + total + " Match:" + Match);
System.gc();
return Match > total * 0.8;
}
static MatOfDMatch filterMatchesByDistance(MatOfDMatch matches) {
List<DMatch> matches_original = matches.toList();
List<DMatch> matches_filtered = new ArrayList<DMatch>();
int DIST_LIMIT = 30;
// Check all the matches distance and if it passes add to list of filtered matches
Log.d("DISTFILTER", "ORG SIZE:" + matches_original.size() + "");
for (int i = 0; i < matches_original.size(); i++) {
DMatch d = matches_original.get(i);
if (Math.abs(d.distance) <= DIST_LIMIT) {
matches_filtered.add(d);
}
}
Log.d("DISTFILTER", "FIL SIZE:" + matches_filtered.size() + "");
MatOfDMatch mat = new MatOfDMatch();
mat.fromList(matches_filtered);
return mat;
}
but getting Following error At extractor.compute(img2, keypoints2, descriptors2);
A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x42ff0068 in tid 19304 (ailestestopencv), pid 19304 (ailestestopencv)
It would be highly appreciated if anyone answer me.