Python中人脸识别的预处理方法 [英] Preprocessing methods for face recognition in Python

查看:74
本文介绍了Python中人脸识别的预处理方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个人脸识别项目,在该项目中,我正在识别运动中的人的脸,这意味着该人不断运动,我必须检测并识别人脸.

为此,我正在使用 caffemodel 进行面部检测,并使用改进的knn方法进行面部识别.它可以正常工作,但在大多数情况下会给出错误的识别.由于人们在移动,因此很难获得良好的面部图像.以下是捕获的面部的一些示例:

相机放置的位置离人所处位置略远,这是因为其面部不十分清晰和正面.人脸图像尺寸为100x120.我必须使用这些图像进行面部识别.我想知道是否有人可以指导我可以在识别之前使用的一些预处理方法,以便可以提高准确性.请帮忙.谢谢

解决方案

最好的预处理方法是消除闪电效果.

假设您有以下图片:

如何找到面孔?还是脸在哪里?

在当前情况下,即使人眼也无法在图像中找到人脸.

如果我们应用 GaussianBlur :

至少我们可以看到人脸在图像中的位置.

  import cv2img = cv2.imread('input.jpg')灰色= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)smooth = cv2.GaussianBlur(gray,(125,125),0)除法= cv2.divide(灰色,平滑,比例= 255)cv2.imwrite('output.jpg',division) 

现在,我们如何定位人脸?

上面是一个具有挑战性的图像,您可以在其中测试您的方法.由于上述图片无法被Haar和

  • 应用高斯模糊

  • 检测脸部

  • 使用Haar

  img = cv2.imread('face_shaded_division.jpg')灰色= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)face_cascade = cv2.CascadeClassifier('/opencv/data/haarcascades/haarcascade_frontalface_default.xml')faces = face_cascade.detectMultiScale(img,1.3,5)对于(x,y,w,h)的脸:img = cv2.rectangle(img,(x,y),(x + w,y + h),(255,0,0),2)roi_gray =灰色[y:y + h,x:x + w]roi_color = img [y:y + h,x:x + w]cv2.imwrite('output.png',img)cv2.imshow('img',img)cv2.waitKey(0)cv2.destroyAllWindows() 

可能的问题 为什么不提及面部对齐?

最具挑战性的事实是面部识别中的闪电效应.如果您的方法能够解决问题,那么您所能做的就是用更多样本训练网络,或者您可以使用预先训练的网络.

I am working on a face recognition project where I am recognizing the faces of the person in movement which means the person keeps moving and I have to detect and recognize face.

To do this I am using caffemodel for face detection and modified knn approach for face recognition. It works fine but most of the case it gives false recognition. Because the persons are moving, thus its really hard to get a good face image. Below are few examples of the face captured:

Camera is placed a bit far from where the person is due to which its not very clear and frontal face. Face image size is 100x120. I have to use these images for face recognition. I was wondering if anyone can guide on some of the pre processing methods I can use before recognition so that accuracy can be improved. Please help. Thanks

解决方案

The best preprocessing method you could do is removing the lightning effect.

Assume you have the following image:

How can you find the face? or where is the face?

In the current situation, it is impossible to find the face in the image even with the human eye.

If we apply GaussianBlur:

At least we can see where the face is in the image.

import cv2

img = cv2.imread('input.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
smooth = cv2.GaussianBlur(gray, (125,125), 0)
division = cv2.divide(gray, smooth, scale=255)
cv2.imwrite('output.jpg',division)

Now, how do we locate the face?

Above is a challenging image in which you can test your method. Since the above image can not be detected by Haar, and face-recognition. If your method finds it, you can be sure about your method.

For instance:

The following image can be found by Haar-like features. Therefore your method must detect the below image. Otherwise, you should change your method.

  • Apply Gaussian Blur

  • Detect the face

  • Using Haar

img = cv2.imread('face_shaded_division.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
face_cascade = cv2.CascadeClassifier('/opencv/data/haarcascades/haarcascade_frontalface_default.xml')

faces = face_cascade.detectMultiScale(img, 1.3, 5)
for (x,y,w,h) in faces:
    img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
    roi_gray = gray[y:y+h, x:x+w]
    roi_color = img[y:y+h, x:x+w]
cv2.imwrite('output.png', img)
cv2.imshow('img', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

Possible Question Why don't you mention about face-alignment?

The most challenging fact is the lightning effect in face-recognition. If your method solves that, all you can do is training your network with more samples, or you could use pre-trained networks.

这篇关于Python中人脸识别的预处理方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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