当前位置:网站首页>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、运行效果 |
|---|
可以看到我们霉霉的脸被边界框框起来了,检测的准确率还可以。
当然,我们不仅可以放入图像进行检测,还可以打开摄像头,进行动态的人脸检测,摄像头在第一节就介绍了,感兴趣的小伙伴去尝试尝试吧~
边栏推荐
- 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
- 0 basic self-study STM32 (wildfire) -- use register to light LED -- Explanation of GPIO function block diagram
- DevCloud加持下的青软,让教育“智”上云端
- Open source warehouse contribution - submit pr
- Epoll analysis
- 在供应链场景应用中,供应链管理系统扮演什么角色?
- R语言ggplot2可视化:使用patchwork包(直接使用加号+)将一个ggplot2可视化结果和一个plot函数可视化结果横向组合起来形成最终结果图
- How to create and delete MySQL triggers
- KUKA机器人外部轴配置你一定要知道的那些知识
- Self taught structure (small turtle C language)
猜你喜欢
随机推荐
Cross border independent station language Unicode to Hebrew
What value can SRM systems bring to the enterprise?
R语言使用MASS包的glm.nb函数建立负二项广义线性模型(negative binomial)、summary函数获取负二项广义线性模型模型汇总统计信息
迈动互联中标大家保险集团
mysql查询视图命令是哪个
reflex
设置双击运行 jar 文件
Use SSH to pull codes
Inherit Chinese virtues, pay attention to the health of the middle-aged and the elderly, and Yurun milk powder has strong respect for the elderly
Tencent cloud released orbit, an automated delivery and operation and maintenance product, to promote enterprise applications to be fully cloud native
Viewing splitchunks code segmentation from MPX resource construction optimization
Repair of JSON parsing errors in a collection
Walk with love, educate and run poor families, and promote public welfare undertakings
SCM系统是什么?供应链管理系统有哪些优势?
What are the advantages of SaaS services
Mysql高可用集群–MHA
力扣每日一题 06.29 两数相加
Redis 原理 - Sorted Set (ZSet)
About harbor private warehouse forgetting the login password
L'intercepteur handlerinterceptor personnalisé permet l'authentification de l'utilisateur
![填充每个节点的下一个右侧节点指针[利用好每个点->尽可能降低时空复杂度]](/img/33/bda0a898bfe3503197026d1f62e851.png)








