Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

BRISK Detector with RANSAC

HI, I find the keypoint and the match between two images with BRISK ( I have to use it ) but now I need to use RANSAC to estimate the correspondence better than the only matcher function. Can you help me?

I think: I take the position of keypoint in the object and in the scene and calculate Homography with it, but i don't now how to continue.

Please help me.

BRISK Detector with RANSAC

HI, I find the keypoint and the match between two images with BRISK ( I have to use it ) but now I need to use RANSAC to estimate the correspondence better than the only matcher function. Can you help me?

I think: I take the position of keypoint in the object and in the scene and calculate Homography with it, but i don't now how to continue.

Please help me.

This is my code:

Bitmap Matches(){
    FeatureDetector detector;
    MatOfKeyPoint keypoints1, keypoints2;
    DescriptorExtractor descriptorExtractor;
    Mat descriptors1, descriptors2;
    DescriptorMatcher descriptorMatcher;
    MatOfDMatch matches = new MatOfDMatch();
    keypoints1 = new MatOfKeyPoint();
    keypoints2 = new MatOfKeyPoint();
    descriptors1 = new Mat();
    descriptors2 = new Mat();
    detector = FeatureDetector.create(FeatureDetector.BRISK);
    descriptorExtractor = DescriptorExtractor.create(DescriptorExtractor.BRISK);
    descriptorMatcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
    detector.detect(immagine1,keypoints1);
    detector.detect(immagine2, keypoints2);

    descriptorExtractor.compute(immagine1, keypoints1, descriptors1);
    descriptorExtractor.compute(immagine2, keypoints2, descriptors2);
    descriptorMatcher.match(descriptors1, descriptors2, matches);

    // Creo una lista di Keypoint della prima e della seconda immagine
    List<KeyPoint> keypoints1_List = keypoints1.toList();
    List<KeyPoint> keypoints2_List = keypoints2.toList();

    // Creo la lista che conterrà i keypoint della seconda immagine che hanno matchato
    List<KeyPoint> keypoint_scena_match = keypoints2.toList();

    // matrice dei soli keypoint della scena che matchano
    MatOfKeyPoint keypoint2_matched = new MatOfKeyPoint();
    keypoint2_matched.fromList(keypoint_scena_match);


    // Ottengo i punti dove si trovano i keypoint:

        // Creo la lista dei punti di match tra oggetto e scena
    LinkedList<Point> objList = new LinkedList<Point>();
    LinkedList<Point> sceneList = new LinkedList<Point>();

    // Creo la lista dei punti che hanno matchato
    for (int i=0; i<descriptors1.rows();i++){
        objList.addLast(keypoints1_List.get(matches.toList().get(i).queryIdx).pt);
        sceneList.addLast(keypoints2_List.get(matches.toList().get(i).trainIdx).pt);
    }

    // Creo le matrici di punti che contengono i punti che matchano
    MatOfPoint2f oggeto = new MatOfPoint2f();
    MatOfPoint2f scena = new MatOfPoint2f();
    oggeto.fromList(objList);
    scena.fromList(sceneList);

    // Trovo la trasformazione avvenuta tra una matrice e l'altra:
    Mat H = Calib3d.findHomography(oggeto, scena, Calib3d.RANSAC, 10); // uso RANSAC

    // Trovo la posizione dei keypoint tramite homografia
    MatOfPoint2f oggetto_homografato = new MatOfPoint2f();
    Imgproc.warpPerspective(oggeto, oggetto_homografato, H, new Size(immagine1.cols(), immagine1.rows()));

    // prendo i keypoint giusti:
    double dist_x = Math.abs(oggetto_homografato.toList().get(1).x-scena.toList().get(1).x);
    double dist_y = Math.abs(oggetto_homografato.toList().get(1).y - scena.toList().get(1).y);
    Toast.makeText(MainActivity.this,"Ho Trovato i match",Toast.LENGTH_SHORT).show();
    /*
    Mat src3 = new Mat();
    Mat im1 = new Mat();
    Mat im2 = new Mat();
    Imgproc.cvtColor(immagine1, im1, Imgproc.COLOR_BGR2RGB);
    Imgproc.cvtColor(immagine2, im2, Imgproc.COLOR_BGR2RGB);
    Features2d.drawMatches(im1, keypoints1, im2, keypoints2, matches, src3);
    Bitmap image1 = Bitmap.createBitmap(src3.cols(), src3.rows(), Bitmap.Config.ARGB_8888);
    Imgproc.cvtColor(src3, src3, Imgproc.COLOR_RGB2BGR);
    Utils.matToBitmap(src3, image1);
    Toast.makeText(MainActivity.this,"Ho finito",Toast.LENGTH_SHORT).show();*/
    return null; // for now is null but at the and it return the aside image of object and the scene
}

