博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
FR人脸识别初步使用
阅读量:3951 次
发布时间:2019-05-24

本文共 1358 字,大约阅读时间需要 4 分钟。

FR人脸识别初步使用

此次试验在Anaconda-Jupyter环境下完成

人脸定位

安装opencv-python

pip install opencv-python
(注意:需要包:'Python路径下/Lib/site-packages/cv2/data/haarcascade_frontalface _default.xml’以及图片test1.jpg)
文件夹内部创建Python文件

import cv2def detect(filename):    face_cascade = cv2.CascadeClassifier('D:/anaconda/Lib/site-packages/cv2/data/haarcascade_eye.xml')    img = cv2.imread(filename)    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)    faces = face_cascade.detectMultiScale(gray, 1.3, 5)    for (x, y, w, h) in faces:        img = cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)    cv2.imshow('Person Detected!', img)    cv2.waitKey(0)    cv2.destroyAllWindows()if __name__ == '__main__':    detect('test1.jpg')

结果如下

人脸识别选择眼部识别haarcascade_eye.xml再次测试
眼部识别

特征点检测

需要dlib包,同样能够输出图像。

创建Python文件

import cv2import dlibpath = "test1.jpg"img = cv2.imread(path)gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)#人脸分类器detector = dlib.get_frontal_face_detector()# 获取人脸检测器predictor = dlib.shape_predictor('D:/anaconda/Lib/site-packages/shape_predictor_68_face_landmarks.dat/shape_predictor_68_face_landmarks.dat')dets = detector(gray, 1)for face in dets:    shape = predictor(img, face)  # 寻找人脸的68个标定点    # 遍历所有点,打印出其坐标,并圈出来    for pt in shape.parts():        pt_pos = (pt.x, pt.y)        cv2.circle(img, pt_pos, 2, (0, 255, 0), 1)    cv2.imshow("image", img)cv2.waitKey(0)cv2.destroyAllWindows()

结果如下

处理结果

转载地址:http://xorwi.baihongyu.com/

你可能感兴趣的文章
如何添加一个提醒
查看>>
Displaying Card Flip Animations 显示卡片翻转动画
查看>>
Zooming a View 缩放视图
查看>>
Animating Layout Changes 动画布局的更改
查看>>
Controlling Your App’s Volume and Playback 控制应用程序的音量和播放
查看>>
Dealing with Audio Output Hardware 处理音频输出硬件设备
查看>>
Monitoring the Battery Level and Charging State 监测电池电量和充电状态
查看>>
Determining and Monitoring the Docking State and Type 判断并监测设备的停驻状态与类型
查看>>
Custom Drawing 自定义绘制
查看>>
跨平台的文字编码转换方法--ICU
查看>>
ICU4C 4.4 静态库的编译
查看>>
FTP下载类, windows平台下对CFtpConnection上传下载的封装类
查看>>
代码自动生成-宏带来的奇技淫巧
查看>>
VC com开发中实现IObjectSafety
查看>>
c# 正则表达式基础
查看>>
C#3.0语言新特性
查看>>
W32Dasm反汇编工具使用教程
查看>>
EXE破解工具介绍
查看>>
机械码对应值
查看>>
常用语音编码的WAVE文件头格式剖析--各种编码
查看>>