69

What are the recommended parameters for CascadeClassifier::detectMultiScale() and depending on which factors I should change default parameters?

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() )
0

2 Answers 2

167

Amongst these parameters, you need to pay more attention to four of them:

  • scaleFactor – Parameter specifying how much the image size is reduced at each image scale.

    Basically the scale factor is used to create your scale pyramid. More explanation can be found here. In short, as described here, your model has a fixed size defined during training, which is visible in the xml. This means that this size of face is detected in the image if present. However, by rescaling the input image, you can resize a larger face to a smaller one, making it detectable by the algorithm.

    1.05 is a good possible value for this, which means you use a small step for resizing, i.e. reduce size by 5%, you increase the chance of a matching size with the model for detection is found. This also means that the algorithm works slower since it is more thorough. You may increase it to as much as 1.4 for faster detection, with the risk of missing some faces altogether.

  • minNeighbors – Parameter specifying how many neighbors each candidate rectangle should have to retain it.

    This parameter will affect the quality of the detected faces. Higher value results in less detections but with higher quality. 3~6 is a good value for it.

  • minSize – Minimum possible object size. Objects smaller than that are ignored.

    This parameter determine how small size you want to detect. You decide it! Usually, [30, 30] is a good start for face detection.

  • maxSize – Maximum possible object size. Objects bigger than this are ignored.

    This parameter determine how big size you want to detect. Again, you decide it! Usually, you don't need to set it manually, the default value assumes you want to detect without an upper limit on the size of the face.

21
  • 1
    are image pyramids used in combination with sliding window techniques? Isn't it true that if we're using a sliding window that scans the image at different scales and different sizes, then we don't need to use image pyramids?
    – user961627
    May 18, 2014 at 13:22
  • 4
    and what does "minNeighbors" refer to? is it about pruning excessive detections around the same face?
    – user961627
    May 18, 2014 at 13:23
  • 3
    @user961627 Yes, image pyramids and sliding window techniques are combined being used. If you use a sliding window that scans the image at different scales and different sizes, you don't need to use image pyramids anymore as image pyramids just up/down-samples images when processing. For minNeighbors, yes, it is about pruning excessive detections around the same face. Please refer to the answer for the description. May 18, 2014 at 15:50
  • 4
    @Micka Don't 100% agree on scaleFactor. In fact, you want it as high as possible while still getting "good" results, and this must be determined somewhat empirically. It's heavily dependent on the target to be detected, the type of cascade and the training; Even and a value as high as 1.1 for a 24x24 FD cascade has worked for me in the past. A too low value for either scaleFactor or minSize will result in huge computational costs because many more pyramid layers need to be generated. A factor of 1.05 requires roughly double the # of layers (and >2x the time) than 1.1 does. Jan 13, 2015 at 14:37
  • 2
    @IwillnotexistIdonotexist that's obviously true, sorry I didn't mention it. I just wanted to say that it is possible to let the detector choose window sizes to someones exact needs and that scaleFactor can be computed to fulfill those needs. But it is hard to recommend a value without knowing the size of the trained window and the min/max size in combination with the constraints to computational time and detection sensitivity/specifity :)
    – Micka
    Jan 13, 2015 at 16:09
-6

If you have a good CPU and RAM performance or more you can set scaleFactor=1 minNeighbors=3

if you're working in an embedded system like in raspberry i recommand to choose smth like scaleFactor= 2, (Higher values means less accuracy) minNeighbors = 1, (Higher values means less accuracy but more reliability) the algorithm will run much faster otherwise it will freeze if the CPU performance and RAM are not enough .

hope it helps

1
  • 3
    ScaleFactor should always be greater than 1, something like 1.05 for good CPU and RAM. Jan 14, 2016 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.