您的位置:首页 > Web前端 > Node.js

ROS学习--人脸识别NODE

2016-06-21 12:31 561 查看

说明

所用的人脸识别为faceplusplus的服务

准备

先安装摄像头,我在树莓派上实验,所用的也是树莓派专用的摄像头。

摄像头具体安装可以见http://shumeipai.nxez.com/2013/10/07/raspberry-pi-to-install-the-camera-module.html
注意插线的时候别插反了就可以。

安装好摄像头的硬件之后,需要修改树莓派的配置,打开摄像头。

$ sudo raspi-config
选择其中的Enable Camera按照提示操作,注意,树莓派打开摄像头的配置之后,需要重启,这个在退出raspi-config之前会有提示。

安装好之后可以测试可以拍张照片测试一下。命令如下
$ raspistill -o image.jpg -t 1000
-o 表示输出的文件名

-t 表示拍照的延时,如果不加,默认的延时时间为5秒。

人脸识别也应该是广播的形式,但是我们可以先用服务的方式实现。

关于视频还有一个Python的包picamera,文档在 http://picamera.readthedocs.org/但我这里并没有使用。

在人脸识别之前,还需要在faceplusplus自己的应用上做一些准备工作,我使用faceplusplus的hello.py其中的代码改的。

# 首先,导入SDK中的API类
from facepp import API
from facepp import File
api = API(API_KEY, API_SECRET)

#创建一个group用来添加人脸
api.group.create(group_name = 'ry_robot_001')

#探测人脸并在这个group中添加person
result = api.detection.detect(img = File(filepath), mode = 'oneface')
face_id = result['face'][0]['face_id']
api.person.create(person_name = name, group_name = 'ry_robot_001', face_id = face_id)

#对这个group进行训练
result = api.recognition.train(group_name = 'ry_robot_001', type = 'all')
session_id = result['session_id']
# 等待训练完成
while True:
result = api.info.get_session(session_id = session_id)
if result['status'] == u'SUCC':
print_result('Async train result:', result)
break
time.sleep(1)

# 识别未知脸部图片

result = api.recognition.recognize(img = File(TARGET_IMAGE), group_name = 'ry_robot_001')
print_result('Recognize result:', result)

# 当然还可以删除创建的group和person
#api.group.delete(group_name = 'ry_robot_001')
#api.person.delete(person_name =  name_list )


这里的代码是说明,node的相关代码已经提交到github,地址:https://github.com/roboyun/ros_afr

备注

关于视频摄像头实时转播。

先启动客户端,将netcat的数据流发送到mplayer上,fps当小于40的时候,会有非常明显的延时

nc -l 5001 | mplayer -fps 60 -cache 1024 -
在树莓派上的命令

raspivid -w 960 -h 540 -t 999999 -o - | nc 192.168.1.2 5001
mplayer 播放视频过程中截图的代码,截图可用于人脸识别。

import time
import subprocess

#cmd = 'mplayer -slave -quiet -vf screenshot a.mp4'
cmd = 'mplayer -quiet -vf screenshot a.mp4'
#print cmd.split()
p = subprocess.Popen(cmd.split(),shell=False,stdout=subprocess.PIPE,stdin=subprocess.PIPE)
while True:
time.sleep(2)
print 'screen shot'
p.stdin.write('s')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息