gpt4 book ai didi

opencv - 使用openCv进行背景减除后的人脸检测

转载 作者:太空宇宙 更新时间:2023-11-03 21:46:47 26 4
gpt4 key购买 nike

我正在尝试改进相机捕获的人脸检测,所以我认为如果在人脸检测过程之前从图像中删除背景会更好,我将 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);
}

谢谢

最佳答案

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

您可以使用腐 eclipse 或将更高的阈值传递给 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);
}

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

关于opencv - 使用openCv进行背景减除后的人脸检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21813246/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com