TA的每日心情 | 奋斗 2022-10-13 10:27 |
---|
签到天数: 216 天 连续签到: 1 天 [LV.7]常住居民III
|
本帖最后由 windworld-1898442 于 2017-1-23 23:33 编辑
前面已经为opencv搭建好了人脸识别所需的各种环境,包括摄像头的驱动Python开发环境以及SimpleCV库函数,这里简单整理成下面步骤一起看看效果
步骤一:搭建opencv开发环境
参考前面步骤
香蕉派 BPI-M2 Ultra 安装OpenCV方法总结
步骤二:安装SimpleCV库函数- sudo apt-get install ipython python-opencv python-scipy python-numpy python-setuptools
- python-pip
- sudo pip install https://github.com/ingenuitas/SimpleCV/zipball/master
- sudo apt-get install python-pygame
- sudo apt-get install python-imaging
复制代码 步骤三:开发插入UVC摄像头并测试
[size=13.3333px]香蕉派 BPI-M2 Ultra 安装mplayer测试
步骤四:Python实现人脸识别程序- #!/usr/bin/env python
- from SimpleCV import *
- from time import sleep
- myCamera = Camera(prop_set={'width':320, 'height': 240})
- myDisplay = Display(resolution=(320, 240))
- while not myDisplay.isDone():
- frame = myCamera.getImage()
- faces = frame.findHaarFeatures('face')
- if faces:
- for face in faces:
- print "Face at: " + str(face.coordinates())
- facelayer = DrawingLayer((frame.width,frame.height))
- w=face.width()
- h=face.height()
- print "x:"+str(w)+" y:"+str(h)
- facebox_dim = (w,h)
- facebox = facelayer.centeredRectangle(face.coordinates(),facebox_dim)
- frame.addDrawingLayer(facelayer)
- frame.applyLayers()
- print "faces has detected."
- else:
- print "No faces detected."
- frame.save(myDisplay)
- sleep(.1)
复制代码 说明:
myCamera =Camera(prop_set={'width':320, 'height': 240})
#指定摄像头影像尺寸
myDisplay =Display(resolution=(320, 240))
#显示窗口大小
frame =myCamera.getImage()
#获取视频流摄像头影像
faces =frame.findHaarFeatures('face')
#寻找人脸
facebox =facelayer.centeredRectangle(face.coordinates(),facebox_dim)
frame.addDrawingLayer(facelayer)
#框出识别到的人脸并把图层放到画面上
print "Nofaces detected."
#如果未检测到人脸打印信息
|
|