使用vue创建一个遮罩组件_使用遮罩脸部识别应用程序创建人的数据集

使用vue创建一个遮罩组件

Everything has changed because of COVID19. The way we live, how we communicate and work, how we travel. Many aspects of our lives have been affected. One of these aspects is wearing face masks, no matter where you are outside, you must wear a face mask. Using masks reduces contamination by COVID19, this way we can protect us and the others. There are a lot of points to consider when you are using masks, some of them are “Place the face mask over your nose and mouth and secure with ties or loops. Make sure the mask fits snugly, molded to your face and around your nose. Make sure the mask fully covers your nose, mouth, and chin.”. Clicking in the underlined text you will find more suggestions on how to use a face mask safely.

一切因COVID19而改变。 我们的生活方式,沟通和工作方式,旅行方式。 我们生活的许多方面都受到了影响。 这些方面之一是戴口罩,无论您在室外什么地方,都必须戴口罩。 使用口罩可减少COVID19的污染,这样我们就可以保护自己和他人。 使用口罩时,有很多要考虑的方面,其中一些是“将口罩放在您的鼻子和嘴上,并用领带或环圈固定。” 确保面罩贴紧,模制在您的脸部和鼻子周围。 确保面罩完全覆盖您的鼻子,嘴巴和下巴。” 。 单击带下划线的文本,您将找到有关如何安全使用口罩的更多建议。

Image for post
Credit: Getty Images
信用:盖蒂图片社

Unfortunately, some systems can be affected by using masks, especially facial image processing, like facial recognition, for example. Now we lost some facial features because we have masks covering the nose and the mouth, so actually, processing depends on facial image can’t work properly. How can we deal with that? The first step is to get a dataset with people using masks.

ünfortunately,一些系统可以通过使用掩模,尤其是面部的图像处理,如面部识别,例如影响。 现在我们失去了一些面部特征,因为我们有覆盖鼻子和嘴巴的面具,所以实际上,处理过程取决于面部图像无法正常工作。 我们该如何处理? 第一步是获取使用蒙版的人员的数据集。

Unluckily we don’t have a dataset with specific people using masks. We need a dataset where we have face images from people properly labeled. Like the typical raw data, we have some input to a specific output. However, now our input is face images from people. Each person must receive a label, this could be their names. So we need something like LFW (Labeled Faces in the Wild Home), that is, folders with people’s face image, each person has their own folder, named using your own names. Once we don’t have it with people wearing face masks, we have to build our own dataset to face recognition of people using face masks.

不幸的是,我们没有使用面具的特定人员的数据集。 我们需要一个数据集,其中包含来自正确标记的人的面部图像。 像典型的原始数据一样,我们有一些输入到特定的输出。 但是,现在我们输入的是来自人的面部图像。 每个人都必须获得一个标签,这可以是他们的名字。 因此,我们需要类似LFW(“荒野之家”中的标签脸)的东西,即带有人脸图像的文件夹,每个人都有自己的文件夹,并使用自己的名字命名。 一旦没有戴口罩的人,我们就必须建立自己的数据集来识别使用口罩的人。

Image for post
Face images found in LFW Dataset
LFW数据集中的人脸图像

Basically our goal is building a dataset like LFW, however, we’re gonna have pictures with and without people wearing masks.

基本上,我们的目标是建立像LFW这样的数据集,但是,我们将拥有带或不带人员戴着口罩的照片。

Image for post
Folders with face pictures, note that each person is identified by their names in folder’s names
带有头像的文件夹,请注意,每个人的名字都由其名字标识
Image for post
Pictures that we wish to have of people wearing masks
我们希望人们戴口罩的照片

You can find images of people wearing face masks, but none of them have labels on how we wish. Below we have a lot of pictures of people (artificially) wearing face masks, but there is no label and just one picture to each person.

您可以找到戴着口罩的人的图像,但没有一个人贴有我们的意愿标签。 下面有很多人的照片(人工地)戴着口罩,但没有标签,每个人只有一张照片。

Image for post
https://www.pyimagesearch.com/2020/05/04/covid-19-face-mask-detector-with-opencv-keras-tensorflow-and-deep-learning/ https://www.pyimagesearch.com/2020/05/04/covid-19-face-mask-detector-with-opencv-keras-tensorflow-and-deep-learning/

