Ask Your Question
2

CascadeClasifier detectMultiScale arguments

asked 2012-07-27 16:25:05 -0600

George Profenza gravatar image

Hello, I'm an opencv/c++ noob so please bare with me. I was looking at the objectdetect sample and tried it with a couple of body detection cascades(haarcascade_fullbody/haarcascade_upperbody/haarcascade_lowerbody,haarcascade_mcs_upperbody) on some footage I took with a camera of a pedestrian bridge. So far so good, but it's a demanding functionality.

I though thinks might run smoother if I pass the min/max Sizes since my camera is always in the same place and I figure out the min/max bounding boxes. Unfortunately I ran into syntax errors when trying to do so:

//my call
body.detectMultiScale( gray, bodies, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, cv::Size(30, 30),cv::Size(0,0),cv::Size(5,13),cv::Size(45,80));
//errors:
main.cpp:43: error: no matching function for call to 'cv::CascadeClassifier::detectMultiScale(cv::Mat&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, double, int, int, cv::Size, cv::Size, cv::Size, cv::Size)'
/opt/local/include/opencv2/objdetect/objdetect.hpp:383: note: candidates are: virtual void cv::CascadeClassifier::detectMultiScale(const cv::Mat&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, double, int, int, cv::Size, cv::Size)
/opt/local/include/opencv2/objdetect/objdetect.hpp:393: note:                 virtual void cv::CascadeClassifier::detectMultiScale(const cv::Mat&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, std::vector<int, std::allocator<int> >&, std::vector<double, std::allocator<double> >&, double, int, int, cv::Size, cv::Size, bool)

I simply added two cv::Size objects as the min max, but to be honest I'm not sure: 1. Why the previous arguments are Size() objects as well when the docs list them as ints ? 2. Am I looking at the wrong docs or at the docs in a wrong way ?

C++: void CascadeClassifier::detectMultiScale(const Mat& image, vector<rect>& objects, double scaleFactor=1.1, int minNeighbors=3, int flags=0, Size minSize=Size(), Size maxSize=Size())

from docs.

Would this improve detection by much ? Also, I'm thinking about running the detection every few frames (not all the time) and track the detected points. What functions should I look for to tell OpenCV to track specified coordinates ?

Thanks!

edit retag flag offensive close merge delete

Comments

Regarding the point tracking I just the lkdemo sample which is awesome !

George Profenza gravatar imageGeorge Profenza ( 2012-07-27 16:39:25 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
9

answered 2012-07-28 04:25:50 -0600

Kirill Kornyakov gravatar image

It seems that you're confused by the meaning of min and max sizes, but may be I'm wrong. Why do you provide 4 cv::Size instead of just 2? Do you think that these are positions, aka ROI where the algorithm should detect objects?

Your call should look something like this:

//my call
body.detectMultiScale( gray, bodies, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, cv::Size(30,30),cv::Size(480,480));

That will mean that the algorithm will search the entire image for objects which are larger than 30x30 pixels, but smaller than 480x480. Please also note that it can't improve the quality of your algorithm, it is just a method to improve your performance. minSize allows you to greatly reduce the detection time, make it as large as you can. In fact providing these sizes may improve your quality, but only by reducing the number of false positives, because you don't even search for too small and too large objects.

And finally I'm not sure that maxSize will work for Haar-cascade, it may be a limitation of the current implementation. But minSize should work and give you some visible speedup.

In order to limit the search space you should create a submatrix and run the detection on it.

edit flag offensive delete link more

Comments

Thanks! this is very well explained. Unfortunately I can't vote up yet :(

George Profenza gravatar imageGeorge Profenza ( 2012-07-28 05:59:02 -0600 )edit

Question Tools

Stats

Asked: 2012-07-27 16:25:05 -0600

Seen: 5,220 times

Last updated: Jul 28 '12