当前位置:首页 » 编程语言 » python人脸识别算法

python人脸识别算法

发布时间: 2022-06-10 05:34:44

⑴ 如何利用python进行精准人脸识别

要调用api接口,建议用face++的,支付宝的人脸识别都是用的这个。可能需要一点费用,不贵,代码里把fece++的api接口放进代码就行,还可以可以检测情绪,年龄等等的。

当然也有其他公司人脸识别的api接口,自己发现吧,其实很多,但基本都不会免费,有的可以试用

⑵ 如何线上部署用python基于dlib写的人脸识别算法

python使用dlib进行人脸检测与人脸关键点标记

Dlib简介:

首先给大家介绍一下Dlib

我使用的版本是dlib-18.17,大家也可以在我这里下载:

之后进入python_examples下使用bat文件进行编译,编译需要先安装libboost-python-dev和cmake

cd to dlib-18.17/python_examples

./compile_dlib_python_mole.bat 123

之后会得到一个dlib.so,复制到dist-packages目录下即可使用

这里大家也可以直接用我编译好的.so库,但是也必须安装libboost才可以,不然python是不能调用so库的,下载地址:

将.so复制到dist-packages目录下

sudo cp dlib.so /usr/local/lib/python2.7/dist-packages/1

最新的dlib18.18好像就没有这个bat文件了,取而代之的是一个setup文件,那么安装起来应该就没有这么麻烦了,大家可以去直接安装18.18,也可以直接下载复制我的.so库,这两种方法应该都不麻烦~

有时候还会需要下面这两个库,建议大家一并安装一下

9.安装skimage

sudo apt-get install python-skimage1

10.安装imtools

sudo easy_install imtools1

Dlib face landmarks Demo

环境配置结束之后,我们首先看一下dlib提供的示例程序

1.人脸检测

dlib-18.17/python_examples/face_detector.py 源程序:

#!/usr/bin/python# The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt## This example program shows how to find frontal human faces in an image. In# particular, it shows how you can take a list of images from the command# line and display each on the screen with red boxes overlaid on each human# face.## The examples/faces folder contains some jpg images of people. You can run# this program on them and see the detections by executing the# following command:# ./face_detector.py ../examples/faces/*.jpg## This face detector is made using the now classic Histogram of Oriented# Gradients (HOG) feature combined with a linear classifier, an image# pyramid, and sliding window detection scheme. This type of object detector# is fairly general and capable of detecting many types of semi-rigid objects# in addition to human faces. Therefore, if you are interested in making# your own object detectors then read the train_object_detector.py example# program. ### COMPILING THE DLIB PYTHON INTERFACE# Dlib comes with a compiled python interface for python 2.7 on MS Windows. If# you are using another python version or operating system then you need to# compile the dlib python interface before you can use this file. To do this,# run compile_dlib_python_mole.bat. This should work on any operating# system so long as you have CMake and boost-python installed.# On Ubuntu, this can be done easily by running the command:# sudo apt-get install libboost-python-dev cmake## Also note that this example requires scikit-image which can be installed# via the command:# pip install -U scikit-image# Or downloaded from . import sys

import dlib

from skimage import io

detector = dlib.get_frontal_face_detector()

win = dlib.image_window()

print("a");for f in sys.argv[1:]:

print("a");

print("Processing file: {}".format(f))
img = io.imread(f)
# The 1 in the second argument indicates that we should upsample the image
# 1 time. This will make everything bigger and allow us to detect more
# faces.
dets = detector(img, 1)
print("Number of faces detected: {}".format(len(dets))) for i, d in enumerate(dets):
print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(
i, d.left(), d.top(), d.right(), d.bottom()))

win.clear_overlay()
win.set_image(img)
win.add_overlay(dets)
dlib.hit_enter_to_continue()# Finally, if you really want to you can ask the detector to tell you the score# for each detection. The score is bigger for more confident detections.# Also, the idx tells you which of the face sub-detectors matched. This can be# used to broadly identify faces in different orientations.if (len(sys.argv[1:]) > 0):
img = io.imread(sys.argv[1])
dets, scores, idx = detector.run(img, 1) for i, d in enumerate(dets):
print("Detection {}, score: {}, face_type:{}".format(
d, scores[i], idx[i]))5767778798081

