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.
- 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.
- Create a new Task macrofilter and name it TrainCharacters. Add LoadImage filter.
- Add FindFiles filter before the LoadImage filter and set inStartDirectory to Characters in order to get all images necessary for training.
- Connect outFileNames with inFile.
- 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).
- 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.
- 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. It is used for joining samples with corresponding characters. 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. The changes above are necessary to distinguish the characters by the SVM algorithm.
- Add SaveObject and connect outOcrModel with inObject. Set inFile to Font_SVM.avdata.
- Create the main 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.
- Add RecognizeCharacters filter.
|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.|