You are here: Start » Program Examples » OCR Read Number
OCR Read Number
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 Blob Analysis to create various character's models.
Solution (FIS)
- In a separate program or in a macrofilter you will have to create an OCR model first. Create new global parameter and name it FileNames of StringArray type. The values will be names of consecutive images of characters.
- Add LoadImage filter and connect FileNames with inFile.
- Add ThresholdToRegion_Dynamic filter and connect outImage with inImage.
- Click on ThresholdToRegion_Dynamic filter and make these changes:
- Set inRadiusX to 10.
- Set inMaxRelativeValue to -68.
- Add MakeCharacterSamples filter.
- In inCharacters write 0123456789.
- Connect outRegion with inCharacterRegions.
- Add TrainOcr_MLP filter. Connect outCharacterSamples with inCharacterSamples. Click on the filter and make these changes in Properties window:
- Set inNormalizationSize.Height to 24.
- Set inRandomSeed to 123456.
- Set inCharacterFeatures.NormalizedPixels to True.
- Set inCharacterFeatures.Convexity to True.
- Set inCharacterFeatures.Circularity to True.
- Set inLearningRate to 0.8.
- Set inMomentum to 0.7.
- Set inIterationCount to 1250.
- Set inCharacterSize.Width to 24.
- Set inCharacterSize.Height to 36.
- Add SaveObject filter. Connect outOcrModel with inObject.
- Save the model as Font_MLP in inFile. Now you can close your program or macrofilter.
- Create the right application and add EnumerateImages filter.
- Add ThresholdToRegion_Dynamic filter. Connect outImage with inImage.
- Click on ThresholdToRegion_Dynamic filter and make these changes in Properties window (in the lower left corner):
- Set inRadiusX to 10.
- Set inMaxRelativeValue to -30.
- Add SplitRegionIntoMultipleCharacters filter. Connect outRegion with inRegion.
- Click on SplitRegionIntoMultipleCharacters filter. Set inCharacterWidth to 24.
- Add RecognizeCharacters filter.
- Connect outRegions with inCharacterRegions.
- Click on the filter and set inCharacterSize.Width to 24 and set inCharacterSize.Height to 36.
- In inOcrModel choose the earlier-created model Font_MLP.
Macrofilter Main
Macrofilter TrainCharacters
Used Filters
Icon | Name | Description |
---|---|---|
![]() |
TrainOcr_MLP | Trains an OCR multilayer perceptron classifier. |
![]() |
EnumerateImages | Emulates image acquisition with images stored on disk. |
![]() |
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. |
![]() |
RecognizeCharacters | Usually the last, yet the most important step of optical character recognition or verification. |
![]() |
LoadImage | Loads a single image from a file. |
![]() |
SaveObject | Saves an object to a file. |
Further Readings
- Optical Character Recognition - Detailed article explaining Optical Character Recognition technique.