Recent

Author Topic: How to write a license plate recognition program?  (Read 9492 times)

Max170702

  • Newbie
  • Posts: 3
How to write a license plate recognition program?
« on: March 20, 2019, 01:44:07 pm »
Hello,

In my internship I have to write a program for license plate recognition. I have never worked with Pascal or Lazarus before. After I managed to filter out the number plate on a picture quite clearly (binarize, crop etc. ) I want to write an algorithm that recognizes the letters and numbers of the number plate. But I have never written an algorithm and unfortunately I have no idea where to start. That's why I'm here looking for help. Where do I best start? And what do I even have to do to write an algorithm?

Max

Ps:
If I should have some mistakes in the text I am sorry but I come from Germany and my English is partly still to be improved. (I would write in a german forum but I find only a decent one, where the registration is not possible at the moment.) :)
« Last Edit: March 22, 2019, 12:13:14 pm by Max170702 »

stab

  • Full Member
  • ***
  • Posts: 234
Re: how to write an algorithm that recognizes letters on images?
« Reply #1 on: March 20, 2019, 02:03:47 pm »
You don't thing you would get along well with a free OCR program like
Microsofts Free OCR software.
https://www.microsoft.com/en-us/p/a9t9-free-ocr-software/9nblgggz5nsn?activetab=pivot:overviewtab

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: how to write an algorithm that recognizes letters on images?
« Reply #2 on: March 20, 2019, 02:33:22 pm »
I have never written an algorithm and unfortunately I have no idea where to start. That's why I'm here looking for help. Where do I best start? And what do I even have to do to write an algorithm?
You have been given an impossible task.
An algorithm is written by breaking down a task into a series of steps each of which is simple enough to translate into computer code.
You learn to write algorithms by analysing simple tasks, and looking at code which more experienced programmers have devised to analyse exactly what those simple steps are, and how they have translated those steps into code that can be communicated to a computer to execute them.
Character recognition based on a given picture file is an immensely complex task. It is not the place to start learning about algorithms. It requires far too much background in analysis of graphic designs and formats.
The best you can hope for as a beginner is to be able to use OCR libraries or programs devised by others to achieve your end.

Max170702

  • Newbie
  • Posts: 3
Re: how to write an algorithm that recognizes letters on images?
« Reply #3 on: March 20, 2019, 03:13:07 pm »
Since the internship is only designed for Lazarus I will probably not be allowed to work with OCR but thanks for the answers and maybe I can get another acceptable solution. :)

six1

  • Full Member
  • ***
  • Posts: 117
Re: how to write an algorithm that recognizes letters on images?
« Reply #4 on: March 20, 2019, 03:32:17 pm »
I'm using tesseract OCR with great success.
Calling tesseract.exe from my lazarus app and getting result from rtf textfile is an easy going.

https://github.com/tesseract-ocr/tessdata

call: [path to file]tesseract.exe "pictureFileName" "FilenameTextfile.txt" -l deu+eng

Zvoni

  • Hero Member
  • *****
  • Posts: 2300
Re: how to write an algorithm that recognizes letters on images?
« Reply #5 on: March 20, 2019, 03:36:41 pm »
usually, i compare an algorithm to a recipe for baking a pie
prepare bowl
take 4 eggs
crack the eggs above the bowl
Repeat
Put Flour into the bowl
until EnoughFlour=True
Repeat
Put water into the bowl
until EnoughWater=True
Call Procedure "MixItTogether"
and so on....

As for the initial problem with registration-plate-recognizing: that's a tall order for a beginner.
It basically boils down to pattern-recognition (and in that context neural networks, too)

EDIT: Found something
https://pdfs.semanticscholar.org/fcc8/8283fcf636fa0a449718e18c969c05dd4b7c.pdf
« Last Edit: March 20, 2019, 03:41:03 pm by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: how to write an algorithm that recognizes letters on images?
« Reply #6 on: March 20, 2019, 04:11:21 pm »
Hello,

