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

最新文章

  1. yii2批量添加的问题
  2. MongoDB基础知识
  3. C++模拟C#事件委托机制(二)
  4. zepto - slice
  5. Scala中的match(模式匹配)
  6. Python中处理时间 —— time模块
  7. Ext.Net学习笔记17:Ext.Net GridPanel Selection
  8. Windows 8上强制Visual Studio以管理员身份运行
  9. js/bat批处理调用谷歌浏览器chrome批量打开网页测试web性能
  10. 数据库操作封装类 DBHelper.cs
  11. 刷新指定行或区 cell
  12. JS学习之闭包的理解
  13. linux-redhat-iso 下载
  14. dynamic-load-apk 插件与宿主方法互调
  15. 简单的CSS颜色查看工具
  16. java基础知识—继承
  17. Netty实战二之自己的Netty应用程序
  18. js自动运行
  19. Hibernate注解与JPA
  20. 闭区间套定理(Nested intervals theorem)讲解1

热门文章

  1. tmux的使用
  2. pycharm同级目录导入问题
  3. [luogu5008]逛庭院
  4. [hgoi#2019/2/24]玄学考试
  5. 【转】学习MOS管技术知识,这篇文章就够了!
  6. [CF1091D]New Year and the Permutation Concatenation
  7. A1032. Sharing
  8. table默认的box-sizing在不同浏览器不同
  9. Vue初学者可能不知道的坑
  10. array_values