Python 对图片进行人脸识别
2024-10-14 10:56:34
import cv2 def detect(path):
img = cv2.imread(path)
cascade = cv2.CascadeClassifier("/vagrant/detect/haarcascade_frontalface_alt.xml")#xml文件路径一定要注意
rects = cascade.detectMultiScale(img, 1.3, 4, cv2.cv.CV_HAAR_SCALE_IMAGE, (20,20)) if len(rects) == 0:
return [], img
rects[:, 2:] += rects[:, :2]
return rects, img def box(rects, img):
for x1, y1, x2, y2 in rects:
cv2.rectangle(img, (x1, y1), (x2, y2), (127, 255, 0), 2)
cv2.imwrite('/vagrant/img/detected.jpg', img); rects, img = detect("/vagrant/img/one.jpg")
box(rects, img)
以上是源码,来自:
http://fideloper.com/facial-detection
依赖:
$ sudo apt-get update
$ sudo apt-get install -y vim build-essential python-software-properties # The Basics
$ sudo apt-get install -y python-opencv python-numpy python-scipy # OpenCV items $ wget http://eclecti.cc/files/2008/03/haarcascade_frontalface_alt.xml
最新文章
- yii2批量添加的问题
- MongoDB基础知识
- C++模拟C#事件委托机制(二)
- zepto - slice
- Scala中的match(模式匹配)
- Python中处理时间 —— time模块
- Ext.Net学习笔记17:Ext.Net GridPanel Selection
- Windows 8上强制Visual Studio以管理员身份运行
- js/bat批处理调用谷歌浏览器chrome批量打开网页测试web性能
- 数据库操作封装类 DBHelper.cs
- 刷新指定行或区 cell
- JS学习之闭包的理解
- linux-redhat-iso 下载
- dynamic-load-apk 插件与宿主方法互调
- 简单的CSS颜色查看工具
- java基础知识—继承
- Netty实战二之自己的Netty应用程序
- js自动运行
- Hibernate注解与JPA
- 闭区间套定理(Nested intervals theorem)讲解1