2

I'm trying to train a Haar Cascade classifier to recognise a specific face. As far as I know, I've done everything else properly (I've got about 800 negative images, 40 positive images turned into 2000 ish samples, merged with mergevec.py, etc).

When I run the following command:

opencv_traincascade.exe -data classifier -vec samples\samples.vec -bg negatives.txt -numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 2050 -numNeg 730 -w 150 -h 200 -mode ALL -precalcValBufSize 1024 -precalcIdxBufSize 1024

The console gives no output, remains at a blank console for about 2-3 minutes, and then finishes. My memory usage and CPU usage both spike to suggest that something is happening, but nothing is outputted in the classifier directory. I'm not 100% sure that numPos and numNeg are correct (I'm fairly certain, and I've checked, but it's difficult to know for certain after it's been merged), but surely there should be some kind out output anyway?

If you need any more information, please let me know.

  • you could add some debug output in the traincascade opencv code and compile the app again (it is open source) to find out what's happening. Or you could reduce minHitrate, maybe there is no feature that works for your parameters, although I never seen such a case. – Micka Jul 03 '18 at 20:32
  • @Micka I reduced the minHitRate to 0.01 and the same thing happens. No idea where to begin adding debug code in as I don't know C++, and it'd be a ballache to recompile OpenCV as I don't have a working Linux installation at the moment :/ I think there has to be some kind of other issue here, as the minute `traincascade` is run it's supposed to log the parameters and inform you that it's about to start training. Any other ideas? – Elliott Weaver Jul 03 '18 at 20:38
  • the console really should output something immediately... can you try the command without any parameters at all to test general xonsole output for that app? – Micka Jul 03 '18 at 20:44
  • if you are on windows 10 make sure your console is not in "edit mode" (which is activated when you click the window). You xan leave that mode by pressing enter. Afair the window title changes in edit mode, but not aure... – Micka Jul 03 '18 at 20:46
  • you should (for debugging) try smaller sizes, too. -w 150 -h 200 is really enomous for cascade classifiers and maybe that could be a problem?!? – Micka Jul 03 '18 at 20:50
  • It prints the parameters if I specify too few, and prints the usage if I specify none (as intended)! I'm trying to tinker to see if I can mess with the parameters to get it to work. I'm a little concerned about changing -w and -h as I've kept them the same throughout. I know they're really high but it should still do something, right? Is it ok to change them even though all the samples are 150×200? If so, what can I change them to? 15×20? EDIT: Tried changing the sizes- it screamed at me (not literally, it just gave me a warning that they didn't correspond to the vector size) – Elliott Weaver Jul 03 '18 at 20:54
  • Nevermind. I was accidentally calling opencv_createsamples for those tests I just did. If I specify too few parameters it just errors with "Bad argument". If I specify none, it gives me the usage thing. – Elliott Weaver Jul 03 '18 at 21:04
  • Update: decreasing -w and -h to 15 and 20 respectively gets the parameters to print, but now there's an error I'm assuming is down to the fact that I'm using the incorrect sizes. `OpenCV(3.4.1) Error: Assertion failed (_img.rows * _img.cols == vecSize) in CvCascadeImageReader::PosReader::get, file C:\build\master_winpack-build-win64-vc14\opencv\apps\traincascade\imagestorage.cpp, line 153` I'll have a tinker :) – Elliott Weaver Jul 03 '18 at 21:12
  • you would have to create new .vec files to test with smaller samples. – Micka Jul 04 '18 at 02:02
  • I think I fixed it. Now I've just got to figure out the right number to use for numPos, as it doesn't seem to work with the correct amount... :/ – Elliott Weaver Jul 04 '18 at 22:04
  • the correct amount should work in the first stage, but later postives are lost (unless you've got a 100% hit rate) so the training will need more additional positives. For 0.999 mhr I typically choose -10% of max pos samples – Micka Jul 05 '18 at 05:24
  • Yep. It gets up to about stage 6 and then stops working. I found some formula on here that I'm gonna try next. It probably works out to about 10%. Should I be using a hitrate of 0.999? I stuck to the default 0.995. – Elliott Weaver Jul 05 '18 at 06:16
  • parameter choice depends on your application and you maybe should try both or multiple settings and cimpare then. With 0.995 you'll need more positive samples. The formula is right, if you assume all your unused positive samples to not fail from previous stages. – Micka Jul 05 '18 at 09:05

0 Answers0