Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to process result of matchShapes to get list of non-matching objects

I want to get list of non-matching objects in 2 images. Below tis the code snippet I am writing Mat img1 = Imgcodecs.imread(filename1, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE); Mat img2 = Imgcodecs.imread(filename2, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE); System.out.println(img1);

    ArrayList<MatOfPoint> contours1 = new ArrayList<MatOfPoint>();
    ArrayList<MatOfPoint> contours2 = new ArrayList<MatOfPoint>();
    Imgproc.findContours(img1, contours1, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
    Imgproc.findContours(img2, contours2, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);

    System.out.println("contours1==" + contours1.size() + "contours2==" + contours2.size());
    for (MatOfPoint matOfPoint : contours1) {
        Mat image1 = matOfPoint.t();
        for (MatOfPoint matOfPoint2 : contours2) {
            Mat image2 = matOfPoint2.t();
            double matchValue = Imgproc.matchShapes(image1,image2,Imgproc.CV_CONTOURS_MATCH_I1,0);
            System.out.println("matchValue="+matchValue);
        }

    }

Below is the output:-

contours1==62contours2==42
matchValue=1.5655476914844257E-11
matchValue=0.0
matchValue=1.5655476914844257E-11
matchValue=1.5655476914844257E-11
matchValue=0.0
matchValue=1.5655476914844257E-11
matchValue=1.5655476914844257E-11
matchValue=2.4461765946171E-11
matchValue=2.3483215372266386E-11
matchValue=0.0
matchValue=0.0
matchValue=1.2230216839270724E-12
matchValue=1.2230216839270724E-12
matchValue=0.0
matchValue=0.0
matchValue=9.78328529299688E-13
matchValue=3.913980251013527E-12
matchValue=9.78328529299688E-13
matchValue=9.78328529299688E-13
matchValue=3.913980251013527E-12
matchValue=0.0
matchValue=3.913980251013527E-12
matchValue=0.0
matchValue=9.78328529299688E-13
matchValue=3.913980251013527E-12
matchValue=9.78328529299688E-13
matchValue=0.0
matchValue=9.78328529299688E-13
matchValue=9.78328529299688E-13
matchValue=0.0
matchValue=4.892308780313215E-12
matchValue=3.913758206408602E-12
matchValue=3.913758206408602E-12
matchValue=4.892308780313215E-12
matchValue=0.0
matchValue=0.06707455245189053
matchValue=1.0763168134531043E-11
matchValue=4.892308780313215E-12
matchValue=1.0763168134531043E-11
matchValue=1.0763168134531043E-11
matchValue=4.892308780313215E-12
matchValue=1.0763168134531043E-11
matchValue=1.0763168134531043E-11
matchValue=1.0763168134531043E-11
matchValue=1.859090659195317E-11
matchValue=1.0763168134531043E-11
matchValue=1.0763168134531043E-11
matchValue=1.467714838554457E-11
matchValue=1.5655476914844257E-11
matchValue=1.0763168134531043E-11
matchValue=1.0763168134531043E-11
matchValue=1.467714838554457E-11
matchValue=1.467714838554457E-11
matchValue=1.5900170069471642E-11
matchValue=1.5900170069471642E-11
matchValue=1.467714838554457E-11
matchValue=1.467714838554457E-11
matchValue=1.5655476914844257E-11
matchValue=1.0763168134531043E-11
matchValue=1.5655476914844257E-11
matchValue=1.5655476914844257E-11
matchValue=1.0763168134531043E-11
matchValue=1.467714838554457E-11
matchValue=1.0763168134531043E-11
matchValue=1.9569457165857784E-11
matchValue=1.467714838554457E-11
matchValue=0.06707455246656768
matchValue=1.0518474979903658E-11
matchValue=5.137001934940599E-12
matchValue=1.0518474979903658E-11
matchValue=1.0518474979903658E-11
matchValue=5.137001934940599E-12

How to process result of matchShapes to get list of non-matching objects

I want to get list of non-matching objects in 2 images. Below tis the code snippet I am writing

  Mat img1 = Imgcodecs.imread(filename1, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
     Mat img2 = Imgcodecs.imread(filename2, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
        System.out.println(img1);

    ArrayList<MatOfPoint> contours1 = new ArrayList<MatOfPoint>();
    ArrayList<MatOfPoint> contours2 = new ArrayList<MatOfPoint>();
    Imgproc.findContours(img1, contours1, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
    Imgproc.findContours(img2, contours2, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);

    System.out.println("contours1==" + contours1.size() + "contours2==" + contours2.size());
    for (MatOfPoint matOfPoint : contours1) {
        Mat image1 = matOfPoint.t();
        for (MatOfPoint matOfPoint2 : contours2) {
            Mat image2 = matOfPoint2.t();
            double matchValue = Imgproc.matchShapes(image1,image2,Imgproc.CV_CONTOURS_MATCH_I1,0);
            System.out.println("matchValue="+matchValue);
        }

    }

Below is the output:-

contours1==62contours2==42
matchValue=1.5655476914844257E-11
matchValue=0.0
matchValue=1.5655476914844257E-11
matchValue=1.5655476914844257E-11
matchValue=0.0
matchValue=1.5655476914844257E-11
matchValue=1.5655476914844257E-11
matchValue=2.4461765946171E-11
matchValue=2.3483215372266386E-11
matchValue=0.0
matchValue=0.0
matchValue=1.2230216839270724E-12
matchValue=1.2230216839270724E-12
matchValue=0.0
matchValue=0.0
matchValue=9.78328529299688E-13
matchValue=3.913980251013527E-12
matchValue=9.78328529299688E-13
matchValue=9.78328529299688E-13
matchValue=3.913980251013527E-12
matchValue=0.0
matchValue=3.913980251013527E-12
matchValue=0.0
matchValue=9.78328529299688E-13
matchValue=3.913980251013527E-12
matchValue=9.78328529299688E-13
matchValue=0.0
matchValue=9.78328529299688E-13
matchValue=9.78328529299688E-13
matchValue=0.0
matchValue=4.892308780313215E-12
matchValue=3.913758206408602E-12
matchValue=3.913758206408602E-12
matchValue=4.892308780313215E-12
matchValue=0.0
matchValue=0.06707455245189053
matchValue=1.0763168134531043E-11
matchValue=4.892308780313215E-12
matchValue=1.0763168134531043E-11
matchValue=1.0763168134531043E-11
matchValue=4.892308780313215E-12
matchValue=1.0763168134531043E-11
matchValue=1.0763168134531043E-11
matchValue=1.0763168134531043E-11
matchValue=1.859090659195317E-11
matchValue=1.0763168134531043E-11
matchValue=1.0763168134531043E-11
matchValue=1.467714838554457E-11
matchValue=1.5655476914844257E-11
matchValue=1.0763168134531043E-11
matchValue=1.0763168134531043E-11
matchValue=1.467714838554457E-11
matchValue=1.467714838554457E-11
matchValue=1.5900170069471642E-11
matchValue=1.5900170069471642E-11
matchValue=1.467714838554457E-11
matchValue=1.467714838554457E-11
matchValue=1.5655476914844257E-11
matchValue=1.0763168134531043E-11
matchValue=1.5655476914844257E-11
matchValue=1.5655476914844257E-11
matchValue=1.0763168134531043E-11
matchValue=1.467714838554457E-11
matchValue=1.0763168134531043E-11
matchValue=1.9569457165857784E-11
matchValue=1.467714838554457E-11
matchValue=0.06707455246656768
matchValue=1.0518474979903658E-11
matchValue=5.137001934940599E-12
matchValue=1.0518474979903658E-11
matchValue=1.0518474979903658E-11
matchValue=5.137001934940599E-12

How I can use this output to get non-matching object list