オプション
Usage: opencv_traincascade
-data <cascade_dir_name>
-vec <vec_file_name>
-bg <background_file_name>
[-numPos <number_of_positive_samples = 2000>]
[-numNeg <number_of_negative_samples = 1000>]
[-numStages <number_of_stages = 20>]
[-precalcValBufSize <precalculated_vals_buffer_size_in_Mb = 1024>]
[-precalcIdxBufSize <precalculated_idxs_buffer_size_in_Mb = 1024>]
[-baseFormatSave]
[-acceptanceRatioBreakValue <value> = -1>]
--cascadeParams--
[-stageType <BOOST(default)>]
[-featureType <{HAAR(default), LBP, HOG}>]
[-w <sampleWidth = 24>]
[-h <sampleHeight = 24>]
--boostParams--
[-bt <{DAB, RAB, LB, GAB(default)}>]
[-minHitRate <min_hit_rate> = 0.995>]
[-maxFalseAlarmRate <max_false_alarm_rate = 0.5>]
[-weightTrimRate <weight_trim_rate = 0.95>]
[-maxDepth <max_depth_of_weak_tree = 1>]
[-maxWeakCount <max_weak_tree_count = 100>]
--haarFeatureParams--
[-mode <BASIC(default) | CORE | ALL
--lbpFeatureParams--
--HOGFeatureParams--
vecファイルを入力として、haar, LBP, HOGなどの特徴を指定して学習データを出力する。訓練用の正例・負例が4など少ない状態で動かしたらエラーになったので数を増やしたら動いた・・・。正例1000、負例80、-numStages 1なら動くことを確認した。訓練時間は1分もかからなかった。正例7000、負例3000は必要らしい。
下記のようなエラーになるときは訓練データ数が足りていない。または-numStagesが大きすぎる。
===== TRAINING 1-stage =====
<BEGIN
POS curreOpenCV Error: Bad argument (Can not get new positive sample. The most possible reason is insufficient count of samples in given vec-file.
) in get, file /Users/user/miniconda3/conda-bld/work/opencv-2.4.12/apps/traincascade/imagestorage.cpp, line 154
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /Users/user/miniconda3/conda-bld/work/opencv-2.4.12/apps/traincascade/imagestorage.cpp:154: error: (-5) Can not get new positive sample. The most possible reason is insufficient count of samples in given vec-file.
エラーなく終了すると、
-rw-r--r-- 1 kt staff 1170 Jan 4 05:44 cascade.xml
-rw-r--r-- 1 kt staff 594 Jan 4 05:44 params.xml
-rw-r--r-- 1 kt staff 384 Jan 4 05:44 stage0.xml
これらのファイルが出力される。caccade.xmlをサンプルで使っているxmlの代わりに使えば認識できるはず。要確認。
計算時間(-stageNum 1)
- 24x24 正例1000, 負例500で1分20秒
- 24x24 正例1000, 負例1000で2分12秒 (負例の数も影響する)
- 24x24 正例2000, 負例1000で3分59秒 (正例の数は大きく影響する)
学習結果のキャッシュ
xml出力ファイルにstageファイルができていて、それを消さないと最学習はしない。-stageNumを増やしたとき、キャッシュがあるときはそれを使う。