从数据集中获取人的脸部图像(不戴口罩) (Getting people’s face image (not wearing masks) from a dataset)

We are using the LFW dataset, you can find it in a lot of resources, but I’m gonna use LFW from Kaggle: https://www.kaggle.com/jessicali9530/lfw-dataset. Once you are there, just download the dataset, and let’s go!

我们正在使用LFW数据集,您可以在很多资源中找到它,但是我将使用Kaggle的LFW: https ://www.kaggle.com/jessicali9530/lfw-dataset。 到达那里后,只需下载数据集,然后开始吧!

Image for post

You must have something like:

您必须具有以下内容:

Image for post

Extract the files:

解压缩文件:

Image for post
Image for post
Files in a folder downloaded from LFW dataset
从LFW数据集下载的文件夹中的文件

Go to lfw-deepfunneled folder, over there you will find folders with people’s names. Each folder has face images of the person in the folder’s name.

转到lfw-deepfunneled文件夹,在那儿您会找到带有人名的文件夹。 每个文件夹在该文件夹的名称中都有该人的面部图像。

Image for post
Folders found in LFW Dataset
在LFW数据集中找到的文件夹

We are ignoring folders with less than 19 pictures.

我们将忽略少于19张图片的文件夹。

Let’s see some examples:

让我们看一些例子:

Image for post
Folder to be ignored, contain only one image
要忽略的文件夹,仅包含一张图像
Image for post
Folder that can be considered in our dataset, as you can see, we have at least 19 images
如您所见,可以在我们的数据集中考虑的文件夹,我们至少有19张图像

The folder above will be in our dataset.

上面的文件夹将在我们的数据集中。

人工戴口罩 (Putting masks artificially)

Now that we have a dataset, let’s put on some masks! We are using the algorithm developed by https://github.com/X-zhangyang/Real-World-Masked-Face-Dataset.

现在我们有了一个数据集,让我们戴上一些面具吧! 我们正在使用https://github.com/X-zhangyang/Real-World-Masked-Face-Dataset开发的算法。

Make: git clone https://github.com/X-zhangyang/Real-World-Masked-Face-Dataset

You will have:

你将会拥有:

Image for post

Go to the wear_mask_to_face folder. We are gonna use the wearmask.py script, but we need to make some changes.

转到wear_mask_to_face文件夹。 我们将使用wearmask.py脚本,但是我们需要进行一些更改。

Image for post

First of all, you need to change shape_predictor local (line 34) to where it is on your computer. If you are struggling to download this file, just take it here: https://github.com/AKSHAYUBHAT/TensorFace/blob/master/openface/models/dlib/shape_predictor_68_face_landmarks.dat.

首先,您需要将shape_predictor本地(第34行)更改为它在计算机上的位置。 如果您正在努力下载此文件,请在此处下载: https : //github.com/AKSHAYUBHAT/TensorFace/blob/master/openface/models/dlib/shape_predictor_68_face_landmarks.dat

Now we are gonna make important changes in the wearmask.py code. Actually, if we have an image input like that below:

现在,我们将对wearmask.py代码进行重要更改。 实际上,如果我们有如下图像输入:

Image for post

the image output is like:

图像输出类似于:

Image for post

That is good because we have the image face and maybe we don’t need to use any image processing to detect the face. However, if you consider using your own face detector, in this case, we need to adjust the code, so we can put on the mask and keep the original image:

很好,因为我们有图像的人脸,也许我们不需要使用任何图像处理来检测人脸。 但是,如果您考虑使用自己的面部检测器,在这种情况下,我们需要调整代码,因此我们可以戴上口罩并保留原始图像:

Image for post

In order to make this, just make some adjusts. After verifying the code, I could see that the with_mask_face matrix (line 127) has the entire image as in the figure above. So, we just need to get the matrix and using it to write a new image.

为了做到这一点,只需进行一些调整即可。 验证代码后,我可以看到with_mask_face矩阵(第127行)具有整个图像,如上图所示。 因此,我们只需要获取矩阵并使用它来编写新图像。

So, we just need to create two modes, the first one gives the original output and the other keeps the entire image how we wish.

