0

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& objects, double scaleFactor=1.1, int minNeighbors=3, int flags=0, Size minSize=Size(), Size maxSize=Size())

from docs.

George Profenza
  • 50,687
  • 19
  • 144
  • 218
  • Why are you passing `cv::Size` for `minNeighbors` and `flags`? – Mohammad Jul 28 '12 at 00:01
  • That's one of the questions I had. I simply copied the call from the [objectdetect.cpp](https://code.ros.org/trac/opencv/browser/trunk/opencv/samples/cpp/tutorial_code/objectDetection/objectDetection.cpp?rev=6483) sample – George Profenza Jul 28 '12 at 08:44
  • The main reason is to get to the `minSize`, `maxSize` arguments which I haven't found a setter method for, so the constructor seems the only access point. – George Profenza Jul 28 '12 at 08:51

2 Answers2

3

It seems I was passing the wrong arguments. This worked:

body.detectMultiScale(gray,bodies,1.1,3,3,cv::Size(5,13),cv::Size(45,80));
George Profenza
  • 50,687
  • 19
  • 144
  • 218
  • have you tried [the documentation](http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html?highlight=detectmultiscale#cascadeclassifier-detectmultiscale) ? `Python: cv.HaarDetectObjects(image, cascade, storage, scale_factor=1.1, min_neighbors=3, flags=0, min_size=(0, 0)) → detectedObjects` – George Profenza Jun 25 '14 at 11:05
  • Yes yes, I made the program, forgot that I had commented. It's all good now. :) – praxmon Jun 25 '14 at 11:06
  • Hi George, from where I can get the cascades for the human detection? Do you think this will work in real time with multiple cameras? – PeakGen Jul 01 '14 at 07:31
  • In your opencv install path or opencv source folder you will find these haar cascade files: `haarcascade_fullbody.xml`,`haarcascade_lowerbody.xml`,`haarcascade_upperbody.xml`. Regarding real time and multiple cameras it totally depends on the setup(the scene: how complex is it, the lighting: how good is it, the camera: how much control do you have over the settings, etc.). Haar cascades are slower than LBP cascades for example, so I recommend you scale the webcam frames down, do the detection, then scale the resulting detection rectangles back up. You will need to tweak values to find the best – George Profenza Jul 01 '14 at 10:52
0

Faced same issue in my case. Following line worked for me. If you consider, I am only providing the minimum size cv::Size(45,80). I am still investigating about other parameters but this is working currently.

haar_cascade.detectMultiScale(gray,faces,1.1,3,3,cv::Size(45,80));
NightFury
  • 13,436
  • 6
  • 71
  • 120