Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
927 views
in Technique[技术] by (71.8m points)

c++ - OpenCV: how to create .vec file to use with opencv_traincascade

As I explained in my previous post here, I am trying to generate some cascade.xml files to recognize euro coins to be used in my iOS app. Anyway, I am founding many difficulties in understanding how to generate a .vec file to give as input to opencv_traincascade. This because I heard many dissenting views: someone told me that vector file must include only positive images containing only the object to recognize; someone else instead (and also as read in my tutorials) said that vector file must include "samples" images, in other words random backgrounds to which the object to recognize has been added by opencv_createsamples. In oter words with:

opencv_createsamples -img positives/1.png -bg negatives.txt -info 1.txt -num 210 -maxxangle 0.0 -maxyangle 0.0 -maxzangle 0.9 -bgcolor 255 -bgthresh 8 -w 48 -h 48

which generated 12000 images. Finally, I have created the .vec file with:

cat *.txt > positives.txt

opencv_createsamples -info positives.txt -bg negatives.txt -vec 2.vec -num 12600 -w 48 -h 48

So, I would like to ask you which the correct images to be contained in vector files from the following two:

enter image description here

enter image description here

Moreover, which is the final command to give to launch the training? This is the ones I have used up to now:

opencv_traincascade -data final -vec 2.vec -bg negatives.txt -numPos 12000 -numNeg 3000 -numStages 20 -featureType HAAR -precalcValBufSize 2048 -precalcIdxBufSize 2048 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -w 48 -h 48 -mode ALL

where the .vec files contains 12000 samples images (background + coin to recognize). Should the .vec file contain only positive images (only coins), how shall I tell opencv_traincascade to train using the samples images?

I really need to know how to do things correctly because I have launched many training which then lead to no correct result and since they take many hours or days to execute, I can't waste time anymore.

Thank to all for your attention.

UPDATE I managed to create a cascade.xml file with LBP. See what happens if I give one of the image used as training samples to a simple OpenCV program:

enter image description here

while with an image like the following:

enter image description here

it does not work at all. I really don't know where I am making the mistake.

UPDATE Maybe firstly converting positive images to gray scale could help? enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I've used the negative samples database of the INRIA training http://pascal.inrialpes.fr/data/human/

and this input (png with alpha transparency around the coin):

enter image description here

using this with this command:

opencv_createsamples -img pos_color.png -num 10 -bg neg.txt -info test.dat -maxxangle 0.6 -maxyangle 0 -maxzangle 0.3 -maxidev 100 -bgcolor 0 -bgthresh 0

produces output like this:

enter image description here

enter image description here

so background color obviously didn't work. Converting to grayscale in the beginning however gives me this input:

enter image description here

and same command produces output like this:

enter image description here

enter image description here

enter image description here

enter image description here

I know this is no answer to all of your questions, but maybe it still helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...