TA的每日心情 | 奋斗 2022-10-13 10:27 |
---|
签到天数: 216 天 连续签到: 1 天 [LV.7]常住居民III
|
前面给出了相关的环境搭建和具体步骤,这里只是给出具体的代码和实验效果,结合相关的步骤进行说明,实验如下:
步骤一:搭建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摄像头并测试
步骤四: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."
#如果未检测到人脸打印信息
效果
|
|