1.首先得在此处下载win pack版的opencv
2.正在此目录(opencv\build\x64\vc14\bin)下找到 opencv_createsamples.exe 和 opencv_traincascade.exe
3.在正样本的文件夹下创建记事本,写入如下内容:
dir /b/s/p/w *.jpg > positives.txt
最后修改为 bat 格式
步骤:
问题:
打开cmd,输入 opencv_createsamples.exe 就会得到帮助信息
Usage: opencv_createsamples.exe
[-info
[-img
[-vec
[-bg
[-num
[-bgcolor
[-inv] [-randinv] [-bgthresh
[-maxidev
[-maxxangle
[-maxyangle
[-maxzangle
[-show [
[-w
[-h
[-maxscale
打开cmd,输入 opencv_traincascade.exe 就会得到帮助信息
Usage: opencv_traincascade.exe
-data
-vec
-bg
[-numPos
[-numNeg
[-numStages
[-precalcValBufSize
[-precalcIdxBufSize
[-baseFormatSave]
[-numThreads
[-acceptanceRatioBreakValue
--cascadeParams--
[-stageType
[-featureType <{HAAR(default), LBP, HOG}>]
[-w
[-h
--boostParams--
[-bt <{DAB, RAB, LB, GAB(default)}>]
[-minHitRate
[-maxFalseAlarmRate
[-weightTrimRate
[-maxDepth
[-maxWeakCount
--haarFeatureParams--
[-mode
--HOGFeatureParams--
(问题1)positives.txt(1) : parse errorDone. Created 0 samples
说明你的 正样本 路径写错了
正确格式:positive_images\1.jpg 1 0 0 20 20(路径+1+0+0+w+h)
(问题2)注意:负样本直接写成路径即可,否则会出现后面错误:
Train dataset for temp stage can not be filled. Branch training terminated.
Cascade classifier can't be trained. Check the used training parameters.
(问题3)运行:opencv_traincascade.exe时,注意添加-numPos 50(不一定为样本数,可能比样本数少,不然会出现以下错误) -numNeg 147(除非为默认样本数)
否则会出现以下错误:
OpenCV Error: Bad argument (Can not get new positive sample.
The most possible reason is insufficient count of samples in given vec-file.) in CvCascadeImageReader::PosReader::get,
file C:\build\master_winpack-build-win64-vc14\opencv\apps\traincascade\imagestorage.cpp, line 158
(问题4)Bad argument (_cascadeDirName or _bgfileName or _vecFileName is NULL) in CvCascadeClassifier::train,
file C:\build\master_winpack-build-win64-vc14\opencv\apps\traincascade\cascadeclassifier.cpp
输入格式不对:可能少了 -
(问题5)OpenCV Error: Assertion failed (_img.rows * _img.cols == vecSize) in CvCascadeImageReader::PosReader
加上 -w 20 -h 20 就好了(你正样本的w和h)