Ask Your Question
0

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

asked 2016-11-03 01:19:44 -0600

Karanbeer Kaur gravatar image

updated 2016-11-03 01:22:26 -0600

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);
    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

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-11-03 02:18:56 -0600

berak gravatar image

your list looks like you're missing some pre-processing, you should binarize the grayscale images before findContours (threshold/canny or such) and filter the found contours for size (boundingRect()) to remove very small (like 1 pixel noise) contours

it might be helpful, to visualize your temporary steps, like the binary images & the contours (drawContours), in most cases you can already "see", what's wrong.

then, you need to find an (experimental) threshold value, so any result from matchShapes larger than that is considered non-matching. this depends on your data, and your processing.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-11-03 01:19:44 -0600

Seen: 880 times

Last updated: Nov 03 '16