因此,我们只需要创建两种模式,第一种可以提供原始输出,另一种可以使整个图像保持期望的状态。

if found_face:
# align
src_faces = []
src_face_num = 0
with_mask_face = np.asarray(self._face_img) mode = 'all_image' #two modes, face_image and all_image if mode == 'face_image':
for (i, rect) in enumerate(face_locations):
src_face_num = src_face_num + 1
(x, y, w, h) = rect_to_bbox(rect)
detect_face = with_mask_face[y - 0:y + h + 0, x - 0:x + w + 0]
src_faces.append(detect_face)
# 人脸对齐操作并保存
faces_aligned = face_alignment(src_faces)
face_num = 0
for faces in faces_aligned:
face_num = face_num + 1
faces = cv2.cvtColor(faces, cv2.COLOR_RGBA2BGR)
size = (int(128), int(128))
faces_after_resize = cv2.resize(faces, size, interpolation=cv2.INTER_AREA)
cv2.imwrite(self.save_path, faces_after_resize) if mode == 'all_image':
face = cv2.cvtColor(with_mask_face, cv2.COLOR_RGBA2BGR)
cv2.imwrite(self.save_path, face)

After that, we can generate images of people using masks without cutting a piece of the image to just show the image face.

之后,我们可以使用蒙版生成人物图像,而无需剪切一部分图像以仅显示图像的脸部。

Now we are gonna choose some people and create a dataset of these people using masks. Put the correct repositories where are the datasets in your computer (lines 227 and 228). I created two ways of making this dataset, the first one (alternate = False, line 239) put the masks after the eighth image. The other (alternate = True) will alternate between put the mask and keep the original image, so you will have something near to 50% of pictures with masks and 50% without masks. You can find below the necessary changes in wearmask.py to make the dataset.

现在,我们将选择一些人,并使用遮罩创建这些人的数据集。 将正确的存储库放在计算机中的数据集所在的位置(第227和228行)。 我创建了两种制作此数据集的方法,第一种(替代= False,第239行)将遮罩放在第八张图像之后。 另一个(alternate = True)将在放置蒙版和保留原始图像之间交替,因此您将获得接近50%带蒙版的图片和50%不带蒙版的图片。 您可以在下面找到wearmask.py进行必要的更改以创建数据集。

if __name__ == '__main__':
dataset_path = '/home/diogenes/Desktop/create_face_mask/wear_mask_to_face/dataset'
save_dataset_path = '/home/diogenes/Desktop/create_face_mask/wear_mask_to_face/save_face_masks'
xor = False for root, dirs, files in os.walk(dataset_path, topdown=False): new_root = root.replace(dataset_path, save_dataset_path)
if not os.path.exists(new_root):
os.makedirs(new_root) for i,name in enumerate(files): alternate = False if alternate == False: if i >= 8:
new_root = root.replace(dataset_path, save_dataset_path)
imgpath = os.path.join(root, name)
save_imgpath = os.path.join(new_root, name)
cli(imgpath,save_imgpath) else:
aux = cv2.imread(root+'/'+name)
cv2.imwrite(new_root+'/'+name,aux) else: if i >= 0:
xor = not xor
if xor == True:
new_root = root.replace(dataset_path, save_dataset_path)
imgpath = os.path.join(root, name)
save_imgpath = os.path.join(new_root, name)
cli(imgpath,save_imgpath) else:
aux = cv2.imread(root+'/'+name)
cv2.imwrite(new_root+'/'+name,aux)

Below you can see one sample of our dataset.

您可以在下面看到我们的数据集的一个样本。

Image for post
Original images
原始图片
Image for post
Alternate := False
备用:=假
Image for post
Alternate := True
备用:=真

If you wish, it is possible to change the mask. Below are the options available. You just need to select the mask on the mask_path (line 81).

如果您愿意,可以更换面罩。 以下是可用的选项。 您只需要在mask_path上选择掩码(第81行)。

Image for post

The entire code is available in https://github.com/Wallis16/wearmask.

完整代码可在https://github.com/Wallis16/wearmask中获得

翻译自: https://medium.com/@diogeneswallis/creating-a-dataset-of-people-using-masks-to-face-recognition-applications-b1be280aa71

使用vue创建一个遮罩组件

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值