C++ OpenCV detectMultiScale() 参数的推荐值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20801015/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Recommended values for OpenCV detectMultiScale() parameters
提问by torayeff
What are the recommended parameters for CascadeClassifier::detectMultiScale()
and depending on which factors I should change default parameters?
CascadeClassifier::detectMultiScale()
我应该根据哪些因素更改默认参数的推荐参数是什么?
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() )
回答by herohuyongtao
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.
scaleFactor
– 指定图像大小在每个图像比例下缩小多少的参数。基本上,比例因子用于创建您的比例金字塔。更多解释可以在这里找到。总之,作为描述在这里,你的模型训练过程中定义一个固定的大小,也就是在可见光
xml
。这意味着在图像中检测到此大小的人脸(如果存在)。但是,通过重新缩放输入图像,您可以将较大的人脸调整为较小的人脸,使其可被算法检测到。1.05
是一个很好的可能值,这意味着您使用一小步来调整大小,即将大小减少 5%,您增加了找到与模型匹配的大小的机会以进行检测。这也意味着该算法的运行速度较慢,因为它更彻底。您可以将其增加到 1.4 以加快检测速度,但可能会完全遗漏某些人脸。minNeighbors
– 指定每个候选矩形应保留多少邻居的参数。该参数会影响检测到的人脸的质量。值越高,检测次数越少,但质量越高。
3~6
物有所值。minSize
– 最小可能的对象大小。小于该值的对象将被忽略。此参数确定您要检测的大小。你来决定!通常,这
[30, 30]
是人脸检测的良好开端。maxSize
– 最大可能的对象大小。大于此值的对象将被忽略。这个参数决定了你想检测多大的尺寸。再次,你决定!通常,您不需要手动设置它,默认值假设您要检测的人脸大小没有上限。
回答by The Beast
If you have a good CPU and RAM performance or more you can set scaleFactor=1 minNeighbors=3
如果您有良好的 CPU 和 RAM 性能或更高,您可以设置 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 .
如果你在像树莓派这样的嵌入式系统中工作,我建议选择像 scaleFactor=2 这样的 smth,(较高的值意味着较低的准确性)minNeighbors = 1,(较高的值意味着较低的准确性但更高的可靠性)算法将运行得更快,否则如果 CPU 性能和 RAM 不够,它会死机。
hope it helps
希望能帮助到你
回答by Milind Morey
cl_int err;
cl_uint numPlatforms;
err = clGetPlatformIDs(0, NULL, &numPlatforms);
if (CL_SUCCESS == err)
printf("\nDetected OpenCL platforms: %d", numPlatforms);
else
printf("\nError calling clGetPlatformIDs. Error code: %d", err);
string str ="haarcascade_frontalface_alt2.xml";
ocl::OclCascadeClassifier fd;
fd.load(str);
ocl::oclMat frame, frameGray;
Mat frameCpu;
CvVideoCapture vcap = openVideo("0");
vcap.set(CV_CAP_PROP_FRAME_WIDTH,320);
vcap.set(CV_CAP_PROP_FRAME_HEIGHT,240);
static const cv::Size maxSize;
for(;;){
// // processing loop
vector<Rect> faces;
vcap >> frameCpu;
frame = frameCpu;
ocl::cvtColor(frame, frameGray, CV_BGR2GRAY);
//ocl::equalizeHist(frameGray, frameGray);
//Mat mm(frameGray);
//cvWaitKey(100);
fd.detectMultiScale(frameGray,faces,1.05,3,0|CV_HAAR_FIND_BIGGEST_OBJECT ,minSize,maxSize);
for(int i=0; i< faces.size() ; i++)
{
if(faces.size())
//circle(img, Point(palm[i].x+ palm[i].width/2,palm[i].y+palm[i].height/2),palm[i].width,Scalar(255,0,0), 2,8 );
cv::rectangle(frameCpu, faces[i],Scalar(255,0,0), 2,8 );
}
imshow("fsfs",frameCpu);
cvWaitKey(1);