Time:20181009
Env:Win10、OpenCV2.4.9
Function:50、50 P、N
1、
C:\>cd G:\
C:\>cd G:\TrainingSample
C:\>cd G:\TrainingSample\pos
C:\>G
'G' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
C:\>G:
G:\TrainingSample\pos>dir/b>pos.dat
G:\TrainingSample\pos>cd..
G:\TrainingSample>cd neg
G:\TrainingSample\neg>dir/b>neg.dat
G:\TrainingSample\neg>cd..
G:\TrainingSample>cd pos
G:\TrainingSample\pos>
2、
G:\TrainingSample\pos>"F:\opencv249\opencv\build\x64\vc12\bin\opecv_creates.exe" -info "pos\pos.dat" -vec pos.vec -num 50 -w 64 -h 32
'"F:\opencv249\opencv\build\x64\vc12\bin\opecv_creates.exe"' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
G:\TrainingSample\pos>F:\opencv249\opencv\build\x64\vc12\bin\opencv_createsamples.exe -info "pos\pos.dat" -vec pos.vec -num 50 -w 64 -h 32
Info file name: pos\pos.dat
Img file name: (NULL)
Vec file name: pos.vec
BG file name: (NULL)
Num: 50
BG color: 0
BG threshold: 80
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 64
Height: 32
Create training samples from images collection...
Unable to open file: pos\pos.dat
Done. Created 0 samples
G:\TrainingSample\pos>
3、
G:\TrainingSample\pos>F:\opencv249\opencv\build\x64\vc12\bin\opencv_createsamples.exe -info "pos.dat" -vec pos.vec -num 50 -w 64 -h 32
Info file name: pos.dat
Img file name: (NULL)
Vec file name: pos.vec
BG file name: (NULL)
Num: 50
BG color: 0
BG threshold: 80
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 64
Height: 32
Create training samples from images collection...
pos.dat(1) : parse errorDone. Created 0 samples
pos.vec文件生成失败!
换用OPencv3.4尝试
4、
G:\TrainingSample>F:\opencv249\opencv\build\x64\vc12\bin\opencv_traincascade.exe -data "G:\TrainingSample" -vec pos\pos.vec -bg neg\neg.dat -numPos 50 -numNeg 50 -numStages 4 -men 200 -featureType LBP -w 64 -h 32
PARAMETERS:
cascadeDirName: G:\TrainingSample
vecFileName: pos\pos.vec
bgFileName: neg\neg.dat
numPos: 50
numNeg: 50
numStages: 4
precalcValBufSize[Mb] : 256
precalcIdxBufSize[Mb] : 256
stageType: BOOST
featureType: LBP
sampleWidth: 64
sampleHeight: 32
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
===== TRAINING 0-stage =====
<BEGIN
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:\builds\2_4_PackSlave-win64-vc12-shared\opencv\apps\traincascade\imagestorage.cpp, line 162
错误分析:
form:https://bbs.csdn.net/topics/390388465
The problem is that your vec-file has exactly the same samples count that you passed in command line -numPos 979. Training application used all samples from the vec-file to train 0-stage and it can not get new positive samples for the next stage training because vec-file is over. The bug of traincascade is that it had assert() in such cases, but it has to throw an exception with error message for a user. It was fixed in r8913. -numPose is a samples count that is used to train each stage. Some already used samples can be filtered by each previous stage (ie recognized as background), but no more than (1 - minHitRate) * numPose on each stage. So vec-file has to contain >= (numPose + (numStages-1) * (1 - minHitRate) * numPose) + S, where S is a count of samples from vec-file that can be recognized as background right away. I hope it can help you to create vec-file of correct size and chose right numPos value.
It worked for me. I also had same problem, I was following the famous tutorial on HAAR training but wanted to try the newer training utility with -npos 7000 -nneg 2973
so i did following calcs:
vec-file has to contain >= (numPos + (numStages-1) * (1 - minHitRate) * numPos) + S
7000 >= (numPos + (20-1) * (1 - 0.999) * numPos) + 2973
(7000 - 2973)/(1 + 19*0.001) >= numPos
numPos <= 4027/1.019
numPos <= 3951 ~~ 3950
and used:
-npos 3950 -nneg 2973
It works.
6、
G:\TrainingSample>F:\OPENCV3.4\opencv\build\x64\vc15\bin\opencv_createsamples.exe -info "pos\pos.txt" -vec pos.vec -num 100 -w 64 -h 32
Info file name: pos\pos.txt
Img file name: (NULL)
Vec file name: pos.vec
BG file name: (NULL)
Num: 100
BG color: 0
BG threshold: 80
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 64
Height: 32
Max Scale: -1
RNG Seed: 12345
Create training samples from images collection...
程序卡在这里了。
7、
F:\opencv249\opencv\build\x64\vc12\bin>opencv_createsamples.exe -info "G:\TrainingSample\pos\pos.txt" -vec pos.vec -num 100 -w 64 -h 32
Info file name: G:\TrainingSample\pos\pos.txt
Img file name: (NULL)
Vec file name: pos.vec
BG file name: (NULL)
Num: 100
BG color: 0
BG threshold: 80
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 64
Height: 32
Create training samples from images collection...
G:\TrainingSample\pos\pos.txt(1) : parse errorDone. Created 0 samples
F:\opencv249\opencv\build\x64\vc12\bin>opencv_createsamples.exe -info "G:\TrainingSample\pos\pos.txt" -vec pos.vec -num 100 -w 64 -h 32
Info file name: G:\TrainingSample\pos\pos.txt
Img file name: (NULL)
Vec file name: pos.vec
BG file name: (NULL)
Num: 100
BG color: 0
BG threshold: 80
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 64
Height: 32
Create training samples from images collection...
G:\TrainingSample\pos\pos.txt(96) : parse errorDone. Created 95 samples
F:\opencv249\opencv\build\x64\vc12\bin>opencv_createsamples.exe -info "G:\TrainingSample\pos\pos.txt" -vec pos.vec -num 100 -w 64 -h 32
Info file name: G:\TrainingSample\pos\pos.txt
Img file name: (NULL)
Vec file name: pos.vec
BG file name: (NULL)
Num: 100
BG color: 0
BG threshold: 80
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 64
Height: 32
Create training samples from images collection...
G:\TrainingSample\pos\pos.txt(96) : parse errorDone. Created 95 samples
F:\opencv249\opencv\build\x64\vc12\bin>opencv_createsamples.exe -info "G:\TrainingSample\pos\pos.txt" -vec pos.vec -num 95 -w 64 -h 32
Info file name: G:\TrainingSample\pos\pos.txt
Img file name: (NULL)
Vec file name: pos.vec
BG file name: (NULL)
Num: 95
BG color: 0
BG threshold: 80
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 64
Height: 32
Create training samples from images collection...
Done. Created 95 samples
F:\opencv249\opencv\build\x64\vc12\bin>opencv_createsamples.exe -info "G:\TrainingSample\pos\pos.txt" -vec pos.vec -num 95 -w 64 -h 32
Info file name: G:\TrainingSample\pos\pos.txt
Img file name: (NULL)
Vec file name: pos.vec
BG file name: (NULL)
Num: 95
BG color: 0
BG threshold: 80
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 64
Height: 32
Create training samples from images collection...
G:\TrainingSample\pos\pos.txt(91) : parse errorDone. Created 90 samples
F:\opencv249\opencv\build\x64\vc12\bin>opencv_createsamples.exe -info "G:\TrainingSample\pos\pos.txt" -vec pos.vec -num 95 -w 64 -h 32
Info file name: G:\TrainingSample\pos\pos.txt
Img file name: (NULL)
Vec file name: pos.vec
BG file name: (NULL)
Num: 95
BG color: 0
BG threshold: 80
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 64
Height: 32
Create training samples from images collection...
G:\TrainingSample\pos\pos.txt(91) : parse errorDone. Created 90 samples
F:\opencv249\opencv\build\x64\vc12\bin>opencv_createsamples.exe -info "G:\TrainingSample\pos\pos.txt" -vec pos.vec -num 95 -w 64 -h 32
Info file name: G:\TrainingSample\pos\pos.txt
Img file name: (NULL)
Vec file name: pos.vec
BG file name: (NULL)
Num: 95
BG color: 0
BG threshold: 80
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 64
Height: 32
Create training samples from images collection...
Done. Created 95 samples
8、在样本目录下 ,出现ERRO
G:\TrainingSample\pos>F:\opencv249\opencv\build\x64\vc12\bin\opencv_createsamples.exe -vec pos.vec -info pos.txt -w 64 -h 32 -num 100
Info file name: pos.txt
Img file name: (NULL)
Vec file name: pos.vec
BG file name: (NULL)
Num: 100
BG color: 0
BG threshold: 80
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 64
Height: 32
Create training samples from images collection...
pos.txt(1) : parse errorDone. Created 0 samples
9、切换目录到.exe文件目录
F:\opencv249\opencv\build\x64\vc12\bin>opencv_createsamples.exe -vec pos.vec -info "G:\TrainingSample\pos\pos.txt" -w 64 -h 32 -num 100
拒绝访问。
F:\opencv249\opencv\build\x64\vc12\bin>opencv_createsamples.exe -vec pos.vec -info G:\TrainingSample\pos\pos.txt -w 64 -h 32 -num 100
拒绝访问。
8、将正负样本及pos.txt\neg.txt文件方法 目录F:\opencv249\opencv\build\x64\vc12\bin
F:\opencv249\opencv\build\x64\vc12\bin>opencv_createsamples.exe -vec pos.vec -info "pos\pos.txt" -w 64 -h 32 -num 50
pos.vec 文件生成成功
9、训练测试(正负样本及pos.txt\neg.txt文件及pos.vec在目录:G:\TrainingSample):
F:\opencv249\opencv\build\x64\vc12\bin>opencv_traincascade.exe -data -vec pos.vec -bg neg\neg.txt -numPos 20 -numNeg 20 -numStages 3 -mem 200 -featureType LBP -w 64 -h 32
F:\opencv249\opencv\build\x64\vc12\bin>opencv_traincascade.exe -data -vec pos.vec -bg "neg\neg.txt" -numPos 20 -numNeg 20 -numStages 3 -mem 200 -featureType LBP -w 64 -h 32
F:\opencv249\opencv\build\x64\vc12\bin>opencv_traincascade.exe -data "G:\TrainingSample" -vec pos.vec -bg "neg\neg.txt" -numPos 20 -numNeg 20 -numStages 3 -mem 200 -featureType LBP -w 64 -h 32
("G:\TrainingSample"存放data路径,,-vec pos.vec -bg "neg\neg.txt"为当前文件加下路径)
PARAMETERS:
cascadeDirName: G:\TrainingSample
vecFileName: pos.vec
bgFileName: neg\neg.txt
numPos: 20
numNeg: 20
numStages: 3
precalcValBufSize[Mb] : 256
precalcIdxBufSize[Mb] : 256
stageType: BOOST
featureType: LBP
sampleWidth: 64
sampleHeight: 32
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
===== TRAINING 0-stage =====
<BEGIN
POS count : consumed 20 : 20
NEG count : acceptanceRatio 20 : 1
Precalculation time: 0.102
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 0|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 0 minutes 0 seconds.
===== TRAINING 1-stage =====
<BEGIN
POS count : consumed 20 : 20
NEG count : acceptanceRatio 20 : 0.833333
Precalculation time: 0.095
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 0|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 0 minutes 1 seconds.
===== TRAINING 2-stage =====
<BEGIN
POS count : consumed 20 : 20
NEG count : acceptanceRatio 20 : 0.555556
Precalculation time: 0.1
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 0|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 0 minutes 2 seconds.
-------------
F:\opencv249\opencv\build\x64\vc12\bin>opencv_traincascade.exe -data "G:\TrainingSample" -vec pos.vec -bg "neg\neg.txt" -numPos 20 -numNeg 20 -numStages 6 -mem 256 -featureType LBP -w 64 -h 32
PARAMETERS:
cascadeDirName: G:\TrainingSample
vecFileName: pos.vec
bgFileName: neg\neg.txt
numPos: 20
numNeg: 20
numStages: 6
precalcValBufSize[Mb] : 256
precalcIdxBufSize[Mb] : 256
stageType: BOOST
featureType: LBP
sampleWidth: 64
sampleHeight: 32
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
Stages 0-4 are loaded
===== TRAINING 5-stage =====
<BEGIN
POS count : consumed 20 : 20
-
-----