1
votes

I working on a project that will read licence plates, my plan is

  1. Converting the image to grayscale for better performance
  2. Use Histogram equalizer to bring out the licence plate characters
  3. Blur the image to remove some noise
  4. Use adaptive threshold to binaries the image
  5. Use open and close morphology
  6. Detect the rectangular bounding box for the licence plate

Well, the issue is: my code is not so good, the result is so bad I cannot detect the rectangle, below is my code:

Imgproc.cvtColor(image, image, Imgproc.COLOR_BGR2GRAY, 0);
    Imgproc.blur(image, image, new Size(3, 3));
    Imgproc.equalizeHist(image, image);
    Mat openElem = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(1, 1));
    Mat closeElem = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(1, 1));
    Imgproc.adaptiveThreshold(image, image, 225, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY_INV, 11, 2);

The input image:

input image

The output image:

Output image

If anyone with experience would help I will appreciate

2

2 Answers

2
votes

In the first is better to detect the plate position in the image, just follow steps below:

  1. Convert to gray

    cvCvtColor(image, grayScale, CV_BGR2GRAY);

enter image description here

  1. Do sobel

    Mat sobel = new Mat(grayScale.size(), CvType.CV_16S); cvSobel(grayScale, sobel, 2, 0, 7); Mat temp = new Mat(sobel.size(), CvType.CV_8UC1); convertScaleAbs(sobel, temp, 0.00390625, 0);

enter image description here

  1. Do threshold

    cvThreshold(sobel, threshold, 0, 255, CV_THRESH_BINARY| CV_THRESH_OTSU);enter image description here

  2. Do morphology

    Mat kernal = cvCreateStructuringElementEx(3,1, 1, 0, CV_SHAPE_RECT); cvDilate(threshold, erode_dilate, kernal, 2);//X vErode(erode_dilate, erode_dilate, kernal, 4);//X cvDilate(erode_dilate, erode_dilate, kernal, 2);//X

    kernal = cvCreateStructuringElementEx(1, 3, 0, 1, CV_SHAPE_RECT); cvErode(erode_dilate, erode_dilate, kernal, 1);// Y cvDilate(erode_dilate, erode_dilate, kernal, 2);

enter image description here

  1. Now you are able to detect the rectangle in the image:

enter image description here

  1. Then you can process the plate for OCR

Hope it helps you!

0
votes

Ok so this is what I came up with

Imgproc.cvtColor(image, image, Imgproc.COLOR_BGR2GRAY, 0);
    originalFrameGrayScale = image.clone();

    Mat morph = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(9, 3));
    Imgproc.morphologyEx(image, image, Imgproc.MORPH_TOPHAT, morph);
    Imgproc.Sobel(image, image, -1, 2, 0);
    Imgproc.GaussianBlur(image, image, new Size(5,5), 3,3);
    Imgproc.morphologyEx(image, image, Imgproc.MORPH_CLOSE, morph);
    Imgproc.threshold(image, image, 200, 255, Imgproc.THRESH_OTSU);
    Vector<Rect> rectangles = detectionContour(image);

And find the greatest contour with height, width and area matching certain values enter image description here