Skip to content

create_ocr_class_mlpCreateOcrClassMlpCreateOcrClassMlpcreate_ocr_class_mlpT_create_ocr_class_mlp🔗

説明🔗

create_ocr_class_mlpCreateOcrClassMlpCreateOcrClassMlpcreate_ocr_class_mlpT_create_ocr_class_mlp — 多層パーセプトロンを使って OCR 識別子を生成する。

書式🔗

create_ocr_class_mlp( integer WidthCharacter, integer HeightCharacter, string Interpolation, string Features, string Characters, integer NumHidden, string Preprocessing, integer NumComponents, integer RandSeed, out ocr_mlp OCRHandle )void CreateOcrClassMlp( const HTuple& WidthCharacter, const HTuple& HeightCharacter, const HTuple& Interpolation, const HTuple& Features, const HTuple& Characters, const HTuple& NumHidden, const HTuple& Preprocessing, const HTuple& NumComponents, const HTuple& RandSeed, HTuple* OCRHandle )static void HOperatorSet.CreateOcrClassMlp( HTuple widthCharacter, HTuple heightCharacter, HTuple interpolation, HTuple features, HTuple characters, HTuple numHidden, HTuple preprocessing, HTuple numComponents, HTuple randSeed, out HTuple OCRHandle )def create_ocr_class_mlp( width_character: int, height_character: int, interpolation: str, features: MaybeSequence[str], characters: Sequence[str], num_hidden: int, preprocessing: str, num_components: int, rand_seed: int ) -> HHandle

Herror T_create_ocr_class_mlp( const Htuple WidthCharacter, const Htuple HeightCharacter, const Htuple Interpolation, const Htuple Features, const Htuple Characters, const Htuple NumHidden, const Htuple Preprocessing, const Htuple NumComponents, const Htuple RandSeed, Htuple* OCRHandle )

void HOCRMlp::HOCRMlp( Hlong WidthCharacter, Hlong HeightCharacter, const HString& Interpolation, const HTuple& Features, const HTuple& Characters, Hlong NumHidden, const HString& Preprocessing, Hlong NumComponents, Hlong RandSeed )

void HOCRMlp::HOCRMlp( Hlong WidthCharacter, Hlong HeightCharacter, const HString& Interpolation, const HString& Features, const HTuple& Characters, Hlong NumHidden, const HString& Preprocessing, Hlong NumComponents, Hlong RandSeed )

void HOCRMlp::HOCRMlp( Hlong WidthCharacter, Hlong HeightCharacter, const char* Interpolation, const char* Features, const HTuple& Characters, Hlong NumHidden, const char* Preprocessing, Hlong NumComponents, Hlong RandSeed )

void HOCRMlp::HOCRMlp( Hlong WidthCharacter, Hlong HeightCharacter, const wchar_t* Interpolation, const wchar_t* Features, const HTuple& Characters, Hlong NumHidden, const wchar_t* Preprocessing, Hlong NumComponents, Hlong RandSeed ) (Windows only)

public HOCRMlp( int widthCharacter, int heightCharacter, string interpolation, HTuple features, HTuple characters, int numHidden, string preprocessing, int numComponents, int randSeed )

public HOCRMlp( int widthCharacter, int heightCharacter, string interpolation, string features, HTuple characters, int numHidden, string preprocessing, int numComponents, int randSeed )

void HOCRMlp::CreateOcrClassMlp( Hlong WidthCharacter, Hlong HeightCharacter, const HString& Interpolation, const HTuple& Features, const HTuple& Characters, Hlong NumHidden, const HString& Preprocessing, Hlong NumComponents, Hlong RandSeed )

void HOCRMlp::CreateOcrClassMlp( Hlong WidthCharacter, Hlong HeightCharacter, const HString& Interpolation, const HString& Features, const HTuple& Characters, Hlong NumHidden, const HString& Preprocessing, Hlong NumComponents, Hlong RandSeed )

void HOCRMlp::CreateOcrClassMlp( Hlong WidthCharacter, Hlong HeightCharacter, const char* Interpolation, const char* Features, const HTuple& Characters, Hlong NumHidden, const char* Preprocessing, Hlong NumComponents, Hlong RandSeed )

void HOCRMlp::CreateOcrClassMlp( Hlong WidthCharacter, Hlong HeightCharacter, const wchar_t* Interpolation, const wchar_t* Features, const HTuple& Characters, Hlong NumHidden, const wchar_t* Preprocessing, Hlong NumComponents, Hlong RandSeed ) (Windows only)

void HOCRMlp.CreateOcrClassMlp( int widthCharacter, int heightCharacter, string interpolation, HTuple features, HTuple characters, int numHidden, string preprocessing, int numComponents, int randSeed )

void HOCRMlp.CreateOcrClassMlp( int widthCharacter, int heightCharacter, string interpolation, string features, HTuple characters, int numHidden, string preprocessing, int numComponents, int randSeed )

説明🔗

create_ocr_class_mlpCreateOcrClassMlp は、多層パーセプトロン(MLP)を使っ て OCR 識別子を生成します。OCR 識別子のハンドルは OCRHandleOCRHandleocrhandle にて返します。

