Python 对图片进行人脸识别
2016-01-07 15:29
543 查看
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[/code]
相关文章推荐
- 黑科技 Python脚本帮你找出微信上删除你好友的人
- [Leetcode]@python 61. Rotate List
- python re的几个函数
- numpy安装
- python 大数据分析
- Python学习笔记
- Python fabric实现远程操作和部署
- 5.1.4. List Comprehensions(列表解析)
- windows下,python+scrapy环境搭建
- python 线程使用
- python 学习笔记 if语句
- Python系列之 - python数据类型(二)
- visual studio 2015使用python tools远程调试maya 2016
- python 实例7 为rhel添加系统用户与登录密码,并给root 发送邮件
- 【Python那些事儿之七】Iterators详解
- Python程序员最常犯的十个错误
- 一个基于Python 装饰器的缓存库——wrapcache
- Python中JSON在解析的同时进行自定义编码处理
- 5.1.1. Using Lists as Stacks(像栈一样)
- caffe的python接口示例