EmguCV仅剪切面部和颈部皮肤并保存新图像 [英] EmguCV Cut Face+Neck Skin Only And Save New Image

查看:94
本文介绍了EmguCV仅剪切面部和颈部皮肤并保存新图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在我的应用中,我将输入人像,并且我想获取该人的 仅面部和颈部 作为单独图像中的输出.
示例:下面的图片作为输入:(来源:


In my app, I will input a human image and I want to get the face and neck only of that person as output in separate image.
Example: Below image as input:(Source:http://www.fremantlepress.com.au) And I want to get the up image as output:
I want to perform the following algorithm:

1.侦测脸孔
2.选择(面部区域* 2)区域
3.检测皮肤和颈部
4.剪切所选图像的皮肤区域
5.将该剪切区域保存到新图像中

1. Detect face
2. Select (face region * 2) area
3. Detect skin and neck
4. Cut the skin region of the selected image
5. Save that cut region into a new image

浏览EmguCV Wiki和其他在线资源时,我有信心执行第1步和第2步.但是我不确定如何完成第3步和第4步.
我正在查看一些功能/方法("Cunny Edge Detection"(轮廓边缘检测),"Contour"(轮廓)等),但是我不确定如何以及在何处应用这些方法. 我正在使用EmguCV(C#)和Windows窗体应用程序.

请帮助我如何执行第3步和第4步.如果有人详细说明了这两个步骤以及一些代码,我将很高兴.

As going through the EmguCV wiki and other online resources, I am confident to perform the step 1 and 2. But I am not sure how can I accomplish step 3 and 4.
There are some functions/methods I am looking on (Cunny Edge Detection, Contour etc) but I am not sure how and where should I apply those methods. I am using EmguCV (C#) and Windows Form Application.

Please help me how can I do step 3 and 4. I will be glad if someone elaborate these two steps and some code also.

推荐答案

好几种方法可以解决这个问题.边缘检测仅会为您提供边缘的二进制图像,并且您将必须执行一些线跟踪或霍夫变换来检测它们的位置.准确度会有所不同.

Well there are several ways you could approach this. Edge detection will only give you a binary image of edges and you will have to perform some line tracing or Hough transforms to detect the location of these. There accuracy will vary.

我会假设您可以检测到眼睛和脸部的相对位置.我希望统计过滤器会比神经网络(这是最好的选择)提供更好的结果,并具有更好的性能.如果使用彩色图像,自然的颜色分割是一个很好的选择(这很容易实现).我还将假设头部位置可能会略有变化,而颈部在图像中或多或少可见.

I will assume for know that you can detect the eyes and the relative location of the face. I would expect a statistical filter would provide a favourable outcome with better performance than a neural network which is the best alternative. A good Alternative is naturally colour segmentation if colour images are used (This is far easier to implement). I will also assume that the head position can change slightly with the neck being more or less visible within an image.

因此对于统计过滤器:

(请注意,在处理灰度图像时,个人的背景类似于面部数据,因此最好使用彩色图像).

(Note that the background of the individual is similar to the face data when dealing with a greyscale image so a colour image would be better to work with).

  1. 为我们的原始图像制作空白副本.我们将以此为基础形成一张脸部的二值地图,而不会 有必要,这将使我们更轻松地检查我们的成功

  1. Take a blank copy of our original image. We will form a binary map of our face on this while not necessary it will allow us to examine our success easier

在原始图像中找到脸,眼和嘴.

Find the Face, Eyes and Mouth in the original image.

我们可以假设来自眼睛和嘴巴的任何数据构成了脸部的一部分,并将其标记在 空白副本带有"1".

We can assume that any data from the eyes and mouth form part of the face and mark these on the blank copy with "1"s.

现在我们需要一些数学运算,因为我们知道人脸检测算法只能在 与相机成一定角度.我们使用它并从某些图像中选择一个统计遮罩 假设图像中的部分距离脸颊区域10x10像素2或3.这将是最 图像中人脸的可能区域.我们使用这些数据并从图像中获取值,例如 均值和标准差.

Now we need a bit of maths, as we know the face detection algorithm can only detect a face at a certain angle to the camera. We use this and select a statistical mask from the image of certain parts from the image let’s say 10x10 pixels 2 or 3 from the cheek area. This will be the most likely area of the face within the image. We use this data and get values from the image such as mean and standard deviation.

我们现在扫描检测到人脸的图像分割部分.我们不会 整个图像,因为这将需要很长时间. (注意:有一个边框是尺寸的一半 不会被看到的面具).我们检查每个像素及其周围像素的周围 10x10遮罩的大小.如果平均值或标准偏差(无论我们在检查什么)是 类似于我们的过滤器说的10%以内,那么我们将空白副本中的这个像素标记为"1" 并认为该像素属于皮肤.

We now scan across the segmented part of the image where we have detected the face. We won't do the whole image as this will take a long period of time. (Note: There is a border half the size of the mask that won't be looked at). We examine each pixel and it surrounding neighbours to the size of the 10x10 mask. If the average or standard deviation (whatever we are examining) is similar to that of our filter say within 10% then we mark this pixel in our blank copy as a "1" and consider that pixel to belong to the skin.

关于颜色分割:

(注意:您也可以尝试此过程进行灰度处理,但是由于砌砖的效果会不太成功)

(Note: You could also try this process for greyscale however it will be less successful due to the brickwork)

  1. 重复步骤1至2.

  1. Repeat steps 1 to 2.

我们将再次选择图像中可以包含面部数据的某些区域(即10 眼睛下方的像素).但是,在这种情况下,我们将检查构成此颜色的数据 像素.不要忘了HSV图像可以从此过程中获得更好的结果,并且结合使用更多 所以.我们可以扫描整个图像,检查每个像素是否具有相似的颜色.如果匹配 在您的二进制地图上标记它.

Again we will select certain areas of the image that we can expect to contain face data (i.e. 10 pixels below the eye). In this case however we examine the data that forms the colour of this pixel. Don't forget HSV images can obtain better results from this process an a combination more so. We can the scan across the image examining each pixel for a similar colour. If it matches mark it on your binary map.

另一种方法是从图像的R G和B光谱中减去或相加一个 只有数据面才能生存.您可以通过以下方式将其直接转换为二进制图像 使任何值> 1 == 1;

An alternative is subtracting or adding a calculated from the R G and B spectrum of the image of which only the data face will survive. You can convert this directly to a binary image by making any value > 1 == 1;

这仅适用于皮肤,因为对于头发,我们将需要其他过滤器.一些注意事项:

This will only work for Skin as for the hair we will need other filters. A few notes:

在彩色图像上工作的统计过滤器具有更大的能力,但是需要更长的时间.

A statistical filter working on a colour image has a far greater ability however takes longer.

使用图像中的数据形成统计过滤器,因为这样可以对其他肤色进行分类.数学设计的滤镜或颜色分割需要大量工作才能实现相同的可变性.

Use data from the image to form your statistical filter as this will allow for other skin colours to be classified. A mathematical designed filter or colour segmentation will require a lot of work to achieve the same variability.

掩码的大小很重要,掩码的大小越大,发生错误的可能性就越小,但处理时间也会再次增加.

The size of the mask is important the greater the mask size the less likely errors will occur but again processing time increases.

如果您要检查的像素已经为1(通过眼睛/鼻子/嘴巴检测进行分类),那么您可以通过引用二进制图副本中的相同区域来加快此过程,然后为什么要再次检查它就跳过它.

You can speed up the process by referencing the same area within the binary map copy if the pixel your examining is already a 1 (classified by eye/nose/mouth detection) then why examine it again just skip it.

使用多个皮肤滤镜可以提供更好的效果,但是可能还会引入更多的噪声,并且记住每个滤镜必须与增加像素处理时间相比进行比较.

Multiple skin filters will provide better results however may also introduce more noise and remember each filter must then by compared with a pixel increasing processing time.

要想准确地运行算法,将需要反复尝试,但是使用这些方法很快就会发现可比的结果.

To get an lgorithm working accuratley will require a bit of trial and error but you sould see comparable results fairly quickly using these methods.

我希望这对您有所帮助.很抱歉没有包含任何代码,但希望其他人可以帮助您,如果您遇到麻烦,自己编写它可以帮助您了解发生了什么并减少处理时间.让我知道您是否需要其他建议,我正在做图像分析博士学位,以使您知道该建议是正确的.

I hope this helps you on your way. Sorry for not including any code but hopefully others can help you were you get stuck and writing it yourself will help you understand what is going on and allow you to cut down on processing time. Let me know if you require any additional advice I'm doing my PhD in image analysis just so you know that the advice is sound.

保重

克里斯

快速的结果:

这里是用于检测头发的20x20滤镜.我编写的程序目前仅适用于灰度图像,因此皮肤检测会受到石头的干扰(请参阅下文)

Here is a 20x20 filter applied in detecting the hair. The program I've written only works on greyscale images at the moment so the skin detection suffers interference from the stone (see later)

面部区域的彩色图像

平均头发过滤器20x20面膜的二进制图40%允许错误

可以看出,在这种情况下,由于衬衫与头发的颜色相匹配,因此会受到衬衫的干扰.只需检查检测到的面部区域的前三分之一或一半即可消除这种情况.

As can be observed there is interference from the shirt in this case as it matches the colour of the hair. This can be eliminated by simply only examining the top third or half of the detected facial region.

平均皮肤过滤器20x20遮罩的二进制图40%允许错误

在此图像中,我仅使用了一个由下巴区域形成的滤镜,因为残茬明显改变了滤镜的性能.个人后面的石头上仍然有噪音,但是使用彩色图像可以消除这种情况.情况下的空白可以由算法或其他过滤器填充.再次,衬衫边缘会产生噪音,但是我们可以通过检测衬衫并去除形成衬衫的任何数据或仅在某些区域仔细查看来将噪声降至最低.

In this image I use only 1 filter formed from the chin area as the stubble obviously changes the filters behaviour. There is still noise presented from the stone behind the individual however using colour image could eliminate this. The gaps in the case could be filled by an algorithm or another filter. Again there is noise from the edge of the shirt but we could minimise this either by detecting the shirt and removing any data that forms it or dimply only looking in certain areas.

要检查的区域示例

要消除错误分类,您可以获取分割图像的前三分之二,并在面部区域的底部查找面部和检测到的眼睛的宽度,以获取颈部数据.

To eliminate false classification you could take the top two thirds of the segmented image and look for the face and the width of the detected eyes to the bottom of the facial region for neck data.

再次欢呼

克里斯

这篇关于EmguCV仅剪切面部和颈部皮肤并保存新图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