我把源代码精简了一下,加了一下注释: face_detector0.1.py

# -*- coding: utf-8 -*-import sys

import dlib

from skimage import io#使用dlib自带的frontal_face_detector作为我们的特征提取器detector = dlib.get_frontal_face_detector()#使用dlib提供的图片窗口win = dlib.image_window()#sys.argv[]是用来获取命令行参数的,sys.argv[0]表示代码本身文件路径,所以参数从1开始向后依次获取图片路径for f in sys.argv[1:]: #输出目前处理的图片地址
print("Processing file: {}".format(f)) #使用skimage的io读取图片
img = io.imread(f) #使用detector进行人脸检测 dets为返回的结果
dets = detector(img, 1) #dets的元素个数即为脸的个数
print("Number of faces detected: {}".format(len(dets))) #使用enumerate 函数遍历序列中的元素以及它们的下标
#下标i即为人脸序号
#left:人脸左边距离图片左边界的距离 ;right:人脸右边距离图片左边界的距离
#top:人脸上边距离图片上边界的距离 ;bottom:人脸下边距离图片上边界的距离
for i, d in enumerate(dets):
print("dets{}".format(d))
print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}"
.format( i, d.left(), d.top(), d.right(), d.bottom())) #也可以获取比较全面的信息,如获取人脸与detector的匹配程度
dets, scores, idx = detector.run(img, 1)
for i, d in enumerate(dets):
print("Detection {}, dets{},score: {}, face_type:{}".format( i, d, scores[i], idx[i]))

#绘制图片(dlib的ui库可以直接绘制dets)
win.set_image(img)
win.add_overlay(dets) #等待点击
dlib.hit_enter_to_continue()041424344454647484950

分别测试了一个人脸的和多个人脸的,以下是运行结果:

运行的时候把图片文件路径加到后面就好了

python face_detector0.1.py ./data/3.jpg12

一张脸的:

两张脸的:

这里可以看出侧脸与detector的匹配度要比正脸小的很多

2.人脸关键点提取

人脸检测我们使用了dlib自带的人脸检测器(detector),关键点提取需要一个特征提取器(predictor),为了构建特征提取器,预训练模型必不可少。

除了自行进行训练外,还可以使用官方提供的一个模型。该模型可从dlib sourceforge库下载:

arks.dat.bz2

也可以从我的连接下载:

这个库支持68个关键点的提取,一般来说也够用了,如果需要更多的特征点就要自己去训练了。

dlib-18.17/python_examples/face_landmark_detection.py 源程序:

#!/usr/bin/python# The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt## This example program shows how to find frontal human faces in an image and# estimate their pose. The pose takes the form of 68 landmarks. These are# points on the face such as the corners of the mouth, along the eyebrows, on# the eyes, and so forth.## This face detector is made using the classic Histogram of Oriented# Gradients (HOG) feature combined with a linear

⑶ python怎么实现人工智能

程序学习的过程就是使用梯度下降改变算法模型参数的过程。

比如说f(x) = aX+b; 这里面的参数是a和b,使用数据训练算法模型来改变参数,达到算法模型可以实现人脸识别、语音识别的目的。

实现人工智能的根本是算法,python是实现算法的一种语言,因为python语言的易用性和数据处理的友好性,所以现在很多用python语言做机器学习。其它语言比如java、c++等也也可以实现人工智能相关算法。下图是一个神经网络的示意图。

⑷ 如何学习python 图像识别

图像识别技术可以用来解决人脸识别或字符识别等多种问题。 在本文中,我将对算法进行实际编码来演示识别手写字,特别是手写的数字。我将会使用Python以及Python的许多模块,比如numpy、PIL等。 1 #从PIL库中导入Image

⑸ 人脸识别为什么用python开发

