Recommended values for OpenCV detectMultiScale() parameters

微笑、不失礼 提交于 2019-11-27 10:11:34
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.

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

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!