IKS
IKS

Reputation: 119

Face detector in OpenCV becoming slow when there is no face in the frame

I am trying to implement face detection program with webcam input using Viola-Jones face detector in OpenCV and it works fine except that it becomes about 10 times slower when no face is detected in the frame.

This is really weird because if there is no face in the frame, most of the windows will be rejected in the earlier stages of the cascade and it should be slightly faster I guess (NOT SLOWER!).

I am using detectMultiScale function (not cvHaarDetectObjects function) for some reasons but I don't think this should matter in any way.

Can anyone give me an advice on this problem please? Thanks in advance.

Upvotes: 0

Views: 720

Answers (1)

Ulpaso
Ulpaso

Reputation: 120

Did you try to add the min and the max size of the face rectangle to be detected ? You can also check your pyramid scale value, it must be > 1, and if it is too slow, try to use a highter value, the detection will not be as good but it will be faster.

    cv::CascadeClassifier cascade;
    // ... init classifier
    cv::Mat grayImage;
    // ... set image
    std::vector<cv::Rect> > results;
    cv::Size minSize(60,60);
    cv::Size maxSize(80,80);
    int minNeighbors= 3; // edited
    float pyramidScale = 1.1f;

    cascade.detectMultiScale(grayImage, results, pyramidScale, minNeighbors,
            0 , minSize, maxSize);

Upvotes: 2

Related Questions