问题描述
我正在研究项目.我正在使用网络摄像头使用emgucv在c#中检测人脸.
一切正常,例如当我运行应用程序时,它启动网络摄像头,然后开始检测面部..
但是现在我要做的是,当它检测到人脸时,应该只模糊人脸,而不是整个网络摄像头视频.或显示其他图像而不是检测到的脸部.
我在图片框中显示人脸检测到的视频.
这是我的代码,到目前为止我已经完成了..
i am working on project. I am using webcam to detect faces in c#, using emgucv.
Every thing is working fine,like when i run application it starts webcam then it starts detecting faces..
But now i want to do is, that when it detects faces , it should blur the face only,not the whole webcam video. or it show some other image instead of detected face.
And i am showing the face detected video in picturebox.
this is my code, i have done so far..
Image<Bgr, byte> ImageFrame = capture.QueryFrame();
if (ImageFrame != null)
{
//convert the image to gray scale
Image<Gray, byte> grayframe = ImageFrame.Convert<Gray, byte>();
//detect faces from the gray-scale image and store into an array of type 'var'
var faces = grayframe.DetectHaarCascade(haar, 1.4, 0,
HAAR_DETECTION_TYPE.DEFAULT,
new Size(25, 25))[0];
//draw a green rectangle on each detected face in image
foreach (var face in faces)
{
ImageFrame.Draw(face.rect, new Bgr(Color.Green), 2);
}
}
camimagebox.Image = ImageFrame;
现在我只想模糊检测到的脸,就这样..请尽快帮助我..
我还用过:
ImageFrame.SmoothBlur(face.rect.Width,face.rect.Height)
但是什么也没发生...
Now i just want to blur the detected face, thats it..kindly help me as soon as you can..
I also used:
ImageFrame.SmoothBlur(face.rect.Width, face.rect.Height)
but nothing happened...
推荐答案
Image<Gray, float> inputImage;
//Set inputImage to whatever image you want to smooth
Image<Gray, float> smoothedImage = new Image<Gray, float>(inputImage.Width, inputImage.Height);
//You can use whichever smooth type you need, gaussian is fairly common, but not the only way to do it.
int apertureWidth = 10;
int apertureHeight = 10;
//The aperture is the size of the smoothing window
//The smoothing window is typically a square that is a few pixels wide; a 10x10 square is a good place to start.
//if you set parameter3 and 4 to zero it will use default values.
cvSmooth(inputImage.Ptr, smoothedImage.Ptr, SMOOTH_TYPE.CV_GAUSSIAN, apertureWidth , apertureHeight , 0, 0);
请在此处进行解释调用cvSmooth.
您需要按照此处.
另请阅读此 [ ^ ]在openCV图像过滤中,cvSmooth大约是页面底部的3/4.
Look here for an explanation of the call to cvSmooth.
You will need to select the smooth type as explained here.
Also read this[^] on openCV Image Filtering, cvSmooth is about 3/4 of the way down the page.
这篇关于想要模糊图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!