MLP がどのように動作するかについての記述については、 create_class_mlpCreateClassMlp を参照してください。 create_ocr_class_mlpCreateOcrClassMlp は、OutputFunctionoutputFunctionoutput_function \(=\) 'softmax'"softmax" を持つ MLP を生成します。MLP の特徴ベクトルの長 さ(create_class_mlpCreateClassMlp における NumInputnumInputnum_input)は、 Featuresfeaturesfeatures で渡される、OCR のために使用する特徴によって決定され ます。特徴は以下のように記述されます。隠れ層のユニットの数は、 NumHiddennumHiddennum_hidden によって決定されます。MLP の出力変数の数( create_class_mlpCreateClassMlp における NumOutputnumOutputnum_output)は、 Characterscharacterscharacters で渡す OCR のために使用する文字の名前から決定 されます。create_class_mlpCreateClassMlp で説明したように、パラメーター Preprocessingpreprocessingpreprocessing および NumComponentsnumComponentsnum_components はデータの前 処理、つまり特徴ベクトルを指定するために使用します。OCR はすでにほ とんどの特徴を正規化しています。 したがって、Preprocessingpreprocessingpreprocessing は一般的に 'none'"none" にす ることができます。パラメーター RandSeedrandSeedrand_seed は、 create_class_mlpCreateClassMlp と同じような意味を持ちます。

また、一般的なMLP(create_class_mlpCreateClassMlp及び set_regularization_params_class_mlpSetRegularizationParamsClassMlp参照)と同様に、 OCR識別子を正規化することが望ましい場合があります。 これは、OCR識別子のトレーニングを実行する前に set_regularization_params_ocr_class_mlpSetRegularizationParamsOcrClassMlpを実行することで 実現可能です。 加えて、一般的なMLP(create_class_mlpCreateClassMlp及び set_rejection_params_class_mlpSetRejectionParamsClassMlp参照)と同様に、 未知の文字列を削除する機能を持つ、OCR識別子が実装されることが 望ましい。 除外クラスは、文字列chr(26)を追加することで指定する必要があります。 除外クラスのパラメータは、OCR識別子のトレーニングを実行する前に set_rejection_params_ocr_class_mlpSetRejectionParamsOcrClassMlpを 実行することで設定可能です。

分類のために使用される特徴は、Featuresfeaturesfeatures によって決められま す。Featuresfeaturesfeatures には、いくつかの特徴名を持つ tuple を指定で きます。これら特徴名は、識別子のために計算される 1 つもしくはそれ 以上の特徴に帰着します。特徴名の中には、グレイ値の特徴を計算するも のもあります(例えば 'pixel_invar'"pixel_invar")。 識別子は一定数の特徴(入力変数)を必要とするため、分類される文字 は WidthCharacterwidthCharacterwidth_character および HeightCharacterheightCharacterheight_character によっ て決められる標準の大きさに変換されます。変換のために使用される補間 は Interpolationinterpolationinterpolation によって決められます。それは、 affine_trans_imageAffineTransImage でのものと同じ意味を持っています。補間 は変換に対してエイリアシング効果が生じないように選ばれる必要があり ます。ほとんどの場合、Interpolationinterpolationinterpolation \(=\) 'constant'"constant" が使用されます。識別子の一般化特性が大きなサイ ズに対して悪くなるかもしれないため、変換された文字のサイズがあまり 大きく選ばれないことを注意すべきです。特に、大きな文字サイズは、グ レイ値の特徴を使用する場合に小さな分割化誤差が計算された特徴におい て大きな影響をもたらします。これは、分割化誤差が領域を囲む最小矩形 を変更するためにおきます。これは、文字がトレーニングセットの文字と は異なり拡大されるためです。多くの場合、6x8 か ら 10x14 の間の大きさを使用するべきです。

パラメーター Featuresfeaturesfeatures は、文字の分類のために以下のような 特徴名を含むことができます。

識別子が生成された後、trainf_ocr_class_mlpTrainfOcrClassMlp を使用してト レーニングされます。この後に、識別子は write_ocr_class_mlpWriteOcrClassMlp を使用して保存することができます。また は、do_ocr_single_class_mlpDoOcrSingleClassMlp または do_ocr_multi_class_mlpDoOcrMultiClassMlp を使用して文字を分類するためにト レーニングした後すぐに識別子を使用することができます。

HALCON は事前にトレーニングされた OCR 識別子数を提供します。( “Solution Guide I”, chapter ‘OCR’, section ‘Pretrained OCR Fonts’ を 参照してください。)事前にトレーニングされた OCR 識別子は、 read_ocr_class_mlpReadOcrClassMlp を使用し直接読み込むことが可能であり、 OCR 識別子をトレーニングする必要なく、さまざまなフォントを読み込む ことができます。したがって、事前にトレーニングされた OCR 識別子の 1 つを使用することができる場合、試しに使用してみてください。この場 合、OCR 識別子を生成し、トレーニングする必要はありません。