可以使用OpenCV,OpenCV的人脸检测功能在一般场合还是不错的。而ubuntu正好提供了python-opencv这个包,用它可以方便地实现人脸检测的代码。

写代码之前应该先安装python-opencv:

#!/usr/bin/python
#-*-coding:UTF-8-*-

#face_detect.py

#FaceDetectionusingOpenCV.Basedonsamplecodefrom:
#http://python.pastebin.com/m76db1d6b

#Usage:pythonface_detect.py<image_file>

importsys,os
fromopencv.cvimport*
fromopencv.highguiimport*
fromPILimportImage,ImageDraw
frommathimportsqrt

defdetectObjects(image):
""""""
grayscale=cvCreateImage(cvSize(image.width,image.height),8,1)
cvCvtColor(image,grayscale,CV_BGR2GRAY)

storage=cvCreateMemStorage(0)
cvClearMemStorage(storage)
cvEqualizeHist(grayscale,grayscale)

cascade=cvLoadHaarClassifierCascade(
'/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml',
cvSize(1,1))
faces=cvHaarDetectObjects(grayscale,cascade,storage,1.1,2,
CV_HAAR_DO_CANNY_PRUNING,cvSize(20,20))

result=[]
forfinfaces:
result.append((f.x,f.y,f.x+f.width,f.y+f.height))

returnresult

defgrayscale(r,g,b):
returnint(r*.3+g*.59+b*.11)

defprocess(infile,outfile):

image=cvLoadImage(infile);
ifimage:
faces=detectObjects(image)

im=Image.open(infile)

iffaces:
draw=ImageDraw.Draw(im)
forfinfaces:
draw.rectangle(f,outline=(255,0,255))

im.save(outfile,"JPEG",quality=100)
else:
print"Error:cannotdetectfaceson%s"%infile

if__name__=="__main__":
process('input.jpg','output.jpg')

⑹ 人脸识别怎么弄

你好
你是指使用python来做人脸识别是吗?
这个其实非常简单,你只需要使用python里面的opencv库,就可以实现。
具体的参考文档,可以去opencv的官方网站上下载。
我之前有做过类似的项目,不过是基于人工智能的。使用的是谷歌tensorflow的库
如果你需要指导,可以找我,我分享一些之前收集的例子给你。

⑺ 关于python人脸识别的问题

应该是没有找到分类器编码文件,把 haarcascade_frontalface_default.xml, haarcascade_eye.xml文件放到项目根目录下,再用cv.CascadeClassifier(path1), cv.CascadeClassifier(path2)两个API导入,另python下windows的文件路径要用 \\ 或者 /

⑻ 如何用Python实现简单人脸识别

你可以使用opencv库提供的人脸识别模块,这样子会比较快

⑼ python opencv 怎么利用csv文件训练人脸识别模型代码

1.1.介绍Introction
从OpenCV2.4开始,加入了新的类FaceRecognizer,我们可以使用它便捷地进行人脸识别实验。本文既介绍代码使用,又介绍算法原理。(他写的源代码,我们可以在OpenCV的opencv\moles\contrib\doc\facerec\src下找到,当然也可以在他的github中找到,如果你想研究源码,自然可以去看看,不复杂)

目前支持的算法有
Eigenfaces特征脸createEigenFaceRecognizer()
Fisherfaces createFisherFaceRecognizer()
LocalBinary Patterns Histograms局部二值直方图 createLBPHFaceRecognizer()
下面所有的例子中的代码在OpenCV安装目录下的samples/cpp下面都能找到,所有的代码商用或者学习都是免费的。

