OCR recognition & training characters of Halcon image

2.1 Process and method of identifying OCR

Process the image so that numbers or letters are black on a white background -> create a character recognition handle -> recognize -> clear the handle

       Operator: read_ocr_class_mlp( : : FileName : OCRHandle)

示例:read_ocr_class_mlp ('Document_0-9A-Z_NoRej.omc', OCRHandle)

'Document_0-9A-Z_NoRej.omc' (input control parameter): input recognition type

OCRHandle (output control parameter): output recognition handle

      

算子:do_ocr_multi_class_mlp(Character, Image : : OCRHandle : Class, Confidence)

示例:do_ocr_multi_class_mlp (ObjectSelected, ImageInvert, OCRHandle, Class, Confidence)

ObjectSelected (input object): input recognition area

ImageInvert(input object): input recognition image

OCRHandle (input parameter): input handle

Class (input object): output recognized characters

Confidence (output parameter): the similarity of the output recognition

Operator: comment( : : Comment : )

Example: clear_ocr_class_mlp(OCRHandle)

OCRHandle (input control parameter): input recognition handle

2.2 Process and method of training character recognition library files

1. Extract the characters in the image ->

2. Add each character to the training file (append_ocr_trainf) ->

3. Deduplication (uniq) ->

4. Create a multilayer perceptron (create_ocr_class_mlp) ->

5. Create a new OCR classifier (trainf_ocr_class_mlp) using a multi-layer perceptron ->

6. Write the OCRHandle of the OCR grader to the FileName (file name) of the file (write_ocr_class_mlp) ->

7. Training character file ->

8. Read the trained file to generate the recognized classifier handle read_ocr_class_mlp ->

9. Character recognition: recognize a single character (do_ocr_single_class_mlp), recognize multiple characters (do_ocr_multi_class_mlp) ->

10. Close the classifier handle (clear_ocr_class_mlp)

**************************detailed steps**********************

2. Add each character to the training file (append_ocr_trainf)

算子:append_ocr_trainf(Character, Image : : Class, TrainingFile : )

示例:append_ocr_trainf (ObjectSelected, ImageReduced, tuple[Index], 'train_ocr'+'.trf')  

ObjectSelected (input object 1): character Regio

ImageReduced (input object 2): Character Image

Tuple (input control parameter 1): character text

'train_ocr'+'.trf' (input control parameter 2): OCR training .trf file path

Example: chans:=uniq(sort(tuple))

Tuple (input control parameter): charset array

3. Weight removal (uniq)

Example: chans:=uniq(sort(tuple))

Tuple (input control parameter): charset array

4. Create a multilayer perceptron using (create_ocr_class_mlp)

算子:create_ocr_class_mlp( : : WidthCharacter, HeightCharacter, Interpolation, Features, Characters, NumHidden, Preprocessing, NumComponents, RandSeed :OCRHandle)

示例:create_ocr_class_mlp (8, 10, 'constant', 'default', chans, 80, 'none', 10, 42, OCRHandle)

8 (input control parameter 1): character width (default)

10 (input control parameter 2): character width (default)

'constant' (input control parameter 3): character scaling style (default)

'default' (input control parameter 4): features for classification (default)

Chans (input control parameter 5): all characters of the character set to be read

80 (input control parameter 6): number of hidden units for MLP (default)

'none' (input control parameter 7): type of preprocessing used to transform feature vectors (default)

10 (input control parameter 8): preprocessing parameter: the number of transformation features (default)

42 (input control parameter 9): The seed value of the random number generator used to initialize the MLP with random values. (default)

OCRHandle (output control parameter): the handle of the output OCR classifier

5. Create a new OCR classifier using a multilayer perceptron (trainf_ocr_class_mlp)

算子:trainf_ocr_class_mlp( : : OCRHandle, TrainingFile, MaxIterations, WeightTolerance, ErrorTolerance : Error, ErrorLog)

Example: trainf_ocr_class_mlp (OCRHandle, 'train_ocr.trf', 200, 1, 0.01, Error, ErrorLog)

OCRHandle (input control parameter 1): the handle of the OCR classifier

'train_ocr.trf' (input control parameter 2), : training file name

200 (input control parameter 3): the maximum number of iterations of the optimization algorithm (default)

1 (input control parameter 4): Threshold for the difference in MLP weights between two iterations of the optimization algorithm (default)

0.01 (input control parameter 5): The threshold of the average error of the MLP on the training data for two iterations of the optimization algorithm. (default)

Error (input control parameter 6): the average error of the MLP in the training data (default)

ErrorLog (input control parameter 7): The average error of the MLP on the training data as a function of the number of iterations of the optimization algorithm. (default)

6. Write the OCRHandle of the OCR grader to the FileName (file name) of the file

Operator: write_ocr_class_mlp( : : OCRHandle, FileName : )

Example: write_ocr_class_mlp(OCRHandle, 'train_ocr')

OCRHandle (input control parameter 1): the handle of the OCR classifier

'train_ocr' (input control parameter 2): save OCR's .omc classifier to file

7. Training character file

8. Read the trained file to generate the recognized classifier handle read_ocr_class_mlp

Operator: read_ocr_class_mlp( : : FileName : OCRHandle)

Example: read_ocr_class_mlp ('C:/Users/Administrator/Desktop/Learning Folder/Exercise/Exercise 11/train_ocr.omc', OCRHandle1)

       'C:/Users/Administrator/Desktop/Learning Folder/Exercise/Exercise 11/train_ocr.omc' (input control parameters): Enter the address of the trained file

       OCRHandle1 (output control parameter): the handle of the output OCR classifier

9. Character recognition: recognize a single character (do_ocr_single_class_mlp), recognize multiple characters (do_ocr_multi_class_mlp)

identify a single

算子:do_ocr_single_class_mlp(Character, Image : : OCRHandle, Num : Class, Confidence)

示例:do_ocr_single_class_mlp (SortedRegions1, ImageScaled2, OCRHandle1, 1, Class1, Confidence1)

SortedRegions1 (input object 1): Enter the character region to be recognized

ImageScaled2 (input object 2): Input the image to be recognized

OCRHandle1 (input control parameter 1): the handle of the input OCR classifier

1 (input control parameter 2): Enter the number of best classes to determine (default)

Class1 (input control parameter 3): output the result of classifying characters using MLP (default)

Confidence1 (input control parameter 4): output character recognition score (default)

Identify multiple:

算子:do_ocr_multi_class_mlp(Character, Image : : OCRHandle : Class, Confidence)

示例:do_ocr_multi_class_mlp (ObjectSelected1, ImageScaled2, OCRHandle1, Class, Confidence)

ObjectSelected1 (input object 1): Enter the character area to be recognized

ImageScaled2 (input object 2): Input the image to be recognized

OCRHandle1 (input control parameter 1): the handle of the input OCR classifier

Class (input control parameter 2): Output the result of MLP classifying characters (default)

Confidence (input control parameter 3): output character recognition score (default)

10. Close the classifier handle (clear_ocr_class_mlp)

Operator: clear_ocr_class_mlp( : : OCRHandle : )

Example: clear_ocr_class_mlp (OCRHandle1)

OCRHandle1 (input control parameter): classifier handle

Guess you like

Origin blog.csdn.net/a296026640/article/details/130339825