2

BackgroundSubtractorMOGカメラキャプチャからの顔検出を改善しようとCascadeClassifierしているので、顔検出プロセスの前に画像から背景を削除したほうがよいと思いましたlbpcascade_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);
}

ありがとう

4

2 に答える 2

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);
} 

このようにして、カスケード分類器の検索領域を縮小します。これにより、処理が高速になるだけでなく、偽陽性の顔も減少します。

于 2016-09-01T22:32:11.597 に答える
0

入力画像と前景マスクがあれば、これは簡単です。C++ では、次のように単純に追加します (コメントを入力した場所に):image.copyTo(fgimage,fgMaskMOG);

私は Java インターフェイスに詳しくありませんが、これは非常に似ているはずです。fgimageフレームごとに正しく初期化してリセットすることを忘れないでください。

于 2014-02-17T07:49:00.803 に答える