1 / 15
文档名称:

python使用opencv进行人脸识别.doc

格式:doc   大小:31KB   页数:15页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

python使用opencv进行人脸识别.doc

上传人:读书之乐 2020/2/14 文件大小:31 KB

下载得到文件列表

python使用opencv进行人脸识别.doc

文档介绍

文档介绍:python使用opencv进行人脸识别欢迎来到小码哥的博客博客搬家啦环境ubuntuLTSpythonopencv安装依赖sudoapt-getinstalllibopencv-*sudoapt-getinstallpython-opencvsudoapt-getinstallpython-numpy示例代码#!/usr/bin/envpython#coding=utf-8importosfromPILimportImage,ImageDrawimportcvdefdetect_object(image):'''检测图片,获取人脸在图片中的坐标'''grayscale=((,),8,1)(image,grayscale,)cascade=("/usr/share/opencv/haarcascades/")rect=(grayscale,cascade,(),,2,,(20,20))result=[]forrinrect:((r[0][0],r[0][1],r[0][0]+r[0][2],r[0][1]+r[0][3]))returnresultdefprocess(infile):'''在原图上框出头像并且截取每个头像到单独文件夹'''image=(infile);ifimage:faces=detect_object(image)im=(infile)path=(infile)save_path=(path)[0]+"_face"try:(save_path)except:passiffaces:draw=(im)count=0forfinfaces:count+=1(f,outline=(255,0,0))a=(f)file_name=(save_path,str(count)+".jpg")#printfile_name(file_name)drow_save_path=(save_path,"")(drow_save_path,"JPEG",quality=80)else:print"Error:cannotdetectfaceson%s"%infileif__name__=="__main__":process("./")转换效果原图:转换后使用感受对于大部分图像来说,只要是头像是正面的,没有被阻挡,识别基本没问题,准确性还是很高的。识别效率有点低,有时候一张图片能处理七八秒才能处理完,当然这个和机器配置有关。如果想加速的话可以使用C语言重写,经测试,C语言版的所花时间大约是python的一半另外,官方提供了几个库可一选择,,除此之外,/usr/share/opencv/haarcascades/文件夹下还有几个库:~~/usr/share/opencv/haarcascades>>ll-h总用量19Mdrwxr-xr-x2rootroot3月2217:14./drwxr-xr-x4rootroot3月2217:14../-rw-r--r--1rootroot4月28-rw-r--r--1rootroot495K4月28-rw-r--r--1rootroot818K4月28-rw-r--r--1rootroot4月28-rw-r--r--1rootroot899K4月28-rw-r--r--1rootroot4月28-rw-r--r--1rootroot622K4月28-rw-r--r--1rootroot316K4月28-rw-r--r--1rootroot520K4月28-rw-r--r--1rootroot350K4月28-rw-r--r--1rootroot401K4月28-rw-r--r--1rootroot306K8月2-rw-r--r--1rootroot760K4月28-rw-r--r--1rootroot703K4月28-rw-r--r--1rootroot4月28-rw-r--r--1rootroot318K8月2-rw-r--r--1rootroot4月28-rw-r--r--1rootroot4月28-rw-r--r--1rootroot4月28-rw-r--r--1rootroot317K4月28-rw-r--r--1rootroot1022K4月28~/usr/share/opencv/haarcascades>>根据文件名大家应该能知道是识别什么的。值得一提的是,这里面有四个关于人脸(frontalface)的识别库,根据我的使用体验,default这个xml识别的最多,这就意味着本来不是头像的也识别成头像了。alt_tree这个库虽然是最大的,但并不意味着这个库是最好的,应该说,用这个库,识别是最严格的,这就意味着,有些头像不能被识别,因为根据他的算法,他认