BRISK Detector with RANSAC

HI, I find the keypoint and the match between two images with BRISK ( I have to use it ) but now I need to use RANSAC to estimate the correspondence better than the only matcher function. Can you help me?

I think: I take the position of keypoint in the object and in the scene and calculate Homography with it, but i don't now how to continue.

Please help me.

This is my code:

 Bitmap Matches(){
     FeatureDetector detector;
     MatOfKeyPoint keypoints1, keypoints2;
     DescriptorExtractor descriptorExtractor;
     Mat descriptors1, descriptors2;
     DescriptorMatcher descriptorMatcher;
     MatOfDMatch matches = new MatOfDMatch();
     keypoints1 = new MatOfKeyPoint();
     keypoints2 = new MatOfKeyPoint();
     descriptors1 = new Mat();
     descriptors2 = new Mat();
     detector = FeatureDetector.create(FeatureDetector.BRISK);
     descriptorExtractor = DescriptorExtractor.create(DescriptorExtractor.BRISK);
     descriptorMatcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
     detector.detect(immagine1,keypoints1);
     detector.detect(immagine2, keypoints2);

     descriptorExtractor.compute(immagine1, keypoints1, descriptors1);
     descriptorExtractor.compute(immagine2, keypoints2, descriptors2);
    descriptorMatcher.match(descriptors1, descriptors2,     descriptorMatcher.match(descriptors2, descriptors1, matches);

    // Creo una lista di Keypoint della prima e della seconda immagine
    //calculate max and min distances between keypoints
        double max_dist=0;double min_dist=99;

        List<DMatch> matchesList = matches.toList();
        for(int i=0;i<descriptors2.rows();i++)
        {
            double dist = matchesList.get(i).distance;
            if (dist<min_dist) min_dist = dist;
            if (dist>max_dist) max_dist = dist;
        }

        //set up good matches, add matches if close enough
        LinkedList<DMatch> good_matches = new LinkedList<DMatch>();
        MatOfDMatch gm = new MatOfDMatch();
        for (int i=0;i<descriptors1.rows();i++)
        {
            if(matchesList.get(i).distance<max_dist)
            {
                good_matches.addLast(matchesList.get(i));
            }
        }
        gm.fromList(good_matches);

        //put keypoints mats into lists
        List<KeyPoint> keypoints1_List = keypoints1.toList();
     List<KeyPoint> keypoints2_List = keypoints2.toList();

    // Creo la lista che conterrà i keypoint della seconda immagine che hanno matchato
    List<KeyPoint> keypoint_scena_match = keypoints2.toList();

    // matrice dei soli keypoint della scena che matchano
    MatOfKeyPoint keypoint2_matched = new MatOfKeyPoint();
    keypoint2_matched.fromList(keypoint_scena_match);


    // Ottengo i punti dove si trovano i keypoint:

        // Creo la lista dei punti di match tra oggetto e scena
    //put keypoints into point2f mats so calib3d can use them to find homography
        LinkedList<Point> objList = new LinkedList<Point>();
     LinkedList<Point> sceneList = new LinkedList<Point>();

    // Creo la lista dei punti che hanno matchato
    for (int i=0; i<descriptors1.rows();i++){
        objList.addLast(keypoints1_List.get(matches.toList().get(i).queryIdx).pt);
        sceneList.addLast(keypoints2_List.get(matches.toList().get(i).trainIdx).pt);
        for(int i=0;i<good_matches.size();i++)
        {
            objList.addLast(keypoints1_List.get(good_matches.get(i).trainIdx).pt);
            sceneList.addLast(keypoints2_List.get(good_matches.get(i).queryIdx).pt);
        }

    // Creo le matrici di punti che contengono i punti che matchano
     MatOfPoint2f oggeto obj = new MatOfPoint2f();
     MatOfPoint2f scena scene = new MatOfPoint2f();
    oggeto.fromList(objList);
    scena.fromList(sceneList);

    // Trovo la trasformazione avvenuta tra una matrice e l'altra:
    obj.fromList(objList);
        scene.fromList(sceneList);

        //output image
        Mat outputImg = new Mat();
        MatOfByte drawnMatches = new MatOfByte();
        Features2d.drawMatches(immagine1, keypoints1, immagine2, keypoints2, gm, outputImg,
                Scalar.all(-1), Scalar.all(-1), drawnMatches,Features2d.NOT_DRAW_SINGLE_POINTS);

        //run homography on object and scene points
        Mat H = Calib3d.findHomography(oggeto, scena, Calib3d.RANSAC, 10); Calib3d.findHomography(obj, scene,Calib3d.RANSAC, 5);


        Mat tmp_corners = new Mat(4,1,CvType.CV_32FC2);
        Mat scene_corners = new Mat(4,1,CvType.CV_32FC2);

        //get corners from object
        tmp_corners.put(0, 0, new double[] {0,0});
        tmp_corners.put(1, 0, new double[] {immagine1.cols(),0});
        tmp_corners.put(2, 0, new double[] {immagine1.cols(),immagine1.rows()});
        tmp_corners.put(3, 0, new double[]{0, immagine1.rows()});

        Core.perspectiveTransform(tmp_corners, scene_corners, H);

        // uso RANSAC

find corner in the scene
        Core.line(outputImg, new Point(scene_corners.get(0,0)),
                new Point(scene_corners.get(1,0)), new Scalar(0, 255, 0),4);
        Core.line(outputImg, new Point(scene_corners.get(1,0)),
                new Point(scene_corners.get(2,0)), new Scalar(0, 255, 0),4);
        Core.line(outputImg, new Point(scene_corners.get(2,0)),
                new Point(scene_corners.get(3,0)), new Scalar(0, 255, 0),4);
        Core.line(outputImg, new Point(scene_corners.get(3,0)),
                new Point(scene_corners.get(0,0)), new Scalar(0, 255, 0),4);

        // Trovo la posizione dei keypoint tramite homografia
    MatOfPoint2f oggetto_homografato = new MatOfPoint2f();
    Imgproc.warpPerspective(oggeto, oggetto_homografato, H, new Size(immagine1.cols(), immagine1.rows()));

    // prendo i keypoint giusti:
    double dist_x = Math.abs(oggetto_homografato.toList().get(1).x-scena.toList().get(1).x);
    double dist_y = Math.abs(oggetto_homografato.toList().get(1).y - scena.toList().get(1).y);
    Toast.makeText(MainActivity.this,"Ho Trovato i match",Toast.LENGTH_SHORT).show();
    /*
    Mat src3 = new Mat();
    Mat im1 = new Mat();
    Mat im2 = new Mat();
    Imgproc.cvtColor(immagine1, im1, Imgproc.COLOR_BGR2RGB);
    Imgproc.cvtColor(immagine2, im2, Imgproc.COLOR_BGR2RGB);
    Features2d.drawMatches(im1, keypoints1, im2, keypoints2, matches, src3);
create the ouput image
        Bitmap image1 = Bitmap.createBitmap(src3.cols(), src3.rows(), image_out = Bitmap.createBitmap(outputImg.cols(),outputImg.rows(), Bitmap.Config.ARGB_8888);
    Imgproc.cvtColor(src3, src3, Imgproc.COLOR_RGB2BGR);
    Utils.matToBitmap(src3, image1);
    Toast.makeText(MainActivity.this,"Ho finito",Toast.LENGTH_SHORT).show();*/
    //Imgproc.cvtColor(outputImg,outputImg,Imgproc.COLOR_GRAY2BGR);
        Utils.matToBitmap(outputImg,image_out);
       return null; // for now is null but at the and it return the aside image of object and the scene
image_out;
    }

This is my object This is my scene This my result

I think if I find the shape of the object and then apply to this the Hmography but my difficulty is to fine the shape, i try with findContours but it does not work i need the coordinate of the point with create the contours.

This is my new code and the result. Can you help me?

BRISK Detector with RANSAC

HI, I find the keypoint and the match between two images with BRISK ( I have to use it ) but now I need to use RANSAC to estimate the correspondence better than the only matcher function. Can you help me?

I think: I take the position of keypoint in the object and in the scene and calculate Homography with it, but i don't now how to continue.

Please help me.

This is my code:

 Bitmap Matches(){
        FeatureDetector detector;
        MatOfKeyPoint keypoints1, keypoints2;
        DescriptorExtractor descriptorExtractor;
        Mat descriptors1, descriptors2;
        DescriptorMatcher descriptorMatcher;
        MatOfDMatch matches = new MatOfDMatch();
        keypoints1 = new MatOfKeyPoint();
        keypoints2 = new MatOfKeyPoint();
        descriptors1 = new Mat();
        descriptors2 = new Mat();
        detector = FeatureDetector.create(FeatureDetector.BRISK);
        descriptorExtractor = DescriptorExtractor.create(DescriptorExtractor.BRISK);
        descriptorMatcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
        detector.detect(immagine1,keypoints1);
        detector.detect(immagine2, keypoints2);

        descriptorExtractor.compute(immagine1, keypoints1, descriptors1);
        descriptorExtractor.compute(immagine2, keypoints2, descriptors2);
        descriptorMatcher.match(descriptors2, descriptors1, matches);

        //calculate max and min distances between keypoints
        double max_dist=0;double min_dist=99;

        List<DMatch> matchesList = matches.toList();
        for(int i=0;i<descriptors2.rows();i++)
        {
            double dist = matchesList.get(i).distance;
            if (dist<min_dist) min_dist = dist;
            if (dist>max_dist) max_dist = dist;
        }

        //set up good matches, add matches if close enough
        LinkedList<DMatch> good_matches = new LinkedList<DMatch>();
        MatOfDMatch gm = new MatOfDMatch();
        for (int i=0;i<descriptors1.rows();i++)
        {
            if(matchesList.get(i).distance<max_dist)
            {
                good_matches.addLast(matchesList.get(i));
            }
        }
        gm.fromList(good_matches);

        //put keypoints mats into lists
        List<KeyPoint> keypoints1_List = keypoints1.toList();
        List<KeyPoint> keypoints2_List = keypoints2.toList();

        //put keypoints into point2f mats so calib3d can use them to find homography
        LinkedList<Point> objList = new LinkedList<Point>();
        LinkedList<Point> sceneList = new LinkedList<Point>();
        for(int i=0;i<good_matches.size();i++)
        {
            objList.addLast(keypoints1_List.get(good_matches.get(i).trainIdx).pt);
            sceneList.addLast(keypoints2_List.get(good_matches.get(i).queryIdx).pt);
        }
        MatOfPoint2f obj = new MatOfPoint2f();
        MatOfPoint2f scene = new MatOfPoint2f();
        obj.fromList(objList);
        scene.fromList(sceneList);

        //output image
        Mat outputImg = new Mat();
        MatOfByte drawnMatches = new MatOfByte();
        Features2d.drawMatches(immagine1, keypoints1, immagine2, keypoints2, gm, outputImg,
                Scalar.all(-1), Scalar.all(-1), drawnMatches,Features2d.NOT_DRAW_SINGLE_POINTS);

        //run homography on object and scene points
        Mat H = Calib3d.findHomography(obj, scene,Calib3d.RANSAC, 5);


    10);

         // trovo il contorno dell'oggetto
    Mat tmp_corners = new Mat(4,1,CvType.CV_32FC2);
    edges = new Mat();
    Mat scene_corners = new Mat(4,1,CvType.CV_32FC2);

        //get corners from object
        tmp_corners.put(0, 0, new double[] {0,0});
        tmp_corners.put(1, 0, new double[] {immagine1.cols(),0});
        tmp_corners.put(2, 0, new double[] {immagine1.cols(),immagine1.rows()});
        tmp_corners.put(3, 0, new double[]{0, immagine1.rows()});

        Core.perspectiveTransform(tmp_corners, scene_corners, H);

    hierarchy = new Mat();

    // find corner in the scene
        Core.line(outputImg, new Point(scene_corners.get(0,0)),
                new Point(scene_corners.get(1,0)), new Scalar(0, 255, 0),4);
        Core.line(outputImg, new Point(scene_corners.get(1,0)),
                new Point(scene_corners.get(2,0)), new Scalar(0, 255, 0),4);
        Core.line(outputImg, new Point(scene_corners.get(2,0)),
                new Point(scene_corners.get(3,0)), new Scalar(0, 255, 0),4);
        Core.line(outputImg, new Point(scene_corners.get(3,0)),
                new Point(scene_corners.get(0,0)), new Scalar(0, 255, 0),4);

 ogni contorno è una lista di punti
    List<MatOfPoint> contourList = new ArrayList<MatOfPoint>(); // lista dei contorni

    Imgproc.Canny(immagine1_grey, edges, 10, 100);
    // Applico la trasformazione all'immagine
    Mat bordi = new Mat(edges.cols(),edges.rows(),CvType.CV_32FC2);
    Imgproc.warpPerspective(edges, bordi, H, new Size(edges.cols(), edges.rows()));
    //Trovo i contorni

    Imgproc.findContours(bordi,contourList,hierarchy,Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);


       // create the ouput image
     Bitmap image_out = Bitmap.createBitmap(outputImg.cols(),outputImg.rows(), Bitmap.createBitmap(bordi.cols(),bordi.rows(), Bitmap.Config.ARGB_8888);
     //Imgproc.cvtColor(outputImg,outputImg,Imgproc.COLOR_GRAY2BGR);
        Utils.matToBitmap(outputImg,image_out);
Utils.matToBitmap(bordi,image_out);
       return image_out;
    }

This is my object This is my scene This my result

I think if I find the shape Now i found the contours of the object and then apply to this the Hmography but my difficulty the tomography application is to fine the shape, i try not the image with findContours edges homograph but it does not work i need the coordinate of the point with create the contours.an image which don't have the contour.

This is my new code and the result. Can you help me?

BRISK Detector with RANSAC

HI, I find the keypoint and the match between two images with BRISK ( I have to use it ) but now I need to use RANSAC to estimate the correspondence better than the only matcher function. Can you help me?

I think: I take the position of keypoint in the object and in the scene and calculate Homography with it, but i don't now how to continue.

Please help me.

This is my code:

 Bitmap Matches(){
     FeatureDetector detector;
     MatOfKeyPoint keypoints1, keypoints2;
     DescriptorExtractor descriptorExtractor;
     Mat descriptors1, descriptors2;
     DescriptorMatcher descriptorMatcher;
     MatOfDMatch matches = new MatOfDMatch();
     keypoints1 = new MatOfKeyPoint();
     keypoints2 = new MatOfKeyPoint();
     descriptors1 = new Mat();
     descriptors2 = new Mat();
     detector = FeatureDetector.create(FeatureDetector.BRISK);
     descriptorExtractor = DescriptorExtractor.create(DescriptorExtractor.BRISK);
     descriptorMatcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
     detector.detect(immagine1,keypoints1);
     detector.detect(immagine2, keypoints2);

     descriptorExtractor.compute(immagine1, keypoints1, descriptors1);
     descriptorExtractor.compute(immagine2, keypoints2, descriptors2);
     descriptorMatcher.match(descriptors2, descriptors1, matches);

     //calculate max and min distances between keypoints
     double max_dist=0;double min_dist=99;

     List<DMatch> matchesList = matches.toList();
     for(int i=0;i<descriptors2.rows();i++)
     {
         double dist = matchesList.get(i).distance;
         if (dist<min_dist) min_dist = dist;
         if (dist>max_dist) max_dist = dist;
     }

     //set up good matches, add matches if close enough
     LinkedList<DMatch> good_matches = new LinkedList<DMatch>();
     MatOfDMatch gm = new MatOfDMatch();
     for (int i=0;i<descriptors1.rows();i++)
     {
         if(matchesList.get(i).distance<max_dist)
         {
             good_matches.addLast(matchesList.get(i));
         }
     }
     gm.fromList(good_matches);

     //put keypoints mats into lists
     List<KeyPoint> keypoints1_List = keypoints1.toList();
     List<KeyPoint> keypoints2_List = keypoints2.toList();

     //put keypoints into point2f mats so calib3d can use them to find homography
     LinkedList<Point> objList = new LinkedList<Point>();
     LinkedList<Point> sceneList = new LinkedList<Point>();
     for(int i=0;i<good_matches.size();i++)
     {
         objList.addLast(keypoints1_List.get(good_matches.get(i).trainIdx).pt);
         sceneList.addLast(keypoints2_List.get(good_matches.get(i).queryIdx).pt);
     }
     MatOfPoint2f obj = new MatOfPoint2f();
     MatOfPoint2f scene = new MatOfPoint2f();
     obj.fromList(objList);
     scene.fromList(sceneList);

     //output image
     Mat outputImg = new Mat();
     MatOfByte drawnMatches = new MatOfByte();
     Features2d.drawMatches(immagine1, keypoints1, immagine2, keypoints2, gm, outputImg,
             Scalar.all(-1), Scalar.all(-1), drawnMatches,Features2d.NOT_DRAW_SINGLE_POINTS);

     //run homography on object and scene points
     Mat H = Calib3d.findHomography(obj, scene,Calib3d.RANSAC, 10);

      // trovo il contorno dell'oggetto
    Mat edges = new Mat();
    Mat hierarchy = new Mat();

    // ogni contorno è una lista di punti
    List<MatOfPoint> contourList = new ArrayList<MatOfPoint>(); // lista dei contorni

    Imgproc.Canny(immagine1_grey, edges, 10, 100);
    // Applico la trasformazione all'immagine
    Mat bordi = new Mat(edges.cols(),edges.rows(),CvType.CV_32FC2);
    Imgproc.warpPerspective(edges, bordi, H, new Size(edges.cols(), edges.rows()));
    //Trovo i contorni

    Imgproc.findContours(bordi,contourList,hierarchy,Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);


       Imgproc.findContours(edges,contourList,hierarchy,Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);

    MatOfPoint2f approxCurve = new MatOfPoint2f();
    MatOfPoint points = null;
    //For each contour found
    for (int i=0; i<contourList.size(); i++)
    {
        //Convert contours(i) from MatOfPoint to MatOfPoint2f
        MatOfPoint2f contour2f = new MatOfPoint2f( contourList.get(i).toArray() );
        //Processing on mMOP2f1 which is in type MatOfPoint2f
        double approxDistance = Imgproc.arcLength(contour2f, true)*0.02;
        Imgproc.approxPolyDP(contour2f, approxCurve, approxDistance, true);

        //Convert back to MatOfPoint
        points = new MatOfPoint( approxCurve.toArray() );

        // Get bounding rect of contour
        Rect rect = Imgproc.boundingRect(points);

        // draw enclosing rectangle (all same color, but you could use variable i to make them unique)
        Core.rectangle(edges,new Point(rect.x,rect.y),
                new Point(rect.x + rect.width,rect.y+rect.height),new Scalar(255,0,0),3);
    }
    MatOfPoint posizione = new MatOfPoint();

    Imgproc.warpPerspective(points, posizione, H, new Size(points.cols(), points.rows())); // this is the problem

    Rect rectangle = Imgproc.boundingRect(posizione);

    Core.rectangle(immagine2_grey,new Point(rectangle.x,rectangle.y),
            new Point(rectangle.x + rectangle.width,rectangle.y + rectangle.height),
            new Scalar(255,0,0),1);

    // create the ouput image
    Bitmap image_out = Bitmap.createBitmap(bordi.cols(),bordi.rows(), Bitmap.Config.ARGB_8888);
    //Imgproc.cvtColor(outputImg,outputImg,Imgproc.COLOR_GRAY2BGR);
    Utils.matToBitmap(bordi,image_out);
    Utils.matToBitmap(immagine2_grey,image_out);
   return image_out;
 }

This is my object This is my scene This my result

Now My idea is: 1) Find the keypoint (done) 2) Find descriptor of keypoint (done) 3) Find homography transformation by RANSAC using calib3d ( the function in the code) and the position of keypoint which match (i think i found done it) 4) Find the contours of the object but the tomography application in the image one ( the object i want to find) (i think it work) 5) Find the position of the contours (i think it work ) 6) Apply homography to the position of point 5 ( this is not the the problem ) 7) Create a rectangle on the image 2( the scene) with the point obtained at the point 6 by homography 8) Create the final image with edges homograph but an image which don't have the contour.Features2d.drawmatches

This is my new code and the result. Can you help me?