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

OCR Read Number (SVM)


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


Several images of numbers.


Detected numbers in the image and recognized characters.


To identify the characters in the image it is recommended to use Optical Character Recognition technique. In this case we will use the SVM algorithm of training.

Solution (AVS)

  1. First of all you have to create an OCR model. You can do it in a separate Task macrofilter or a separate program. In this case we will show the first way, so follow the steps below.
  2. Create a new Task macrofilter and name it TrainCharacters. Add LoadImage filter.
  3. Add FindFiles filter before the LoadImage filter and set inStartDirectory to Characters in order to get all images necessary for training.
  4. Connect outFileNames with inFile.
  5. Add ThresholdToRegion_Dynamic filter or ThresholdToRegion filter (basically, the difference between them is about the background homogeneity - the dynamic variant will deal better with cases where foreground and background are quite similar).
  6. Create a new Step macrofilter and name it MakeCharacterVariations. Add new input inCharacters and connect it with outRegion. Thanks to creating this Step macrofilter, we will have all possible variations in one place. What's more we can join them in one array and pass it on the input of the MakeCharacterSamples filter.
  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. It is used for joining samples with corresponding characters. 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 main 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.
FindFiles Returns files of the input directory.

Further Readings