当前位置:网站首页>3h精通OpenCV(九)-最简单的人脸检测
3h精通OpenCV(九)-最简单的人脸检测
2022-06-29 17:37:00 【华为云】
| 0、准备工作 |
|---|
右击新建的项目,选择Python File,新建一个Python文件,然后在开头import cv2导入cv2库。
import cv2
| 1、实现源码 |
|---|
要进行人脸检测,对于现在的深度学习来说简直是入门级项目了。
如果我们使用传统的方法来进行人脸检测,就可以省去寻找数据集、调参以及训练的时间了。
- faceCascade是我们的人脸分类器,一个写好的分类器文件,虽然很老,但是很有效。关注公众号《萌新加油站》,后台回复:==人脸识别==,即可获取。
- img是读取的图像,先通过
cvtColor(img,cv2.COLOR_BGR2GRAY)转为灰度图像 detectMultiScale()中的参数是灰度图像,比例因子,还有邻居个数。- 下面围绕面孔创建一个边界框,边界框的两个坐标点可以确定框的位置,然后是bounding box的颜色,最后是线条的厚度。
- 最后就
imshow显示结果图像,waitKey(0)让窗口持久保持。
import cv2faceCascade=cv2.CascadeClassifier("Resources/haarcascade_frontalface_default.xml")img=cv2.imread("Resources/mm.jpg")imgGray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)faces=faceCascade.detectMultiScale(imgGray,1.1,4)for(x,y,w,h) in faces: cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)cv2.imshow("Result",img)cv2.waitKey(0)| 2、运行效果 |
|---|
可以看到我们霉霉的脸被边界框框起来了,检测的准确率还可以。
当然,我们不仅可以放入图像进行检测,还可以打开摄像头,进行动态的人脸检测,摄像头在第一节就介绍了,感兴趣的小伙伴去尝试尝试吧~
边栏推荐
- KUKA机器人外部轴配置你一定要知道的那些知识
- 剑指 Offer 13. 机器人的运动范围 (BFS)
- 关于Go中两个模块互相调用的场景解决方案
- 固定资产管理系统让企业动态掌握资产情况
- R language uses GLM function to build Poisson logarithm linear regression model, processes three-dimensional contingency table data to build saturation model, uses exp function and coef function to ob
- Online text digit recognition list summation tool
- The dplyr package filter function of R language filters the data in dataframe data through combinatorial logic (and logic). The content of one field is equal to one of the specified vectors, and the v
- Redis principle - sorted set (Zset)
- 人脸识别4-百度商用方案调研
- Younger sister Juan takes you to learn JDBC - 2-day dash Day1
猜你喜欢
![分割回文串[dp + dfs组合]](/img/7b/221b000984977508f849e19802c2c2.png)
分割回文串[dp + dfs组合]

Tencent cloud released orbit, an automated delivery and operation and maintenance product, to promote enterprise applications to be fully cloud native

剖析下零拷贝机制的实现原理,适用场景和代码实现
Master slave replication of MySQL

PCB frame drawing - ad19

mysql支持外键吗

传承中华美德,关注中老年大健康,育润奶粉敬老情浓

Walk with love, educate and run poor families, and promote public welfare undertakings

【WebDriver】使用AutoIt上传文件

Automatic vending machine
随机推荐
从一个被应用商店坑了的BUG说起
0 basic self-study STM32 (wildfire) - register lit LED
DevCloud加持下的青软,让教育“智”上云端
Bags of Binary Words for Fast Place Recognition in Image Sequenc
Custom handlerinterceptor interceptor for user authentication
Graduation season | Huawei experts teach interview tips: how to get a high salary offer from a large factory?
LeetCode 每日一题——535. TinyURL 的加密与解密
Kubernetes deployment dashboard (Web UI management interface)
底层内功修养
Collaborative development of epidemic home outsourcing project 𞓜 community essay solicitation
使用autoIt 上传文件
Issue 42: is it necessary for MySQL to have multiple column partitions
第42期:MySQL 是否有必要多列分区
High landing pressure of "authorization and consent"? Privacy computing provides a possible compliance "technical solution"
R语言使用MASS包的glm.nb函数建立负二项广义线性模型(negative binomial)、summary函数获取负二项广义线性模型模型汇总统计信息
力扣每日一题 06.29 两数相加
如何使用B/S开发工具DevExtreme的图表控件 - 自定义轴位置?
Sectigo ov pan domain name certificate is 1590 yuan a year easy to use
数字孪生能源系统,打造低碳时代“透视”眼
从居家办公中感悟适配器模式 | 社区征文