HowOldRobot 是微軟推出的一個小服務,實現識別圖片中的人臉以及預測圖片中人的年齡,預測模型可能比較復雜,但是想做一個簡單的人臉輪廓的識別還是比較簡單的,下面記錄使用Opencv工具包裡的haarcascade
進行識別的過程。
import matplotlib.pyplot as plt
%matplotlib inline
import sys, cv2
imagePath = '3jpg.jpg'
image = cv2.imread(imagePath)
# plt.imshow(image)
# plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
faceCascade = cv2.CascadeClassifier('F:\BaiduYunDownload\opencv\sources\data\haarcascades\haarcascade_frontalface_default.xml')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# plt.imshow(gray)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30,30),
flags=cv2.CASCADE_SCALE_IMAGE)
print faces
[[401 26 91 91]
[ 47 26 108 108]
[238 44 60 60]]
import random
font = cv2.FONT_HERSHEY_SIMPLEX
for (x, y, w, h) in faces:
cv2.rectangle(image, (x, y), (x+w, y+h), (14, 201, 255), 2)
cv2.putText(image, str(random.randrange(20, 30)), (x+(w/2)-18, y-10), font, 1,(14, 201, 255), 2)
plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
OpenCV官方教程中文版(For Python) PDF http://www.linuxidc.com/Linux/2015-08/121400.htm
Ubuntu Linux下安裝OpenCV2.4.1所需包 http://www.linuxidc.com/Linux/2012-08/68184.htm
Ubuntu 12.04 安裝 OpenCV2.4.2 http://www.linuxidc.com/Linux/2012-09/70158.htm
CentOS下OpenCV無法讀取視頻文件 http://www.linuxidc.com/Linux/2011-07/39295.htm
Ubuntu 12.04下安裝OpenCV 2.4.5總結 http://www.linuxidc.com/Linux/2013-06/86704.htm
Ubuntu 10.04中安裝OpenCv2.1九步曲 http://www.linuxidc.com/Linux/2010-09/28678.htm
基於QT和OpenCV的人臉識別系統 http://www.linuxidc.com/Linux/2011-11/47806.htm
[翻譯]Ubuntu 14.04, 13.10 下安裝 OpenCV 2.4.9 http://www.linuxidc.com/Linux/2014-12/110045.htm
OpenCV的詳細介紹:請點這裡
OpenCV的下載地址:請點這裡