This is my original picture and i want to find the plate in order to search for the number plate in this rectangle instead of searching in whole picture
original image test_1.jpg:
using the following code in javacv:
IplImage originalImage = cvLoadImage("test_1.jpg");
IplImage resultImage = IplImage.create(originalImage.width(),
originalImage.height(), IPL_DEPTH_8U, 1);
cvCvtColor(originalImage, resultImage, CV_BGR2GRAY);
cvAdaptiveThreshold(resultImage, resultImage, 255, CV_ADAPTIVE_THRESH_GAUSSIAN_C, CV_THRESH_BINARY_INV, 7, 7);
cvSaveImage("test_2.jpg", resultImage);
The resultant picture is test_2.jpg looks like this:
and adding this code by giving thresholdImg the resultImg
static void findLines(IplImage thresholdImg)
{
IplImage dst;
IplImage colorDst;
dst = cvCreateImage(cvGetSize(thresholdImg), thresholdImg.depth(), 1);
colorDst = cvCreateImage(cvGetSize(thresholdImg), thresholdImg.depth(), 3);
cvCanny(thresholdImg, dst, 100, 200, 3);
CvSeq lines = new CvSeq();
CvMemStorage storage = cvCreateMemStorage(100000);
cvSaveImage("test_3.jpg", dst);
}
The resultant picture test_3.jpg :
Is there any picture of what i generated can be used for continuing my code in order to find the rectangle containing the plate in the image
You're going in the right direction.
You will want to perform a smooth/blur of some kind before thresholding the image, in order to eliminate unwanted noise
Apply threshold to the image like you are doing now
Use the openCv library's dilate function to slightly dilate your detected edges. This is useful because once the license plate's characters are dilated, they will sort of fill the rectangle in which they are contained
openCV has a function called cvRectangle that searches for rectanglular shapes in the image. There's plenty of documenation online to assist you in using it
Finally, you'll want to filter the rectangular shapes found that are license plate candidates based on ratio (width / height) and area (width * height). For example, portuguese license plates, at least in my test images, had a ratio between 2 and 3.5 and an area of around 5000-7000 pixels. Obviously this depends on the license plate's shape, the image size, etc..
I assure you this approach works. I've used it myself and it detects the license plate area in 99.5% of the vehicle photos I had for tests.
One thing you might want to do is use a Sobel filter (also available in the opencv library) before the threshold, if your pictures are too bright. That implies a change only in step 2, the others stay the same.
Hope I was of help :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With