create_ocr_class_svm — Create an OCR classifier using a support vector machine.
create_ocr_class_svm creates an OCR classifier that uses a support vector machine (SVM). The handle of the OCR classifier is returned in OCRHandle.
For a description on how an SVM works, see create_class_svm. create_ocr_class_svm creates an SVM for classification with the classification mode given by Mode. The length of the feature vector of the SVM (NumFeatures in create_class_svm) is determined from the features that are used for the OCR, which are passed in Features. The features are described below. The kernel is parametrized with KernelType, KernelParam and Nu like in create_class_svm. The number of classes of the SVM (NumClasses in create_class_svm) is determined from the names of the characters to be used in the OCR, which are passed in Characters. As described with create_class_svm, the parameters Preprocessing and NumComponents can be used to specify a preprocessing of the data (i.e., the feature vectors). For the sake of numerical stability, Preprocessing can typically be set to 'normalization'. In order to speed up classification time, 'principal_components' or 'canonical_variates' can be used, as the number of input features can be significantly reduced without deterioration of the recognition rate.
The features to be used for the classification are determined by Features. Features can contain a tuple of feature names. Each of these feature names results in one or more features to be calculated for the classifier. Some of the feature names compute gray value features (e.g., 'pixel_invar'). Because a classifier requires a constant number of features (input variables), a character to be classified is transformed to a standard size, which is determined by WidthCharacter and HeightCharacter. The interpolation to be used for the transformation is determined by Interpolation. It has the same meaning as in affine_trans_image. The interpolation should be chosen such that no aliasing effects occur in the transformation. For most applications, Interpolation = 'constant' should be used. It should be noted that the size of the transformed character is not chosen too large, because the generalization properties of the classifier may become bad for large sizes. In particular, for large sizes small segmentation errors will have a large influence on the computed features if gray value features are used. This happens because segmentation errors will change the smallest enclosing rectangle of the regions, thus the character is zoomed differently than the characters in the training set. In most applications, sizes between 6x8 and 10x14 should be used.
The parameter Features can contain the following feature names for the classification of the characters.
'ratio' and 'pixel_invar' are selected.
Gray values of the character (WidthCharacter x HeightCharacter features).
Gray values of the character with maximum scaling of the gray values (WidthCharacter x HeightCharacter features).
Region of the character as a binary image zoomed to a size of WidthCharacter x HeightCharacter (WidthCharacter x HeightCharacter features).
Gradients are computed on the character image. The gradient directions are discretized into 8 directions. The amplitude image is decomposed into 8 channels according to these discretized directions. 25 samples on a 5x5 grid are extracted from each channel. These samples are used as features (200 features).
Horizontal projection of the gray values (see gray_projections, HeightCharacter features).
Maximally scaled horizontal projection of the gray values (HeightCharacter features).
Vertical projection of the gray values (see gray_projections, WidthCharacter features).
Maximally scaled vertical projection of the gray values (WidthCharacter features).
Aspect ratio of the character (see height_width_ratio, 1 feature).
Anisometry of the character (see eccentricity, 1 feature).
Width of the character before scaling the character to the standard size (not scale-invariant, see height_width_ratio, 1 feature).
Height of the character before scaling the character to the standard size (not scale-invariant, see height_width_ratio, 1 feature).
Difference in size between the character and the values of WidthCharacter and HeightCharacter (not scale-invariant, 1 feature).
Fraction of pixels in the foreground (1 feature).
Fraction of pixels in the foreground in a 3x3 grid within the smallest enclosing rectangle of the character (9 features).
Fraction of pixels in the foreground in a 4x4 grid within the smallest enclosing rectangle of the character (16 features).
Compactness of the character (see compactness, 1 feature).
Convexity of the character (see convexity, 1 feature).
Normalized 2nd moments of the character (see moments_region_2nd_invar, 3 features).
Normalized 2nd relative moments of the character (see moments_region_2nd_rel_invar, 2 features).
Normalized 3rd moments of the character (see moments_region_3rd_invar, 4 features).
Normalized central moments of the character (see moments_region_central, 4 features).
Normalized gray value moments and the angle of the gray value plane (see moments_gray_plane, 4 features).
Orientation (angle) of the character (see elliptic_axis, 1 feature).
Number of connected components (see connect_and_holes, 1 feature).
Number of holes (see connect_and_holes, 1 feature).
Values of the binary cooccurrence matrix (see gen_cooc_matrix, 12 features).
Number of runs in the region normalized by the height (1 feature).
Frequency of the runs per row (not scale-invariant, HeightCharacter features).
After the classifier has been created, it is trained using trainf_ocr_class_svm. After this, the classifier can be saved using write_ocr_class_svm. Alternatively, the classifier can be used immediately after training to classify characters using do_ocr_single_class_svm or do_ocr_multi_class_svm.
A comparison of SVM and the multi-layer perceptron (MLP) (see create_ocr_class_mlp) typically shows that SVMs are generally faster at training, especially for huge training sets, and achieve slightly better recognition rates than MLPs. The MLP is faster at classification and should therefore be preferred in time critical applications. Please note that this guideline assumes optimal tuning of the parameters.
This operator returns a handle. Note that the state of an instance of this handle type may be changed by specific operators even though the handle is used as an input parameter by those operators.
Width of the rectangle to which the gray values of the segmented character are zoomed.
Default value: 8
Suggested values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 20
Typical range of values: 4 ≤ WidthCharacter ≤ 20
Height of the rectangle to which the gray values of the segmented character are zoomed.
Default value: 10
Suggested values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 20
Typical range of values: 4 ≤ HeightCharacter ≤ 20
Interpolation mode for the zooming of the characters.
Default value: 'constant'
List of values: 'bicubic', 'bilinear', 'constant', 'nearest_neighbor', 'weighted'
Features to be used for classification.
Default value: 'default'
List of values: 'anisometry', 'chord_histo', 'compactness', 'convexity', 'cooc', 'default', 'foreground', 'foreground_grid_16', 'foreground_grid_9', 'gradient_8dir', 'height', 'moments_central', 'moments_gray_plane', 'moments_region_2nd_invar', 'moments_region_2nd_rel_invar', 'moments_region_3rd_invar', 'num_connect', 'num_holes', 'num_runs', 'phi', 'pixel', 'pixel_binary', 'pixel_invar', 'projection_horizontal', 'projection_horizontal_invar', 'projection_vertical', 'projection_vertical_invar', 'ratio', 'width', 'zoom_factor'
All characters of the character set to be read.
Default value: ['0','1','2','3','4','5','6','7','8','9']
The kernel type.
Default value: 'rbf'
List of values: 'linear', 'polynomial_homogeneous', 'polynomial_inhomogeneous', 'rbf'
Additional parameter for the kernel function.
Default value: 0.02
Suggested values: 0.01, 0.02, 0.05, 0.1, 0.5
Regularization constant of the SVM.
Default value: 0.05
Suggested values: 0.0001, 0.001, 0.01, 0.05, 0.1, 0.2, 0.3
Restriction: Nu > 0.0 && Nu < 1.0
The mode of the SVM.
Default value: 'one-versus-one'
List of values: 'one-versus-all', 'one-versus-one'
Type of preprocessing used to transform the feature vectors.
Default value: 'normalization'
List of values: 'canonical_variates', 'none', 'normalization', 'principal_components'
Default value: 10
Suggested values: 1, 2, 3, 4, 5, 8, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100
Restriction: NumComponents >= 1
Handle of the OCR classifier.
read_image (Image, 'letters') * Segment the image. binary_threshold(Image,&Region, 'otsu', 'dark', &UsedThreshold); dilation_circle (Region, RegionDilation, 3.5) connection (RegionDilation, ConnectedRegions) intersection (ConnectedRegions, Region, RegionIntersection) sort_region (RegionIntersection, Characters, 'character', 'true', 'row') * Generate the training file. count_obj (Characters, Number) Classes :=  for J := 0 to 25 by 1 Classes := [Classes,gen_tuple_const(20,chr(ord('a')+J))] endfor Classes := [Classes,gen_tuple_const(20,'.')] write_ocr_trainf (Characters, Image, Classes, 'letters.trf') * Generate and train the classifier. read_ocr_trainf_names ('letters.trf', CharacterNames, CharacterCount) create_ocr_class_svm (8, 10, 'constant', 'default', CharacterNames, \ 'rbf', 0.01, 0.01, 'one-versus-all', \ 'principal_components', 10, OCRHandle) trainf_ocr_class_svm (OCRHandle, 'letters.trf', 0.001, 'default') * Re-classify the characters in the image. do_ocr_multi_class_svm (Characters, Image, OCRHandle, Class)
If the parameters are valid the operator create_ocr_class_svm returns the value 2 (H_MSG_TRUE). If necessary, an exception is raised.
do_ocr_single_class_svm, do_ocr_multi_class_svm, clear_ocr_class_svm, create_class_svm, train_class_svm, classify_class_svm