惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
B
Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
Netflix TechBlog - Medium
腾讯CDC
IT之家
IT之家
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
C
Cyber Attacks, Cyber Crime and Cyber Security
罗磊的独立博客
P
Privacy International News Feed
D
DataBreaches.Net
T
Threatpost
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google DeepMind News
Google DeepMind News
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
S
Securelist
P
Palo Alto Networks Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Secure Thoughts
Security Archives - TechRepublic
Security Archives - TechRepublic
L
LangChain Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Troy Hunt's Blog
The Last Watchdog
The Last Watchdog
T
Tor Project blog
V
Vulnerabilities – Threatpost
T
Threat Research - Cisco Blogs
H
Heimdal Security Blog
Hugging Face - Blog
Hugging Face - Blog
Hacker News: Ask HN
Hacker News: Ask HN
阮一峰的网络日志
阮一峰的网络日志
博客园 - 叶小钗
S
SegmentFault 最新的问题
Know Your Adversary
Know Your Adversary
博客园_首页
N
News and Events Feed by Topic
G
GRAHAM CLULEY
L
LINUX DO - 热门话题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Help Net Security
Help Net Security
Simon Willison's Weblog
Simon Willison's Weblog
H
Hacker News: Front Page
大猫的无限游戏
大猫的无限游戏
AWS News Blog
AWS News Blog
The Cloudflare Blog
AI
AI

博客园 - Q.Lee.lulu

aProxy: 带认证授权和权限控制的反向代理 Nginx做前端Proxy时TIME_WAIT过多的问题 Cubieboard通过aria2和minidlna来架设家庭媒体中心 与IT&码农有关的电影和记录片 golang与node.js的http模块性能对比测试(go1) linux下SublimeText的中文输入法问题之解决方案 golang与node.js的http对比测试 作为Web开发人员,我为什么喜欢Google Chrome浏览器 sqlalchemy在web.py中的session使用 web.py大文件下载 Python和Node.js支持尾递归吗? 小文件、nginx、Redis、Moosefs 一道JavaScript面试题(setTimeout) 用Eclipse调试Node.js代码 Javascript中的类数组对象 Javascript正则分组命名 抛弃Fastcgi,用uwsgi来部署你的Django程序吧 Node.js:用JavaScript写服务器端程序-介绍并写个MVC框架 FaWave(发微)-Chrome上的多微博全能插件
用OpenCv来做人脸识别
Q.Lee.lulu · 2012-02-08 · via 博客园 - Q.Lee.lulu

参考这篇文章: http://tech.idv2.com/2012/01/20/face-detection-with-python-opencv/

python比较简单,只需安装 python-opencv 就行:

$ sudo apt-get install python-opencv

python的实现也很简单,参考:http://opencv.willowgarage.com/documentation/python/objdetect_cascade_classification.html

代码:

#!/usr/bin/python
#
-*- coding: UTF-8 -*-

# face_detect.py

# Face Detection using OpenCV. Based on sample code from:
#
http://python.pastebin.com/m76db1d6b

# Usage: python face_detect.py <image_file>

import sys, os
import cv
from PIL import Image, ImageDraw

def detectObjects(image):
"""Converts an image to grayscale and prints the locations of any faces found"""
storage = cv.CreateMemStorage()

cascade = cv.Load('haarcascade_frontalface_alt.xml')
faces = cv.HaarDetectObjects(image, cascade, storage)

result = []
for (x,y,w,h),n in faces:
result.append((x, y, x+w, y+h))

return result

def process(infile, outfile):

image = cv.LoadImage(infile);
if image:
faces = detectObjects(image)

im = Image.open(infile)

if faces:
draw = ImageDraw.Draw(im)
for f in faces:
draw.rectangle(f, outline=(255, 0, 255))

im.save(outfile, "JPEG", quality=100)
else:
print "Error: cannot detect faces on %s" % infile

if __name__ == "__main__":
process('input.jpg', 'output.jpg')

注:haarcascade_frontalface_alt.xml 可以在 https://github.com/talvarez/Face.js/tree/master/cascades 找到

Node.js的话,有一个叫Face.js的项目,对OpenCv做了简单封装,地址是: https://github.com/talvarez/Face.js 
这个需要先安装OpenCv库,目前版本是2.3.1,按照可以参考: UBUNTU 下编译安装opencv 2.3.1

Face.js的具体的示例代码可以在Face.js里面的example里面找到,这里贴个简单的: 

var Face = require('../build/default/face.node'),
detector = new Face.init();

detector.img = './samples/frame1.png';
detector.maxsize = 20;
detector.pathto = '../cascades/'

detector.oncomplete = function(faces){
console.log("I found " + faces.length + " faces");
for(var i = 0; i < faces.length; i++) {
console.log(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
}
};

detector.run();


最后贴张识别后的图: