Detect license plate

asked 2017-03-23 05:38:54 -0600

Tomna gravatar image

updated 2017-03-29 13:22:12 -0600

ok i am working on how to detect the plate on different image sizes so i have read from this link that there is technique as follow link

    1.Rectangle check   
     Checking that the candidate regions for plate had rectangle shape by compare white pixels count of these regions to their areas with ±5% tolerance  
 If count of white pixels = ±5% area of these region   
This region may be a plate 
  Else This region not a plate
     2. Plate dimension check 
 The Egyptian plate had a fixed dimension with height equal to 17 cm and width equal to 32 cm, so the ratio between heights to width approximately 1:2.   After rectangle check, the dimension check applied of the succeed regions of rectangle shapes, 
 If 1.5 < width/height of the succeed region <2.5    
            This region may be a plate   
              Else This region not a plate

so after findcontours such if conditions should be applies and here is my code

Mat hierarchy = new Mat();
        Imgproc.findContours(image_threshold.clone(), contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_NONE);

//        Rect rectCrop = new Rect();
        Mat m = new Mat();
        for (MatOfPoint contour : contours) {

            Rect rec = Imgproc.boundingRect(contour);

            if (hierarchy.size().height > 0 && hierarchy.size().width > 0) {
                for (int i = 0; i < contours.size(); i++) {

                    if (verifysize(rec)) {
                        System.out.println("first test");
                        Core.extractChannel(contour, m, 0);
                        int n = Core.countNonZero(m);
                        float area = (float) (rec.size().height * (float) rec.size().width); 
                        int minarea = (int) area - (int) (area / 100 * 6);
                        int maxarea = (int) area + (int) (area / 100 * 6);
                        if (minarea < n || n < maxarea) {
                            System.err.println("second test");
//                            Imgproc.drawContours(image, contours, i, new Scalar(0, 0, 255), -1, 8, hierarchy, 0, new Point());
                            Imgproc.rectangle(image, rec.tl(), rec.br(), new Scalar(0, 0, 255), 3);
//                        rectCrop = new Rect(rec.x, rec.y, rec.width, rec.height);
                        }
                    }
                }

            }
            Imgcodecs.imwrite("/home/tomna/NetBeansProjects/MainClass/src/mainclass/121.jpg", image);
        }

public static boolean verifysize(Rect re) {

    float ratio = (float) re.size().width / (float) re.size().height;
    if (1.5 > ratio || ratio > 2.5) {
        return false;
    } else {
        return true;
    }

}
edit retag flag offensive close merge delete

Comments

1

(float) (re.size().width / re.size().height); <-- please cast to float before dividing, like:

(float) (re.size().width) / (float)(re.size().height);

then, your "region" is actually the "aspect" or "ratio". region would be width*height

berak gravatar imageberak ( 2017-03-23 10:56:52 -0600 )edit

apart from that, -- any problem or error ? what is your question ?

berak gravatar imageberak ( 2017-03-23 11:01:10 -0600 )edit

my question is how to detect the plate depending on the image different size or distance of the plate? check the samples provided

Tomna gravatar imageTomna ( 2017-03-23 11:06:44 -0600 )edit

i will edit this question explaining more

Tomna gravatar imageTomna ( 2017-03-23 11:08:57 -0600 )edit
1

@berak edited i hope this is better

Tomna gravatar imageTomna ( 2017-03-23 11:54:29 -0600 )edit

@berak any ideas ?

Tomna gravatar imageTomna ( 2017-03-25 06:11:26 -0600 )edit

@berak i edited the whole question could see if you can help i really don't want to add a new question :D

Tomna gravatar imageTomna ( 2017-03-29 14:29:36 -0600 )edit