Question

Work done

I try to detect and read a license plate with these steps:

1) Detect a quadrilateral by using houghlines (already got this problem with this step, sorry)
2) Correct the perspective of this quadrilateral to a rectangle
3) Perform OCR on this rectangle

You can see the visual problem/effect of my code here.
The code itself can be found here.

disclaimer: I use Emgu CV for this, but if someone is kind enough to answer me, I don't want to bother him or her to give me an answer for this wrapper specifically.

public string loadImage()
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.ShowDialog();
            String s = ofd.FileName.Normalize();
            return s;
        }

public void processImage()
        {
            String s = loadImage();
            Image<Gray, Byte> img = new Image<Gray, byte>(s);
            Console.WriteLine("read file @" + s);

            Image<Gray, Byte> tinyGrayImg = img.Resize(0.25, INTER.CV_INTER_NN);
            CvInvoke.cvShowImage("original gray", tinyGrayImg);
            Console.WriteLine("converted " + s + " to grayscale");

            Image<Gray, Byte> canny = new Image<Gray, byte>(CvInvoke.cvGetSize(tinyGrayImg));
            CvInvoke.cvCanny(tinyGrayImg, canny, 97, 225, 3);
            CvInvoke.cvShowImage("canny", canny);
            Console.WriteLine("applied Canny to " + s);

            try
            {
                MemStorage mem = new MemStorage();
                Image<Bgr, byte> linesImg = canny.Convert<Bgr, byte>();
                IntPtr lines = CvInvoke.cvHoughLines2(canny, mem.Ptr, HOUGH_TYPE.CV_HOUGH_PROBABILISTIC, 1, Math.PI /   180, 70, 30, 10);
                Seq<LineSegment2D> segments = new Seq<LineSegment2D>(lines, mem);
                LineSegment2D[] segArray = segments.ToArray();

                for (int i = 0; i < segArray.Length; i++)
                {
                    linesImg.Draw(segArray[i], new Bgr(Color.Red), 1);
                }
                CvInvoke.cvShowImage("lines", linesImg);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

Problem

As you can see in the attached image (I don't have enough karma for direct adding images) the HOUGH_PROBABILISTIC filter does not work as I expected and I have no idea why the edges of the license plate aren't recognised. Any idea how to reach my goal is welcome.

Was it helpful?

Solution

The Hough transform is not perfect. It will detect lines following it's very simple algorithm and I can assure you that the result that you got is very good.

Now, you need to filter the result. For example, if you know that the line will always be in some angles, remove the rest. If you know they will be of some lenght, remove everything smaller.

If it's not enough, maybe the canny transform that you did at the beginning is not enought. Maybe you need to have a Region of interest (ROI) based on color (white plate). Or maybe you could use blob detection to find white object. Everything that you know as a constant should be used in computer vision. Using a single algorithm like the Hough transform can help but it will not find everything automatically, you need to help it!

Hope it helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top