Hi, i want this:

but i obtain this with my code:

and my code is:
Bitmap Matches(){
Mat images1 = new Mat();
Mat images2 = new Mat();
images1 = immagine1.clone();
images2 = immagine2.clone();
// trovo i keypoint
final MatOfKeyPoint keypoint1 = new MatOfKeyPoint();
final MatOfKeyPoint keypoint2 = new MatOfKeyPoint();
final Mat descriptor1 = new Mat();
final Mat descriptor2 = new Mat();
final Mat out_put_image = new Mat();
Bitmap image;
final MatOfDMatch dMatch = new MatOfDMatch();
FeatureDetector detector = FeatureDetector.create(FeatureDetector.BRISK);
final DescriptorExtractor descriptorExtractor = DescriptorExtractor.create(DescriptorExtractor.BRISK);
final DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
detector.detect(images1, keypoint1);
detector.detect(images2, keypoint2);
// trovo i descrittori
descriptorExtractor.compute(images1, keypoint1, descriptor1);
descriptorExtractor.compute(images2, keypoint2, descriptor2);
// trovo i match
matcher.match(descriptor2, descriptor1, dMatch);
//calculate max and min distances between keypoints
double max_dist=0;double min_dist=99;
List matchesList = dMatch.toList();
for(int i=0;i max_dist)
{
max_dist = dist;
}
}
double threshold = 3 * min_dist;
double threshold2 = 2 * min_dist;
if (threshold2 >= max_dist)
{
threshold = min_dist * 1.1;
}
else if (threshold >= max_dist)
{
threshold = threshold2 * 1.4;
}
//set up good matches, add matches if close enough
LinkedList good_matches = new LinkedList();
MatOfDMatch gm = new MatOfDMatch();
for (int i = 0; i < matchesList.size(); i++)
{
double dist = matchesList.get(i).distance;
if (dist < threshold)
{
good_matches.add(dMatch.toList().get(i));
}
}
gm.fromList(good_matches);
//put keypoints mats into lists
List keypoints1_List = keypoint1.toList();
List keypoints2_List = keypoint2.toList();
//put keypoints into point2f mats so calib3d can use them to find homography
LinkedList objList = new LinkedList();
LinkedList objK = new LinkedList<>();
LinkedList sceneList = new LinkedList();
LinkedList scnK = new LinkedList<>();
for(int i=0;i contourList = new ArrayList<>();
Imgproc.cvtColor(images1, gray1, Imgproc.COLOR_BGR2GRAY);
Imgproc.Canny(images1, cannyEdges, 10, 110);
Imgproc.findContours(cannyEdges, contourList, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
Mat obj_mat = Converters.vector_Point_to_Mat(contourList.get(0).toList(),CvType.CV_32F);
Mat destination = new Mat(obj_mat.rows(),obj_mat.cols(),CvType.CV_32F);
List contourLists = new ArrayList<>();
//Creo l'immagine
Imgproc.cvtColor(images1, images1, Imgproc.COLOR_BGR2RGB);
Imgproc.cvtColor(images2, images2, Imgproc.COLOR_BGR2RGB);
MatOfPoint2f approxCurve = new MatOfPoint2f();
//For each contour found
for (int i=0; i nuovi = new LinkedList<>();
MatOfPoint2f nuovi_point = new MatOfPoint2f();
for (int i=0; i
↧