6

I am writing an app using OpenCV 2.4.3.2 for Android.
my app is about license plate recognition.
there are a few ways to do it , I chose to do the following:

1. convert the image to HSV color space
2. threshold image according to license plate HSV (in my country they are yellow...)
3. smooth the image with a Gaussian Blur
4. Detect edges
5. find contours
6. fund houghlines
7. from the houglines, detect curves that match rectangle
I am stuck at 7, I can't find a way to successfully detect the rectangles from the houglines.

I would very much appreciate a code sample in Java, since most of the examples are in C/C++ and converting it is not so straightforward.
here is my code (right now I am just drawing the lines...):

Imgproc.cvtColor(inputFrame, mRGBMat, Imgproc.COLOR_RGBA2BGR);
// convert HSC color space
Imgproc.cvtColor(mRGBMat, mHSVMat, Imgproc.COLOR_BGR2HSV);
// Filter out colors which are out of range (license plate hue ~ 14)
            Core.inRange(mHSVMat, new Scalar(9, 70, 80, 0), new Scalar(30, 255,
                    255, 0), mGrayMat);
            // some smoothing of the image
            for (int i = 0; i < 10; i++) {
                Imgproc.GaussianBlur(mGrayMat, mGrayMat, new Size(9, 9), 2, 2);
            }
Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_DILATE,
                    new Size(3, 3), new Point(1, 1));
Imgproc.Canny(mGrayMat, mGrayMat0, 48, 120);
Imgproc.dilate(mGrayMat0, mGrayMat0, kernel);
kernel.release();
List<MatOfPoint> contours = new Vector<MatOfPoint>();
            Imgproc.findContours(mGrayMat0, contours, mHirerchy,
                    Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
            Mat lines = new Mat(); // finds houghlines in the contours
            Imgproc.HoughLinesP(mGrayMat0, lines, 1, Math.PI / 180, 1);
            for (int x = 0; x < lines.cols(); x++) {
                double[] vec = lines.get(0, x);
                double x1 = vec[0], y1 = vec[1], x2 = vec[2], y2 = vec[3];
                Point start = new Point(x1, y1);
                Point end = new Point(x2, y2);
                Core.line(mRgba, start, end, RECT_COLOR, 1);

            }
Orr
  • 4,740
  • 3
  • 28
  • 31

1 Answers1

0

I've written such an algorithm before. You classify the lines into two types: 1) vertical 2) horizontal x) outliers for deletion

Then you classify the lines more into two subtypes each: 1a) vertical, the left border 1b) vertical, the right border 1x) outliers for deletion 2a), 2b), 2x).

Get the average slopes and intercept points of these lines and you have your "rectangle".

Boyko Perfanov
  • 3,007
  • 18
  • 34