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.