Ask Your Question
0

Haar Classifier does not work, only one feature seems to be trained.

asked 2018-02-27 11:45:54 -0600

Joshitha gravatar image

updated 2018-02-27 12:44:58 -0600

berak gravatar image

II have been trying to use OpenCV to create my own Haar Cascade Classifier to detect cows from images.

  • Number of positive images:83 , size 430x 280 px, .bmp format
  • Number of negative images:200, size 640x480px

My images aren't of that good a quality:

image description

used this to create the samples:

createsamples.exe -info positive/info.txt -vec vector/vector.vec -num 100000 -w 24 -h 24

used this to train:

haartraining.exe -data cascades -vec vector/vector.vec -bg negative/bg.txt -npos 83 -nneg 200 -nstages 18 -mem 2000 -mode ALL -w 24 -h 24

rem -nonsym

And this is a snippet of the training. I realized only one feature is being used (correct me if I am wrong)

Parent node: 6 Chosen number of splits: 0

Total number of splits: 0

Tree Classifier Stage +---+---+---+---+---+---+---+---+ | 0| 1| 2| 3| 4| 5| 6| 7| +---+---+---+---+---+---+---+---+

0---1---2---3---4---5---6---7

Parent node: 7

* 1 cluster * POS: 7 7 1.000000 NEG: 16 1.80409e-005 BACKGROUND PROCESSING TIME: 16.41 Precalculation time: 0.41 +----+----+-+---------+---------+---------+---------+ | N |%SMP|F| ST.THR | HR |
FA | EXP. ERR| +----+----+-+---------+---------+---------+---------+ | 1|100%|-| 0.882353| 1.000000| 0.062500| 0.043478| +----+----+-+---------+---------+---------+---------+ Stage training time: 0.12 Number of used features: 1

Parent node: 7 Chosen number of splits: 0

Total number of splits: 0

Tree Classifier Stage +---+---+---+---+---+---+---+---+---+ | 0| 1| 2| 3| 4| 5| 6| 7| 8| +---+---+---+---+---+---+---+---+---+

0---1---2---3---4---5---6---7---8

It ran upto 8 stages in less than 3mins !

I used this to convert to an xml file:

haarconv.exe cascades myhaar.xml 24 24

My python code uses this xml and can not detect a cow from the positive data set itself. Where am I going here?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-02-27 11:54:55 -0600

berak gravatar image

updated 2018-02-27 12:06:47 -0600

it's amazing, what kind of things folks are trying to train a cascade on ..

i don't want to discourage you entirely, trying this, but your attempt suffers from:

  • pose problem. you'd need to train 2 classifiers, like cow_frontal, and cow_profile (and flip images for the latter, lookup, how this is done for faces)
  • texture problem, no cow skin is the same, that's bad. terrible. total bummer.
  • not enough images. you'd need like ~ 10 to 100 times more
  • -w=24 -h=24, that's probably too small, and the wrong shape(distortion). w=64, h=32 might work much better

also note, there's a pretrained cow detector in opencv_contrib/dpm, also there are pretrained dnn's that can detect cows (and then, re-training / transfer-learning (ssd or yolo) cnn's can be done with a surprisingly low amount of images, look it up !)

My images aren't of that good a quality

it's not bad at all, the problem is more a fundamental / systemic one.

edit flag offensive delete link more

Comments

Thank you for your suggestions. Also, a minor clarification, does -w and -h signify the size of the window the Haar algorithm will use to sample the images?

Joshitha gravatar imageJoshitha ( 2018-02-28 01:07:12 -0600 )edit

yes ..

also, if you want to train a"cow-profile" classifier, make sure, the head is always on the same side (evt. flip train images)

berak gravatar imageberak ( 2018-02-28 01:30:57 -0600 )edit

Will try this and let you know what happens. Thanks

Joshitha gravatar imageJoshitha ( 2018-02-28 10:24:13 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-02-27 11:45:54 -0600

Seen: 833 times

Last updated: Feb 27 '18