Skip to content

trainf_ocr_class_knnTrainfOcrClassKnnTrainfOcrClassKnntrainf_ocr_class_knnT_trainf_ocr_class_knn🔗

Short description🔗

trainf_ocr_class_knnTrainfOcrClassKnnTrainfOcrClassKnntrainf_ocr_class_knnT_trainf_ocr_class_knn — Trains an k-NN classifier for an OCR task.

Signature🔗

trainf_ocr_class_knn( ocr_knn OCRHandle, filename.read TrainingFile, string GenParamName, number GenParamValue )void TrainfOcrClassKnn( const HTuple& OCRHandle, const HTuple& TrainingFile, const HTuple& GenParamName, const HTuple& GenParamValue )static void HOperatorSet.TrainfOcrClassKnn( HTuple OCRHandle, HTuple trainingFile, HTuple genParamName, HTuple genParamValue )def trainf_ocr_class_knn( ocrhandle: HHandle, training_file: MaybeSequence[str], gen_param_name: Sequence[str], gen_param_value: Sequence[Union[int, str, float]] ) -> None

Herror T_trainf_ocr_class_knn( const Htuple OCRHandle, const Htuple TrainingFile, const Htuple GenParamName, const Htuple GenParamValue )

void HOCRKnn::TrainfOcrClassKnn( const HTuple& TrainingFile, const HTuple& GenParamName, const HTuple& GenParamValue ) const

void HOCRKnn::TrainfOcrClassKnn( const HString& TrainingFile, const HTuple& GenParamName, const HTuple& GenParamValue ) const

void HOCRKnn::TrainfOcrClassKnn( const char* TrainingFile, const HTuple& GenParamName, const HTuple& GenParamValue ) const

void HOCRKnn::TrainfOcrClassKnn( const wchar_t* TrainingFile, const HTuple& GenParamName, const HTuple& GenParamValue ) const (Windows only)

void HOCRKnn.TrainfOcrClassKnn( HTuple trainingFile, HTuple genParamName, HTuple genParamValue )

void HOCRKnn.TrainfOcrClassKnn( string trainingFile, HTuple genParamName, HTuple genParamValue )

Description🔗

trainf_ocr_class_knnTrainfOcrClassKnn trains the k-NN classifier OCRHandleOCRHandleocrhandle with the training characters stored in the OCR training files given by TrainingFiletrainingFiletraining_file. The training files must have been created, e.g., using write_ocr_trainfWriteOcrTrainf, before calling trainf_ocr_class_knnTrainfOcrClassKnn. Please, note that training characters that have no corresponding class in the classifier OCRHandleOCRHandleocrhandle are discarded.

The following options may be set using GenParamNamegenParamNamegen_param_name and GenParamValuegenParamValuegen_param_value, respectively:

  • 'num_trees'"num_trees" Sets the number of search trees. A higher number of trees improves the accuracy of the search, but also increases the runtime.

    Default: 44.

  • 'normalization'"normalization" Activates the data normalization, if set to 'true'"true". This will change the stored training data permanently. Therefore, adding data after the training is not possible.

    List of values: 'true'"true", 'false'"false".

    Default: 'false'"false".

Execution information🔗

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

This operator modifies the state of the following input parameter:

During execution of this operator, access to the value of this parameter must be synchronized if it is used across multiple threads.

Parameters🔗

OCRHandleOCRHandleocrhandle (input_control, state is modified) ocr_knn → (handle)HTuple (HHandle)HOCRKnn, HTuple (IntPtr)HHandleHtuple (handle)

Handle of the k-NN classifier.

TrainingFiletrainingFiletraining_file (input_control) filename.read(-array) → (string)HTuple (HString)HTuple (string)MaybeSequence[str]Htuple (char*)

Names of the training files.

Default: 'ocr.trf'"ocr.trf"
File extension: .trf, .otr

GenParamNamegenParamNamegen_param_name (input_control) string-array → (string)HTuple (HString)HTuple (string)Sequence[str]Htuple (char*)

Names of the generic parameters that can be adjusted for the k-NN classifier creation.

Default: [][]
List of values: 'normalization', 'num_trees'"normalization", "num_trees"

GenParamValuegenParamValuegen_param_value (input_control) number-array → (integer / string / real)HTuple (Hlong / HString / double)HTuple (int / long / string / double)Sequence[Union[int, str, float]]Htuple (Hlong / char* / double)

Values of the generic parameters that can be adjusted for the k-NN classifier creation.

Default: [][]
Suggested values: 4, 5, 'false', 'true'4, 5, "false", "true"

Example🔗

(HDevelop)

* Train an OCR classifier
read_ocr_trainf_names ('ocr.trf', CharacterNames, CharacterCount)
create_ocr_class_knn (8, 10, 'constant', 'default', CharacterNames, [],\
                      [], OCRHandle)
trainf_ocr_class_knn (OCRHandle, 'ocr.trf', [], [])
write_ocr_class_knn (OCRHandle, 'ocr.omc')

Result🔗

If the parameters are valid, the operator trainf_ocr_class_knnTrainfOcrClassKnn returns the value 2 (H_MSG_TRUE). If necessary, an exception is raised.

Combinations with other operators🔗

Combinations

Possible predecessors

create_ocr_class_knnCreateOcrClassKnn, write_ocr_trainfWriteOcrTrainf, append_ocr_trainfAppendOcrTrainf, write_ocr_trainf_imageWriteOcrTrainfImage

Possible successors

do_ocr_single_class_knnDoOcrSingleClassKnn, do_ocr_multi_class_knnDoOcrMultiClassKnn

Alternatives

read_ocr_class_knnReadOcrClassKnn

See also

train_class_knnTrainClassKnn

Module🔗

OCR/OCV