MLP とサポートベクトルマシン(SVM)(create_ocr_class_svmCreateOcrClassSvm 参照)を比較すると、特に大規模なトレーニングセットの場合では、SVM のほうがトレーニングが通常早く、MLP よりもわずかに優れた認識率が得 られることが一般にわかります。MLP はクラス分けが早いので、スピード 重視の用途に望ましいといえます。なお、このガイドラインはパラメー ターの最適同調を想定していることにご注意ください。

実行情報🔗

実行情報
  • マルチスレッドタイプ: リエントラント(非排他なオペレーターと並列に動作)

  • マルチスレッドスコープ: グローバル(他のスレッドから呼び出される可能性あり)

  • 並列演算処理には未対応

このオペレータはハンドルを返します。このハンドルタイプのインスタンスの状態は、特定のオペレータにおいては、入力パラメータとして使われている場合であっても変更されることがあります。

パラメーター🔗

WidthCharacterwidthCharacterwidth_character (input_control) integer → (integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

分割化した文字のグレイ値の矩形の拡大する幅

初期値: 88
推奨値: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 201, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 20
値域: 4 ≤ WidthCharacter ≤ 20

HeightCharacterheightCharacterheight_character (input_control) integer → (integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

分割化した文字のグレイ値の矩形の拡大する高さ

初期値: 1010
推奨値: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 201, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 20
値域: 4 ≤ HeightCharacter ≤ 20

Interpolationinterpolationinterpolation (input_control) string → (string)HTuple (HString)HTuple (string)strHtuple (char*)

文字の拡大のための補間モード

初期値: 'constant'"constant"
値のリスト: 'bicubic', 'bilinear', 'constant', 'nearest_neighbor', 'weighted'"bicubic", "bilinear", "constant", "nearest_neighbor", "weighted"

Featuresfeaturesfeatures (input_control) string(-array) → (string)HTuple (HString)HTuple (string)MaybeSequence[str]Htuple (char*)

分類のために使用する特徴

初期値: 'default'"default"
値のリスト: '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'"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"

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

読むべき文字セットのすべての文字

初期値: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]

NumHiddennumHiddennum_hidden (input_control) integer → (integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

MLP の隠れ層の数

初期値: 8080
推奨値: 1, 2, 3, 4, 5, 8, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100, 120, 1501, 2, 3, 4, 5, 8, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100, 120, 150
制限: NumHidden >= 1

Preprocessingpreprocessingpreprocessing (input_control) string → (string)HTuple (HString)HTuple (string)strHtuple (char*)

特徴ベクトルを変換するために使用する前処理のタイプ

初期値: 'none'"none"
値のリスト: 'canonical_variates', 'none', 'normalization', 'principal_components'"canonical_variates", "none", "normalization", "principal_components"

NumComponentsnumComponentsnum_components (input_control) integer → (integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

前処理パラメーター: 変換される特徴の数( Preprocessingpreprocessingpreprocessing \(=\) 'none'"none" および Preprocessingpreprocessingpreprocessing \(=\) 'normalization'"normalization" の場合は無視される)

初期値: 1010
推奨値: 1, 2, 3, 4, 5, 8, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 1001, 2, 3, 4, 5, 8, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100
制限: NumComponents >= 1

RandSeedrandSeedrand_seed (input_control) integer → (integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

乱数で MLP を初期化するために使用する乱数生成器の シード値

初期値: 4242

OCRHandleOCRHandleocrhandle (output_control) ocr_mlp → (handle)HTuple (HHandle)HOCRMlp, HTuple (IntPtr)HHandleHtuple (handle)

OCR 識別子のハンドル

例🔗

(HDevelop)


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_mlp (8, 10, 'constant', 'default', CharacterNames, 20, \
                      'none', 81, 42, OCRHandle)
trainf_ocr_class_mlp (OCRHandle, 'letters.trf', 100, 0.01, 0.01, Error, \
                      ErrorLog)
* Re-classify the characters in the image.
do_ocr_multi_class_mlp (Characters, Image, OCRHandle, Class, Confidence)

結果🔗

パラメーターが有効ならば、オペレーター create_ocr_class_mlpCreateOcrClassMlp は値 2 (H_MSG_TRUE) を返します。必要に応じて、 例外処理が発生します。

他のオペレーターとの組み合わせ🔗

組み合わせ

後処理の候補

trainf_ocr_class_mlpTrainfOcrClassMlp, set_regularization_params_ocr_class_mlpSetRegularizationParamsOcrClassMlp, set_rejection_params_ocr_class_mlpSetRejectionParamsOcrClassMlp

他の選択候補

create_ocr_class_svmCreateOcrClassSvm

関連項目

do_ocr_single_class_mlpDoOcrSingleClassMlp, do_ocr_multi_class_mlpDoOcrMultiClassMlp, clear_ocr_class_mlpClearOcrClassMlp, create_class_mlpCreateClassMlp, train_class_mlpTrainClassMlp, classify_class_mlpClassifyClassMlp

モジュール🔗

OCR/OCV