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 (FIS)
- 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.
- Add LoadImage filter.
- Create new global parameter and name it FileNames of StringArray type. The values will be names of consecutive images of characters.
- Connect FileNames with inFile.
- Add ThresholdToRegion_Dynamic filter and:
- Connect outImage with inImage.
- Set inRadiusX to 10.
- Set inMaxRelativeValue to -68.
- Create a new macrofilter and name it MakeCharacterVariations. Connect outRegion to it and name the input inCharacters.
- Get inside and add DilateRegion filter. Set inKernel to Ellipse.
- Connect inCharacters with inRegion.
- Add ErodeRegion filter. Connect outRegion with inRegion.
- Add JoinArrays filter. Connect inCharacters, outRegion and outRegion to it.
- Connect outJoinedArray with macrofilter's output and name it outCharacters.
- Leave the macrofilter and add MakeCharacterSamples filter. Connect outCharacters macrofilter's output with inCharacterRegions.
- Set inCharacters to 012345678901234567890123456789.
- Add TrainOcr_SVM filter.
- Connect outCharacterSamples with inCharacterSamples.
- Set inNormalizationSize.Height to 24.
- Set inRegularizationConstant to 0.1.
- Set inUseShrinkingHeuristics to False.
- Set inCharacterSize.Width to 24 and inCharacterSize.Height to 36.
- Set inRandomSeed to 12345.
- Set inCharacterFeatures.NormalizedPixels to True.
- Set inCharacterFeatures.Orientation to True.
- Set inCharacterFeatures.HorizontalProject to True.
- Add SaveObject and connect outOcrModel with inObject. Set inFile to Font_SVM.fidata.
- Create the right application and add EnumerateImages filter.
- Add ThresholdToRegion_Dynamic filter and connect outImage with inImage.
- Set inRadiusX to 10 and set inMaxRelativeValue to -30.
- Add SplitRegionIntoMultipleCharacters filter.
- Connect outRegion with inRegion.
- Set inCharacterWidth to 24.
- Add RecognizeCharacters filter.
- Connect outRegions with inCharacterRegions.
- Connect your earlier created SVM model to inOcrModel.
- Set inCharacterSize.Width to 24 and inCharacterSize.Height to 36.
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
- Blob Analysis - Article presents detailed information about the Blob Analysis technique.
- Optical Character Recognition - Detailed article explaining Optical Character Recognition technique.