You are here: Start » Program Examples » OCR Read Number (SVM)

OCR Read Number (SVM)

Aim

The aim of the program is to recognize characters in an image.

Input

Several images of numbers.

Output

Detected numbers in the image and recognized characters.

Hints

To identify the characters in the image it is recommended to use Optical Character Recognition technique to recognize different characters with Region Morphology to create various character's models. In this variant we use the SVM method.

Solution (AVS)

  1. First of all you have to create an OCR model. You can do it in a separate macrofilter or a separate program, so make a new one.
  2. Add LoadImage filter.
  3. Create new global parameter and name it FileNames of StringArray type. The values will be names of consecutive images of characters.
  4. Connect FileNames with inFile.
  5. Add ThresholdToRegion_Dynamic filter and:
  6. Create a new macrofilter and name it MakeCharacterVariations. Connect outRegion to it and name the input inCharacters.
  7. Get inside and add DilateRegion filter. Set inKernel to Ellipse.
  8. Connect inCharacters with inRegion.
  9. Add ErodeRegion filter. Connect outRegion with inRegion.
  10. Add JoinArrays filter. Connect inCharacters, outRegion and outRegion to it.
  11. Connect outJoinedArray with macrofilter's output and name it outCharacters.
  12. Leave the macrofilter and add MakeCharacterSamples filter. Connect outCharacters macrofilter's output with inCharacterRegions.
  13. Set inCharacters to 012345678901234567890123456789.
  14. Add TrainOcr_SVM filter.
  15. Add SaveObject and connect outOcrModel with inObject. Set inFile to Font_SVM.avdata.
  16. Create the right application and add EnumerateImages filter.
  17. Add ThresholdToRegion_Dynamic filter and connect outImage with inImage.
  18. Set inRadiusX to 10 and set inMaxRelativeValue to -30.
  19. Add SplitRegionIntoMultipleCharacters filter.
  20. Add RecognizeCharacters filter.

Macrofilter Main

Macrofilter MakeCharacterVariations

Macrofilter TrainCharacters

Used Filters

Icon Name Description
EnumerateImages Emulates image acquisition with images stored on disk.
JoinArrays Concatenates the input arrays one after another.
ThresholdToRegion_Dynamic Useful in case of uneven illumination.
SplitRegionIntoMultipleCharacters Text segmentation when the number of characters is unknown, usually followed by a RecognizeCharacters filter.
MakeCharacterSamples Creates training font samples from the provided regions.
TrainOcr_SVM Trains an OCR support vector machines classifier.
RecognizeCharacters Usually the last, yet the most important step of optical character recognition or verification.
ErodeRegion Making the region thinner or removing small parts.
DilateRegion Making the region thicker or filling-in small holes within it.
LoadImage Loads a single image from a file.
SaveObject Saves an object to a file.

Further Readings