i've been trying to write an app that recognizes the cap of a pencil (in this case).
i've been taking about 40 pictures of the object, and 635 pictures without the object. then i've been using the perl script "createsamples.pl" to generate 3000 positive images from the 40 positive pictures with this command (i also tried to generate 1500 images, same result):
createsamples.pl p.dat n.dat output
p.dat is the file with the names of the 40 positive images, n.dat is the file with the names of the 636 negative images.
i've been merging the created vector files into one vector file, then i've been trying to start the training like this:
opencv_traincascade -data cascades -vec samples.vec -bg n.dat -numPos 1000 -numNeg 635 -numStages 1 -w 20 -h 20 -featureType LBP
this finished in a few seconds, but gave me countless false detections when i tried it in my app.
so i tried again with more stages, up to 20.
===== TRAINING 19-stage =====
BEGIN
POS count : consumed 2000 : 2302
NEG count : acceptanceRatio 635 : 0.000145818
Precalculation time: 1.487
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 1|
+----+---------+---------+
| 2| 0.997| 0.829921|
+----+---------+---------+
| 3| 0.997| 0.829921|
+----+---------+---------+
| 4| 0.9985| 0.856693|
+----+---------+---------+
| 5| 0.9965| 0.694488|
+----+---------+---------+
| 6| 0.9955| 0.645669|
+----+---------+---------+
| 7| 0.9955| 0.6|
+----+---------+---------+
| 8| 0.996| 0.579528|
+----+---------+---------+
| 9| 0.9955| 0.544882|
+----+---------+---------+
| 10| 0.9955| 0.540157|
+----+---------+---------+
| 11| 0.9955| 0.359055|
+----+---------+---------+
END>
on the this stage, i still got false detections, not that many anymore, but they are still there.
so i tried more stages, up to 30. but on the 21st stage training, i already got this acceptance ratio:
===== TRAINING 20-stage =====
BEGIN
POS count : consumed 2000 : 2320
NEG count : acceptanceRatio 635 : 9.72903e-005
Precalculation time: 1.493
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 1|
+----+---------+---------+
| 2| 0.997| 0.831496|
+----+---------+---------+
| 3| 0.997| 0.831496|
+----+---------+---------+
| 4| 0.999| 0.779528|
+----+---------+---------+
| 5| 0.9955| 0.64252|
+----+---------+---------+
| 6| 0.9965| 0.694488|
+----+---------+---------+
| 7| 0.9955| 0.689764|
+----+---------+---------+
| 8| 0.9955| 0.628346|
+----+---------+---------+
| 9| 0.996| 0.645669|
+----+---------+---------+
| 10| 0.9965| 0.541732|
+----+---------+---------+
| 11| 0.9955| 0.43622|
+----+---------+---------+
END>
this acceptance ratio means that the classifier is overtrained, right? atleast thats what people mentioned on stackoverflow on a few questions.
im using a videocapture and hold the object (cap of pencil) in front of the camera in order to detect it. in most of the frames it still gets detected, but any other object that lies on the same background as the cap is getting detected aswell.
the 40 positive pictures look like that:
https://i.stack.imgur.com/7H5XM.jpg
10 of them were taken on a gray background, 10 were taken on a red background, 10 were taken on a silver background, 10 were taken with the cap lying on my keyboard.
so all in all, my questions:
1) are the 40 pictures i am using ok to use? or are the supposed to have no background in them at all? because right now, when im pointing my videocapture at the red background i was using before, then i get false detections. example of what happens (REMOVE SPACE PLEASE): http: //i.imgur.com/w0szcTh.jpg?1
2) am i totally on the wrong way to reach my goal?
3) the best tutorial i found about what im trying was this one: http://coding-robin.de/2013/07/22/train-your-own-opencv-haar-classifier.html his pictures show background aswell, but it seems he does not get false detections. do you know what else could be wrong with my approach?
thanks in advance guys, i hope any of you can help me out here.