检测多尺度大小始终为0

时间:2016-08-18 08:11:27

标签: c++ opencv java-native-interface face-detection

我正在使用Android中的原生OpenCV简单的FaceDetector。我有c ++本机代码,我想在那里进行检测。但结果始终为0.级联分类器负载很好。我不明白为什么不检测任何脸。

这是我的代码:

CascadeClassifier face_cascade;
Face_Alignment face_alignment;
face_cascade.load(fn_haar);

if (face_cascade.empty()) {
    cout << "Error loading face_cascade. Check path" << endl;
    return;
}
else {
    cout << "Face_cascade loaded" << endl;
}


// Find face in image:
cv::Rect roi_face = face_alignment.detect_face(image, face_cascade);

if(roi_face == Rect())
{
    cout << "No face detected" << endl;
    return;
}

Rect Face_Alignment::detect_face(const cv::Mat & image, cv::CascadeClassifier cascade)
{
    const double scale_factor = 1.1;
    const int min_neighbours = 3;
    const int flags = CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_DO_CANNY_PRUNING | CV_HAAR_SCALE_IMAGE;
    const Size min_size = Size(48, 48);
    const Size max_size = Size();

    if (cascade.empty() || image.empty()) {
        return Rect();
}

    vector<Rect> faces;
    cascade.detectMultiScale(image, faces, scale_factor, min_neighbours, flags, min_size, max_size);

    if (faces.empty())
         return Rect();

    return faces.front();
}

如果有人能帮助我,我将不胜感激。 谢谢!

0 个答案:

没有答案