资源简介
DIY_Face_recognition_system-master.zip

代码片段和文件信息
import cv2
import dlib
import os
import sys
import random
output_dir = ‘./wyj_faces‘ #采集图片的输出目录
size = 64
if not os.path.exists(output_dir): #如果采集图片的输出目录不存在则创建
os.makedirs(output_dir)
# 改变图片的亮度与对比度
def relight(img light=1 bias=0): #定义函数
w = img.shape[1] #图片的宽的像素数
h = img.shape[0] #图片的高的像素数
#image = []
for i in range(0w): #一列一列地来改变像素的亮度和对比度
for j in range(0h):
for c in range(3):
tmp = int(img[jic]*light + bias)
if tmp > 255:
tmp = 255
elif tmp < 0:
tmp = 0
img[jic] = tmp
return img
#使用dlib自带的frontal_face_detector作为我们的特征提取器
detector = dlib.get_frontal_face_detector()
# 打开摄像头 参数为输入流,可以为摄像头或视频文件
camera = cv2.VideoCapture(0)
index = 1
while True:
if (index <= 200): #截取1000张图片
print(‘Being processed picture %s‘ % index) #输出当前截取图片的进度
# 从摄像头读取照片
success img = camera.read()
# 转为灰度图片
gray_img = cv2.cvtColor(img cv2.COLOR_BGR2GRAY)
# 使用detector进行人脸检测
dets = detector(gray_img 1) #detector会返回识别到的人脸的矩形的左下角和右上角的坐标
for i d in enumerate(dets): #enumerate用于遍历括号中的元素及其下标,其中i对应元素下标,d对应元素
x1 = d.top() if d.top() > 0 else 0 #通过left,right,top,down获取矩形的四个坐标x1,x2,y1,y2
y1 = d.bottom() if d.bottom() > 0 else 0
x2 = d.left() if d.left() > 0 else 0
y2 = d.right() if d.right() > 0 else 0
face = img[x1:y1x2:y2] #把图片里含有人脸的矩形截取出来给face
# 调整图片的对比度与亮度, 对比度与亮度值都取随机数,这样能增加样本的多样性
face = relight(face random.uniform(0.5 1.5) random.randint(-50 50))
face = cv2.resize(face (sizesize)) #调整图片大小
cv2.imshow(‘Easy & Happy-get picture now‘ face) #显示处理后的图像
cv2.imwrite(output_dir+‘/‘+str(index)+‘.jpg‘ face) #将图片保存下来
index += 1
key = cv2.waitKey(30) & 0xff
if key == 27:
break
else:
print(‘Finished!‘)
break
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-10-27 20:04 DIY_Face_recognition_system-master\
文件 2607 2019-10-27 15:54 DIY_Face_recognition_system-master\pictures_get.py
文件 1877 2019-10-27 15:54 DIY_Face_recognition_system-master\pictures_set.py
文件 556 2019-10-27 20:06 DIY_Face_recognition_system-master\README.md
文件 6298 2019-10-27 15:54 DIY_Face_recognition_system-master\test.py
文件 6942 2019-10-27 15:54 DIY_Face_recognition_system-master\train.py
文件 2394816 2019-10-27 15:54 DIY_Face_recognition_system-master\项目报告-基本.pdf
- 上一篇:一种采用Gabor小波的纹理特征提取方法
- 下一篇:ICA算法-快速独立分量分析
相关资源
- PID_AutoTune_v0.rar
- vspd7.2.308.zip
- 价值2k的H漫画小说系统
- Pythonamp;课堂amp;笔记(高淇amp;400;集第
- ddos压力测试工具99657
- UML建模大全
- 开源1A锂电池充电板TP4056原理图+PCB
- m1卡 ic卡可选择扇区初始化加密软件
- TSCC.exe
- FTP课程设计(服务端+客户端)
- 计算机图形学 边填充算法实现代码
- 电力系统潮流计算程序集合
- oracle数据迁移项目实施方案
- Web Api 通过文件流 文件到本地
- Visio图标-最新最全的网络通信图标库
- Spire API文档
- OpenGL参考手册
- Python中Numpy库最新教程
- SPD博士V5.3.exe
- 直流无刷电机方波驱动 stm32 例程代码
- layui后台管理模板
- 仿知乎界面小程序源代码
- 云平台-阿里云详细介绍
- photoshop经典1000例
- scratch垃圾分类源码(最终版本).sb
- IAR ARM 7.8破解
- TI CCS V5.4 安装步骤及破解文件
- 松下plc FP-XH的驱动
- 局域网硬件信息收集工具
- 加快Windows XP操作系统开机速度
评论
共有 条评论