In my internship I have to write a program for license plate recognition. I have never worked with Pascal or Lazarus before. After I managed to filter out the number plate on a picture quite clearly (binarize, crop etc. ) I want to write an algorithm that recognizes the letters and numbers of the number plate. But I have never written an algorithm and unfortunately I have no idea where to start. That's why I'm here looking for help. Where do I best start? And what do I even have to do to write an algorithm?

Max

Ps:
If I should have some mistakes in the text I am sorry but I come from Germany and my English is partly still to be improved. (I would write in a german forum but I find only a decent one, where the registration is not possible at the moment.) :)
Basic letter recognition algorithm isn't that complex. Just isolate glyphs and then perform per-pixel comparison with some sort of template glyphs. Such comparison shouldn't be just = or =/=. It should calculate some sort of score, i.e. what % of pixels match. Glyph with best % wins. At the same time this max % shows, how confident you can be about this result. Lower % means, that quality of text is bad, so you can't be sure about results. As simple, as that. If text, you'll need to recognize, will have good enough quality - match ratio will also be good enough to complete this task.
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

mr-highball

  • Full Member
  • ***
  • Posts: 233
    • Highball Github
Re: how to write an algorithm that recognizes letters on images?
« Reply #7 on: March 20, 2019, 04:58:34 pm »
lazarus / delphi bindings and examples for such a task:
https://github.com/r1me/TTesseractOCR4

dogriz

  • Full Member
  • ***
  • Posts: 126
Re: how to write an algorithm that recognizes letters on images?
« Reply #8 on: March 20, 2019, 06:08:29 pm »
Complete solution written in C++ https://github.com/openalpr/openalpr
Browse the documentation to see all the complexity of LPR system.
FPC 3.2.2
Lazarus 2.2.4
Debian x86_64, arm

Thaddy

  • Hero Member
  • *****
  • Posts: 14169
  • Probably until I exterminate Putin.
Re: how to write an algorithm that recognizes letters on images?
« Reply #9 on: March 20, 2019, 07:44:50 pm »
Our resident AI expert has written a library that does just that. Have to look it up but it is on the forum.
Specialize a type, not a var.

Max170702

  • Newbie
  • Posts: 3
Re: how to write an algorithm that recognizes letters on images?
« Reply #10 on: March 22, 2019, 12:06:09 pm »
I have now marked the EU sign on the number plates with a blue filter. I would now like to scan the area around the blue marked pixels so that the license plate is filtered out and I can cut it out accordingly. But how can you scan the perimeter of a pixel for a color?

Gizmo

  • Hero Member
  • *****
  • Posts: 831
Re: How to write a license plate recognition program?
« Reply #11 on: March 22, 2019, 02:30:45 pm »
I have also been looking for a Freepascal library for OCR. Not for number plates, but for scanning normal picture files like JPEGS and creating text based output of any recognised letters\words.

There used to be (back in 2011!) a FPC conversion of Tesseract here (https://code.google.com/archive/p/ocrivist/source) but it has since been taken down.

Does anyone know of an active, useable OCR library for Freepascal which could help both the OP and myself?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11352
  • FPC developer.
Re: How to write a license plate recognition program?
« Reply #12 on: March 22, 2019, 04:31:51 pm »
I asked my boss who did old skool vision, and he said that easiest is to make vertical and horizontal projections of every characters and store the patters for the different digits.

If you first make the vertical projection, you can use that to separate the digits, and then run the horizontal ones per digit.

Maybe you can even use the data that you already found (the EU logo) as a rough measure for the to be expected size of the digits.

This works if the digits are not too slanted.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: How to write a license plate recognition program?
« Reply #13 on: March 22, 2019, 05:06:55 pm »
This works if the digits are not too slanted.

And even that can be corrected if you can isolate the EU symbol and measure its slant, since the plate is (supposedly) a plain rectangle.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11352
  • FPC developer.
Re: How to write a license plate recognition program?
« Reply #14 on: March 22, 2019, 09:24:56 pm »
All depends on border conditions, I guess.

If you start with a bounding box in the inner part of the license plate (uniform background with just letters), you'd probably use some form of edge over the full width to measure slant.

If you have nothing, and you can get the EU logo from a color channel, that might be your best bet.

 

TinyPortal © 2005-2018