Ask Your Question

Problem with Cascade Classifier

asked 2016-12-08 08:23:37 -0600

Tobyy gravatar image

updated 2016-12-09 07:03:24 -0600

I've problems with the Cascade Classifer. I created 5000 positive samples like this: image description

with this command:

C:\OpenCV31\opencv\build\x64\vc14\bin\opencv_createsamples.exe -img C:\CreateSamples\test\image6.jpg -vec gew.vec -bg neg.txt -num 5000 -w 80 -h 80 -show -maxyangle 0.0 -maxzangle 0.0 -maxxangle 0.5 -bgcolor 0

then i trained a classifier like this:

C:\OpenCV31\opencv\build\x64\vc14\bin\opencv_traincascade.exe -data NEWclassifier -vec gew.vec -bg neg.txt -numStages 15 -numPos 2500 -numNeg 1500 -w 80 -h 80 -precalcValBufSize 4048 -precalcIdxBufSize 4048 -featureType LBP

and get this result:

image description

The Problem is: it detects nearly everything as an object:

I used this image: image description

and get this:

image description

I'm new with Cascade Classifier and read a lot of tutorials and samples, but i don't get my mistake. Can you help me?

I call detectMultiscale like this: face_cascade.detectMultiScale(frame_gray, faces, 1.1, 0, 0, cv::Size(10, 10));

edit retag flag offensive close merge delete



It seems like you generate your positive image samples (5000) from only one image. In general, it is not good. It is better to use real positive images. Also, your negative image samples should be various.

Training a cascade of classifiers is a try and retry process to get a good training set.

Eduardo gravatar imageEduardo ( 2016-12-08 09:20:42 -0600 )edit

How you call detectMultiscale() when get such results? Paste a code here! Maybe you have set min neighbours to zero?

pi-null-mezon gravatar imagepi-null-mezon ( 2016-12-09 06:14:33 -0600 )edit

face_cascade.detectMultiScale(frame_gray, faces, 1.1, 0, 0, cv::Size(10, 10));

Tobyy gravatar imageTobyy ( 2016-12-09 07:04:39 -0600 )edit

setting a higher value for min_neighbours will remove a lot of your false positives

berak gravatar imageberak ( 2016-12-09 08:31:32 -0600 )edit

so, if minNeighbours is equal to zero opencv returns all the rects that was found on detection, try to increase this value to 5 / 7 / 11 /...

pi-null-mezon gravatar imagepi-null-mezon ( 2016-12-09 09:18:22 -0600 )edit

Thank you very much! I've now taken samples from a video and optimized minNeighbours and min Size. It works very well.

Tobyy gravatar imageTobyy ( 2016-12-10 14:25:03 -0600 )edit

Still, it shouldn't detect everything on the screen right? Why would that happen?

stephenc gravatar imagestephenc ( 2016-12-10 22:48:56 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-12-10 23:07:06 -0600

stephenc gravatar image

Is the cascadeclassifier trained correctly? I keep getting the same error on around stage 2 or 3 generally. Can you figure out why that error is happening? What opencv_traincascade are you using? Are you using a pre-compiled one, or one you built yourself?

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-12-08 08:23:37 -0600

Seen: 300 times

Last updated: Dec 09 '16