1.2.人脸识别Face Recognition
对人类来说,人脸识别很容易。文献[Tu06]告诉我们,仅仅是才三天的婴儿已经可以区分周围熟悉的人脸了。那么对于计算机来说,到底有多难?其实,迄今为止,我们对于人类自己为何可以区分不同的人所知甚少。是人脸内部特征(眼睛、鼻子、嘴巴)还是外部特征(头型、发际线)对于人类识别更有效?我们怎么分析一张图像,大脑是如何对它编码的?David Hubel和TorstenWiesel向我们展示,我们的大脑针对不同的场景,如线、边、角或者运动这些局部特征有专门的神经细胞作出反应。显然我们没有把世界看成零散的块块,我们的视觉皮层必须以某种方式把不同的信息来源转化成有用的模式。自动人脸识别就是如何从一幅图像中提取有意义的特征,把它们放入一种有用的表示方式,然后对他们进行一些分类。基于几何特征的人脸的人脸识别可能是最直观的方法来识别人脸。第一个自动人脸识别系统在[Kanade73]中又描述:标记点(眼睛、耳朵、鼻子等的位置)用来构造一个特征向量(点与点之间的距离、角度等)。通过计算测试和训练图像的特征向量的欧氏距离来进行识别。这样的方法对于光照变化很稳健,但也有巨大的缺点:标记点的确定是很复杂的,即使是使用最先进的算法。一些几何特征人脸识别近期工作在文献[Bru92]中有描述。一个22维的特征向量被用在一个大数据库上,单靠几何特征不能提供足够的信息用于人脸识别。

特征脸方法在文献[TP91]中有描述,他描述了一个全面的方法来识别人脸:面部图像是一个点,这个点是从高维图像空间找到它在低维空间的表示,这样分类变得很简单。低维子空间低维是使用主元分析(Principal Component Analysis,PCA)找到的,它可以找拥有最大方差的那个轴。虽然这样的转换是从最佳重建角度考虑的,但是他没有把标签问题考虑进去。[gm:读懂这段需要一些机器学习知识]。想象一个情况,如果变化是基于外部来源,比如光照。轴的最大方差不一定包含任何有鉴别性的信息,因此此时的分类是不可能的。因此,一个使用线性鉴别(Linear Discriminant Analysis,LDA)的特定类投影方法被提出来解决人脸识别问题[BHK97]。其中一个基本的想法就是,使类内方差最小的同时,使类外方差最大。
近年来,各种局部特征提取方法出现。为了避免输入的图像的高维数据,仅仅使用的局部特征描述图像的方法被提出,提取的特征(很有希望的)对于局部遮挡、光照变化、小样本等情况更强健。有关局部特征提取的方法有盖伯小波(Gabor Waelets)([Wiskott97]),离散傅立叶变换(DiscreteCosinus Transform,DCT)([Messer06]),局部二值模式(LocalBinary Patterns,LBP)([AHP04])。使用什么方法来提取时域空间的局部特征依旧是一个开放性的研究问题,因为空间信息是潜在有用的信息。
1.3.人脸库Face Database
我们先获取一些数据来进行实验吧。我不想在这里做一个幼稚的例子。我们在研究人脸识别,所以我们需要一个真的人脸图像!你可以自己创建自己的数据集,也可以从这里(http://face-rec.org/databases/)下载一个。
AT&TFacedatabase又称ORL人脸数据库,40个人,每人10张照片。照片在不同时间、不同光照、不同表情(睁眼闭眼、笑或者不笑)、不同人脸细节(戴眼镜或者不戴眼镜)下采集。所有的图像都在一个黑暗均匀的背景下采集的,正面竖直人脸(有些有有轻微旋转)。

热点内容
数据库access2003 发布:2024-05-19 02:49:39 浏览:619
碧蓝航线pc挂机脚本 发布:2024-05-19 02:30:03 浏览:588
脚本fir 发布:2024-05-19 02:28:57 浏览:260
阿里云独享服务器 发布:2024-05-19 02:23:54 浏览:253
织梦源码ga 发布:2024-05-19 02:23:20 浏览:571
java文件名后缀 发布:2024-05-19 02:14:39 浏览:956
快手点榜脚本 发布:2024-05-19 02:08:44 浏览:163
pythonforinkeys 发布:2024-05-19 01:55:44 浏览:793
电脑如何局域网共享文件夹 发布:2024-05-19 01:25:01 浏览:69
手机存储越大性能越好吗 发布:2024-05-19 01:14:28 浏览:177