Skip to content

Commit 5d42a12

Browse files
committed
init checkin
1 parent 810095f commit 5d42a12

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ Please be advised the red rectangle around faces.
3838
![](http://cloudsdocker.github.io/images/facial_postProcessImage.png)
3939

4040

41+
## Souce Code Dissection
42+
### Prerequite
43+
First of first, as you know, this program is composed by **python**,therefore, make sure you work station or laptop equiped with python, vesrion is irrelavant for this program.
44+
45+
In addition, this utility is built upon [OpenCV](http://opencv.org/downloads.html) (http://opencv.org/downloads.html), therefore please install this component as well. Just as its name suggested, it is an open source framework focus on computer vision related deep learning. This is one Intel lab built by Rusian, which is a very active community.
46+
47+
Particulary, if you are Mac users, it's recommended to use *brew* to setup OpenCV. Below is sample commands(The 1st line of following command may raise some errors, in that case please contact me via the link at the rear of this blog):
48+
```sh
49+
brew tap homebrew/science
50+
brew install opencv
51+
```
52+
53+
Let's dissect file **recognizeFace_loose_en.py** as one example
54+
4155

4256

4357

recognizeFace_loose_en.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# -*- coding: utf-8 -*-
2+
import cv2,sys
3+
import logging
4+
5+
# FORMAT='%(asctime)-15s %(user)-8s %(message)s'
6+
FORMAT='%(asctime)-15s [%(levelname)s] %(lineno)d %(clientip)s %(user)-8s %(message)s'
7+
#Full list of formats can be found at https://docs.python.org/2/library/logging.html#logging.Formatter
8+
9+
extraD={'clientip':'localhost','user':'todzhang'}
10+
logging.basicConfig(filename=r'app.log',level=logging.DEBUG,format=FORMAT)
11+
logger=logging.getLogger(__name__)
12+
13+
logger.debug(" start to process ",extra=extraD)
14+
# 使用输入的测试照片的文件名
15+
inputImageFile=sys.argv[1]
16+
logger.debug(" inputImageFile is %s",inputImageFile,extra=extraD)
17+
18+
logger.debug('使用 HAAR 的机器学习积累的原始文件,这里此文件包括了人脸识别的“经验”',extra=extraD)
19+
faceBase='haarcascade_frontalface_default.xml'
20+
21+
logger.debug(' 根据机器学习库文件创建一个 classifier',extra=extraD)
22+
faceClassifier=cv2.CascadeClassifier(faceBase)
23+
24+
logger.debug(' 使用库 cv2 来加载图片',extra=extraD)
25+
objImage=cv2.imread(inputImageFile)
26+
27+
logger.debug(' 首先将图片进行灰度化处理,以便于进行图片分析',extra=extraD)
28+
cvtImage=cv2.cvtColor(objImage,cv2.COLOR_BGR2GRAY)
29+
30+
logger.debug(' 执行detectMultiScale方法来识别物体,我们这里使用的是人脸的数据,因此用于面部识别',extra=extraD)
31+
foundFaces=faceClassifier.detectMultiScale(cvtImage,scaleFactor=1.3,minNeighbors=9,minSize=(50,50),flags = cv2.cv.CV_HAAR_SCALE_IMAGE)
32+
33+
logger.info(" 在图片中找到了 %d 个人脸",len(foundFaces),extra=extraD)
34+
35+
logger.debug(' 遍历发现的人脸',extra=extraD)
36+
for (x,y,w,h) in foundFaces:
37+
cv2.rectangle(objImage,(x,y),(x+w,y+h),(0,0,255),2)
38+
39+
logger.debug('显示这个图片识别的结果',extra=extraD)
40+
cv2.imshow(u'面部识别的结果已经高度框出来了。按任意键退出'.encode('gb2312'), objImage)
41+
cv2.waitKey(0)

0 commit comments

Comments
 (0)