【问题标题】:Face detection after background substraction using openCv使用openCv进行背景减法后的人脸检测
【发布时间】:2014-03-15 19:32:42
【问题描述】:

我正在尝试改进从相机捕获的面部检测,所以我认为如果在面部检测过程之前我从图像中删除背景会更好, 我使用BackgroundSubtractorMOGCascadeClassifierlbpcascade_frontalface 进行人脸检测,

我的问题是:如何获取前景图像以将其用作人脸检测的输入?这是我目前所拥有的:

while (true) {
    capture.retrieve(image);

    mog.apply(image, fgMaskMOG, training?LEARNING_RATE:0);

    if (counter++ > LEARNING_LIMIT) {
        training = false;
    }

    // I think something should be done HERE to 'apply' the foreground mask 
    // to the original image before passing it to the classifier..

    MatOfRect faces = new MatOfRect();
    classifier.detectMultiScale(image, faces);

    // draw faces rect
    for (Rect rect : faces.toArray()) {
        Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(255, 0, 0));
    }

    // show capture in JFrame
    frame.update(image);
    frameFg.update(fgMaskMOG);

    Thread.sleep(1000 / FPS);
}

谢谢

【问题讨论】:

    标签: opencv javacv face-detection background-subtraction


    【解决方案1】:

    我可以使用 BackgroundSubtractorMOG2 用 C++ 回答:

    您可以使用腐蚀或将更高的阈值传递给 MOG 背景减法器以消除噪声。为了彻底去除噪声和误报,还可以对蒙版图像进行模糊处理,然后应用阈值:

    // Blur the mask image
    blur(fgMaskMOG2, fgMaskMOG2, Size(5,5), Point(-1,-1));
    
    // Remove the shadow parts and the noise
    threshold(fgMaskMOG2, fgMaskMOG2, 128, 255, 0);
    

    现在你可以很容易地找到包围前景区域的矩形并将这个区域传递给级联分类器:

    // Find the foreground bounding rectangle
    Mat fgPoints;
    findNonZero(fgMaskMOG2, fgPoints);
    Rect fgBoundRect = boundingRect(fgPoints);
    
    // Crop the foreground ROI
    Mat fgROI = image(fgBoundRect);
    
    // Detect the faces
    vector<Rect> faces;
    face_cascade.detectMultiScale(fgROI, faces, 1.3, 3, 0|CV_HAAR_SCALE_IMAGE, Size(32, 32));
    
    // Display the face ROIs
    for(size_t i = 0; i < faces.size(); ++i) 
    {
        Point center(fgBoundRect.x + faces[i].x + faces[i].width*0.5, fgBoundRect.y + faces[i].y + faces[i].height*0.5);
        circle(image, center, faces[i].width*0.5, Scalar(255, 255, 0), 4, 8, 0);
    } 
    

    通过这种方式,您将减少级联分类器的搜索区域,这不仅使其速度更快,而且还减少了误报人脸。

    【讨论】:

      【解决方案2】:

      如果您有输入图像和前景蒙版,这很简单。 在 C++ 中,我会简单地添加(就在您发表评论的地方):image.copyTo(fgimage,fgMaskMOG);

      我不熟悉java接口,但这应该很相似。只是不要忘记正确初始化fgimage 并在每一帧重置它。

      【讨论】:

      • 太好了,昨晚我意识到我可以使用copyTo...我还添加了侵蚀以避免噪音,谢谢
      猜你喜欢
      • 2013-03-23
      • 2017-10-02
      • 1970-01-01
      • 1970-01-01
      • 2012-05-18
      • 2014-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多