├── classifier
├── createsamples.pl
├── mergevec.py
├── neg
│ ├── download1.jpg
│ ├── negative images
├── negatives.txt
├── pos
│ ├── download1.jpg
│ ├── positive images
├── positives.txt
├── samples
│ ├── download1.jpg.vec
│ ├── download3.jpg.vec
│ └── images.jpg.vec
└── sample.vec
This is the file structure for my project.
Since this is for learning, I have used 4 positive images and 10 negative images.
perl createsamples.pl positives.txt negatives.txt samples 4 "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 40 -h 30"
This is the perl script to generate sample vec files.
I merge them using this mergevec.py file.
I read in this tutorial that -w
and -h
should be in the ratio of the positive images.
My positive images are 480 X 360
.
Thus my perl script has -w 40 -h 30
as args.
opencv_traincascade -data classifier -vec sample.vec -bg negatives.txt -numStages 3 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 4 numNeg10 -w 40 -h 30 -mode ALL -precalcValBufSize 1024-precalcIdxBufSize 1024
On running this , I get
===== TRAINING 0-stage =====
OpenCV Error: Assertion failed (_img.rows * _img.cols == vecSize) in get, file /build/opencv-SviWsf/opencv- 2.4.9.1+dfsg/apps/traincascade/imagestorage.cpp, line 157
terminate called after throwing an instance of 'cv::Exception' what(): /build/opencv-SviWsf/opencv- 2.4.9.1+dfsg/apps/traincascade/imagestorage.cpp:157: error: (-215) _img.rows * _img.cols == vecSize in function get
Aborted (core dumped)
I get this ouput on running opencv_traincascade
PARAMETERS:
cascadeDirName: classifier
vecFileName: sample.vec
bgFileName: negatives.txt
numPos: 4
numNeg: 1000
numStages: 3
precalcValBufSize[Mb] : 256
precalcIdxBufSize[Mb] : 256
stageType: BOOST
featureType: HAAR
sampleWidth: 24
sampleHeight: 24
boostType: GAB
minHitRate: 0.999
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: BASIC
Why does it show 24 in sampleWidth
and sampleHeight
and what should I do to successfully train.
Thank you.