【使用攻略】【驾驶行为分析】
功能介绍
检测到驾驶员后,进一步识别行为属性,可识别使用手机、抽烟、不系安全带、双手离开方向盘、视角未朝前方5大类行为
应用场景
营运车辆驾驶监测
针对出租车、客车、公交车、货车等各类营运车辆,实时监控车内情况,识别驾驶员抽烟、使用手机、未系安全带等危险行为,及时预警,降低事故发生率,保障人身财产安全
社交内容分析审核
汽车类论坛、社区平台,对配图库以及用户上传的UGC图片进行分析识别,自动过滤出涉及危险驾驶行为的不良图片,有效减少人力成本并降低业务违规风险
接口描述
对于输入的一张车载监控图片(可正常解码,且长宽比适宜),识别图像中是否有人体(驾驶员),若检测到至少1个人体,则进一步识别属性行为,可识别使用手机、抽烟、未系安全带、双手离开方向盘、视线未朝前方5种典型行为姿态。
图片质量要求:
1、服务只适用于车载司机场景,请使用驾驶室的真实监控图片测试,勿用网图、非车载场景的普通监控图片、或者乘客的监控图片测试,否则效果不具备代表性。
2、车内摄像头硬件选型无特殊要求,分辨率建议720p以上,但更低分辨率的图片也能识别,只是效果可能有差异。
3、车内摄像头部署方案建议:尽可能拍全驾驶员的身体,并充分考虑背光、角度、方向盘遮挡等因素。
4、服务适用于夜间红外监控图片,识别效果跟可见光图片相比可能略微有差异。
5、图片主体内容清晰可见,模糊、驾驶员遮挡严重、光线暗等情况下,识别效果肯定不理想。
代码实现(python3):
import urllib
import base64
import json
import time
#client_id 为官网获取的AK, client_secret 为官网获取的SK
client_id = 'XXXXXXXX'
client_secret = 'XXXXXXXXX'
#获取token
def get_token():
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + client_id + '&client_secret=' + client_secret
request = urllib.request.Request(host)
request.add_header('Content-Type', 'application/json; charset=UTF-8')
response = urllib.request.urlopen(request)
token_content = response.read()
if token_content:
token_info = json.loads(token_content)
token_key = token_info['access_token']
return token_key
#生成报告
def generate_report(persons):
for person in persons:
warning=''
result=''
attributes=person['attributes']
#使用手机
score = attributes['cellphone']['score']
threshold = attributes['cellphone']['threshold']
if score>threshold:
warning=warning+'使用手机 '
result=result+('使用手机: {:.5f} \n'.format(score))
#抽烟
score = attributes['smoke']['score']
threshold = attributes['smoke']['threshold']
if score>threshold:
warning=warning+'抽烟 '
result=result+( '抽烟: {:.5f} \n'.format(score))
#未系安全带
score = attributes['not_buckling_up']['score']
threshold = attributes['not_buckling_up']['threshold']
if score>threshold:
warning=warning+'未系安全带 '
result=result+( '未系安全带: {:.5f} \n'.format(score))
#双手离开方向盘
score = attributes['both_hands_leaving_wheel']['score']
threshold = attributes['both_hands_leaving_wheel']['threshold']
if score>threshold:
warning=warning+'双手离开方向盘 '
result=result+( '双手离开方向盘: {:.5f} \n'.format(score))
#视角未看前方
score = attributes['not_facing_front']['score']
threshold = attributes['not_facing_front']['threshold']
if score>threshold:
warning=warning+'视角未看前方 '
result=result+( '视角未看前方: {:.5f} \n'.format(score))
if warning=='':
warning='无'
result=result+ '警告:'+warning
print(result)
#驾驶行为识别
def driver_behavior(filename):
request_url = "https://aip.baidubce.com/rest/2.0/image-classify/v1/driver_behavior"
print(filename)
# 二进制方式打开图片文件
f = open(filename, 'rb')
img = base64.b64encode(f.read())
params = dict()
params['image'] = img
params = urllib.parse.urlencode(params).encode("utf-8")
access_token = get_token()
begin = time.perf_counter()
request_url = request_url + "?access_token=" + access_token
request = urllib.request.Request(url=request_url, data=params)
request.add_header('Content-Type', 'application/x-www-form-urlencoded')
response = urllib.request.urlopen(request)
content = response.read()
end = time.perf_counter()
print('处理时长:'+'%.2f'%(end-begin)+'秒')
if content:
content=content.decode('utf-8')
data = json.loads(content)
print('人数:',data['person_num'])
persons=data['person_info']
generate_report(persons)
产品测评:
人数: 1
使用手机: 0.95
抽烟: 0.01
未系安全带: 0.80
双手离开方向盘: 0.95
视角未看前方: 0.98
警告:使用手机 未系安全带 双手离开方向盘 视角未看前方
测试结果及建议
通过评测发现百度驾驶行为分析具有速度快,识别准确等优势。针对不同应用,还有以下一些特点:
深入场景:专项训练高精度识别模型,覆盖出租车、客车、公交车、货车等典型车载场景
应用灵活:针对每类属性行为,分别返回概率分数和建议阈值,可根据实际业务需求灵活设置
服务稳定:可提供企业级稳定、精确的大流量服务,拥有毫秒级识别响应能力及99.9%的可靠性保障
建议可以将警告信息与百度的语音合成结合起来,直接通过语音告警提示驾驶员。
可以通过结果二次开发,语音合成播报提醒司机
怎么与语音结合呢?是不是通过语音合成读取放回的结果啊??
可以和语音结合在一起
这个功能对于驾驶安全有很大帮助