Find the plate rectangle in this image

This is my original painting, and I want to find a plate to look for the number plate in this rectangle instead of looking for the whole picture
Original image test_1.jpg:

enter image description here

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 resulting image - test_2.jpg looks like this:

enter image description here

and adding this code specifying the thresholdImg 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); } 

Final image test_3.jpg:

enter image description here

Is there any picture of what I generated that I can use to continue my code to find the rectangle containing the plate in the image.

+8
java image-processing opencv javacv
source share
2 answers

You are going in the right direction.

  • You will need to do some kind of smooth / blur before the image threshold to eliminate unwanted noise

  • Apply threshold to image as you are doing now

  • Use the openCv extended library extension function to expand your detected edges a bit. This is useful because when the license plate characters are expanded, they will sort the filling of the rectangle in which they are contained.

  • openCV has a cvRectangle function that searches for rectangular shapes in an image. There are many documents online to help you use.

  • Finally, you will want to filter out the found rectangular shapes that are candidates for the license plate based on the ratio (width / height) and area (width * height). For example, the Portuguese license plates, at least in my test images, had a ratio between 2 and 3.5 and an area of ​​about 5000-7000 pixels. Obviously, this depends on the shape of the license plate, image size, etc.

I assure you that this approach works. I used it myself, and he found the license plate area in 99.5% of the car photos I had for testing.

One thing you might want to do is use the Sobel filter (also available in the opencv library) to the threshold if your images are too bright. This implies a change only in step 2, the rest remain unchanged.

Hope I helped :)

+4
source share

Chapter 5 Mastering OpenCV with practical projects in the field of computer vision addresses this exact problem, dividing the task into 2 main stages: segmentation and classification of segments .

enter image description here

I do not want to go into details, since you can read it in a book, but the C ++ code for this project is freely available for download.

+2
source share

All Articles