OpenCV Training Custom Haar Cascade with Python 3

asked 2020-06-28 10:54:26 -0500

I am trying to train a haar cascade on my face. I have everything setup including the positive, negetive, the vec file, etc. but when I run the opencv_traincascade, it gave me a terminate called after throwing an instance of 'std::bad_alloc' error. Then I added this line to my arguments -nonsym -mem 512 and it gave me this error:terminate called after throwing an instance of 'std::logic_error'.

Here is the command I am running:

opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt\
>    -numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 1000\
>    -numNeg 600 -w 80 -h 40 -mode ALL -precalcValBufSize 1024\
>    -precalcIdxBufSize 1024\
>    -nonsym\
>    -mem 512\

Any help would be greatly appreciated!

edit retag flag offensive close merge delete


with Python 3

those are all c++ cmdline tools, python does not matter here

(sidenote: if you can still use those, you must be on an outdated opencv version)

berak gravatar imageberak ( 2020-06-28 12:10:17 -0500 )edit


you're out of memory

berak gravatar imageberak ( 2020-06-28 12:10:54 -0500 )edit

-w 80 -h 40

far too large, most likely the reason for being "out of memory"

berak gravatar imageberak ( 2020-06-28 12:12:29 -0500 )edit

I am trying to train a haar cascade on my face

no, it won't work.

and this is the real "bummer" in your question

it's a detection tool not a classification one. (you cannot train this for your face)

(you clearly misunderstood something here reason for downvote)

berak gravatar imageberak ( 2020-06-28 12:14:58 -0500 )edit