python3人脸识别的两种方法
作者:小满丫 时间:2021-07-09 23:12:52
本文实例为大家分享了python3实现人脸识别的具体代码,供大家参考,具体内容如下
第一种:
import cv2
import numpy as np
filename = 'test1.jpg'
path = r'D:\face'
def detect(filename):
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
face_cascade.load(path + '\haarcascade_frontalface_default.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.namedWindow("vikings detected")
cv2.imshow("vikings detected", img)
cv2.waitKey(0)
detect(filename)
结果:
第二种 参考贾志刚opencv教程
# -*- coding:utf-8 -*-
import cv2 as cv
import numpy as np
src = cv.imread('test1.jpg')
path = r'D:\face'
def face_detect_demo():
gray = cv.cvtColor(src,cv.COLOR_BGR2GRAY)
face_detector = cv.CascadeClassifier('haarcascade_frontalface_default.xml')
face_detector.load(path + '\haarcascade_frontalface_default.xml')
faces = face_detector.detectMultiScale(gray,1.3,5)
for x,y,w,h in faces:
cv.rectangle(src,(x,y),(x+w,y+h),(0,0,255),2)
cv.imshow("result",src)
print("--------------python face detect-------------")
cv.namedWindow("input image",0)
cv.namedWindow("result",0)
cv.imshow("input image",src)
face_detect_demo()
cv.waitKey(0)
cv.destroyAllWindows()
结果:
来源:https://blog.csdn.net/weixin_42512266/article/details/89467643
标签:python,人脸识别
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
js取得当前鼠标的X,Y坐标
2007-09-27 19:52:00
Python全栈之for循环
2021-06-04 20:55:06
![](https://img.aspxhome.com/file/2023/8/87608_0s.png)
django-allauth入门学习和使用详解
2022-05-24 12:36:09
Python Tkinter实现简易计算器功能
2023-08-08 09:53:30
![](https://img.aspxhome.com/file/2023/5/105795_0s.jpg)
django 装饰器 检测登录状态操作
2021-03-13 16:40:40
![](https://img.aspxhome.com/file/2023/2/97592_0s.jpg)
python 协程并发数控制
2023-09-20 01:07:10
python超详细实现完整学生成绩管理系统
2022-08-25 08:59:08
![](https://img.aspxhome.com/file/2023/5/82775_0s.png)
python 实现简单的吃豆人游戏
2023-12-02 22:00:59
![](https://img.aspxhome.com/file/2023/5/97645_0s.gif)
Python技法之如何用re模块实现简易tokenizer
2021-08-04 17:03:52
Python matplotlib绘制散点图配置(万能模板案例)
2023-08-02 23:04:18
![](https://img.aspxhome.com/file/2023/9/61989_0s.png)
Python算法练习之二分查找算法的实现
2023-08-27 14:29:29
![](https://img.aspxhome.com/file/2023/8/104388_0s.jpg)
Python 数据结构之队列的实现
2021-11-28 15:27:26
解决pycharm运行时interpreter为空的问题
2022-04-01 22:56:39
![](https://img.aspxhome.com/file/2023/4/103354_0s.jpg)
Python使用JSON库解析JSON数据的方法
2021-09-24 13:35:10
![](https://img.aspxhome.com/file/2023/2/71492_0s.jpg)
python实现计算资源图标crc值的方法
2022-07-02 17:57:56
python利用socketserver实现并发套接字功能
2021-01-28 16:36:45
![](https://img.aspxhome.com/file/2023/1/72011_0s.jpg)
sqlserver主键设计的注意点
2012-08-21 10:42:44
Pycharm 使用 Pipenv 新建的虚拟环境(图文详解)
2023-12-08 18:55:11
![](https://img.aspxhome.com/file/2023/6/107596_0s.png)
PHP开发实现快递查询功能详解
2023-11-24 12:19:39
![](https://img.aspxhome.com/file/2023/3/55723_0s.png)
Python3利用SMTP协议发送E-mail电子邮件的方法
2023-10-12 17:39:32
![](https://img.aspxhome.com/file/2023/2/63202_0s.jpg)