Detect license plate
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;
}
}
(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
apart from that, -- any problem or error ? what is your question ?
my question is how to detect the plate depending on the image different size or distance of the plate? check the samples provided
i will edit this question explaining more
@berak edited i hope this is better
@berak any ideas ?
@berak i edited the whole question could see if you can help i really don't want to add a new question :D