mrgloom
mrgloom

Reputation: 21602

How to force detectMultiScale search on 1:1 scale?

How to force OpenCV CascadeClassifier::detectMultiScale function search only on 1:1 scale?

How many scales used by default?

UPD: Found relate code: https://github.com/Itseez/opencv/blob/cc92cd07e8d6a54dfd57d5f74c3d4e05b1d956af/modules/objdetect/src/cascadedetect.cpp

for( double factor = 1; ; factor *= scaleFactor )
{
Size originalWindowSize = getOriginalWindowSize();

Size windowSize( cvRound(originalWindowSize.width*factor), cvRound(originalWindowSize.height*factor) );
if( windowSize.width > maxObjectSize.width || windowSize.height > maxObjectSize.height ||
windowSize.width > imgsz.width || windowSize.height > imgsz.height )
break;
if( windowSize.width < minObjectSize.width || windowSize.height < minObjectSize.height )
continue;
scales.push_back((float)factor);
}

Upvotes: 0

Views: 802

Answers (1)

akarsakov
akarsakov

Reputation: 2154

Number of scales used in CascadeClassifier::detectMultiScale depends on image size, original trained window size, minObjectSize, maxObjectSize and scaleFactor parameters. It loops through all the scales starting with 1 in increments of scaleFactor until one of the conditions:

  • current window size is larger image size
  • current window size is larger maxObjectSize

So there are several possibilities to reduce number of scales used in `CascadeClassifier::detectMultiScale:

  1. Set maxObjectSize parameter equal to original trained size. It guaranties that cascade will use only 1:1 scale.
  2. Set scaleFactor parameter to extremely large value (1000 for example). Thus next scale after 1 will not be used since window size is much larger than image size. It's dirty hack as for me.

Please be sure that you tune minNeighbors parameter. If you would use only one scale you will get very few candidates, so to detect something you need you must decrease this parameter.

Upvotes: 2

Related Questions