AI战疫【百度大脑新品体验】驾驶行为分析试用攻略
worddict 发布于2020-04 浏览:3619 回复:6
3
收藏

功能介绍
疫情期间的安全出行,关系着很多人,驾驶行为分析针对车载场景识别驾驶员行为属性,新增4个识别属性:是否正确佩戴口罩、低头、闭眼、打哈欠,并进一步优化抽烟、使用手机属性的识别效果。本文将针对新增的特性进行评测。

接口描述
对于输入的一张车载驾驶员监控图片(可正常解码,且长宽比适宜),识别图像中是否有人体,若检测到至少1个人体,将目标最大的人体作为驾驶员,进一步识别驾驶员的属性行为,可识别使用手机、抽烟、未系安全带、双手离开方向盘、视线未朝前方、未佩戴口罩、闭眼、打哈欠、低头9种典型行为姿态。

注:若图像中检测到多个大小相当的人体,默认取画面中右侧最大的人体作为驾驶员;针对香港、海外地区的右舵车,可通过请求参数里的wheel_location字段,指定将左侧最大的人体作为驾驶员。

图片质量要求:

1、服务只适用于车载监控场景,请使用驾驶室的真实监控图片测试,勿用网图、非车载场景的普通监控图片测试,否则测试效果不具备代表性。

2、车内摄像头硬件选型无特殊要求,分辨率建议720p以上,但更低分辨率的图片也能识别,只是效果可能有差异。

3、车内摄像头部署方案建议:尽可能拍全驾驶员的身体,并充分考虑背光、角度、方向盘遮挡等因素。

4、服务适用于夜间红外监控图片,识别效果跟可见光图片相比可能略微有差异。

5、图片主体内容清晰可见,模糊、驾驶员遮挡严重、光线暗等情况下,识别效果肯定不理想。

帮助地址:https://ai.baidu.com/ai-doc/BODY/Nk3cpywct

请求URL: https://aip.baidubce.com/rest/2.0/image-classify/v1/driver_behavior


返回示例

{
"person_num": 1,
"person_info": [
{
"attributes": {
"cellphone": {
"threshold": 0.76,
"score": 0.089325942099094
},
"yawning": {
"threshold": 0.66,
"score": 0.0007511890726164
},
"not_buckling_up": {
"threshold": 0.58,
"score": 0.81095975637436
},
"no_face_mask": {
"threshold": 0.72,
"score": 0.99875915050507
},
"both_hands_leaving_wheel": {
"threshold": 0.3,
"score": 0.9014720916748
},
"eyes_closed": {
"threshold": 0.1,
"score": 0.090511165559292
},
"head_lowered": {
"threshold": 0.58,
"score": 0.11450858414173
},
"smoke": {
"threshold": 0.25,
"score": 0.026156177744269
},
"not_facing_front": {
"threshold": 0.53,
"score": 0.68074524402618
}
},
"location": {
"width": 856,
"top": 419,
"score": 0.90945136547089,
"left": 464,
"height": 626
}
}
],
"log_id": 2320165720061799596
}

代码实现(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))
        #新增特性
        #未带口罩
        score = attributes['no_face_mask']['score']
        threshold = attributes['no_face_mask']['threshold']
        if score>threshold:
            warning=warning+'未带口罩 '
        result=result+( '未带口罩 {:.5f} \n'.format(score))
        #闭眼
        score = attributes['eyes_closed']['score']
        threshold = attributes['eyes_closed']['threshold']
        if score>threshold:
            warning=warning+'闭眼 '
        result=result+( '闭眼 {:.5f} \n'.format(score))
        #低头
        score = attributes['head_lowered']['score']
        threshold = attributes['head_lowered']['threshold']
        if score>threshold:
            warning=warning+'低头 '
        result=result+( '低头 {:.5f} \n'.format(score))
        #打哈欠
        score = attributes['yawning']['score']
        threshold = attributes['yawning']['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)
        print('人数:',data['person_num'])
        persons=data['person_info']
        
        generate_report(persons)

driver_behavior('../wimage/drive2.jpg')

测试结果及评价

人数: 1
使用手机: 1.00000
抽烟: 0.00024
未系安全带: 0.88225
双手离开方向盘: 0.01746
视角未看前方: 0.71449
未带口罩 0.99710
闭眼 0.00006
低头 0.00318
打哈欠: 0.00004
警告:使用手机 未系安全带 视角未看前方 未带口罩

 

疫情期间的安全出行,关系着很多人,驾驶行为分析针对车载场景识别驾驶员行为属性,本功能新增4个识别属性:是否正确佩戴口罩、低头、闭眼、打哈欠,并进一步优化抽烟、使用手机属性的识别效果。经过测试发现效果非常好,识别非常准确,可以及时预警违规/危险驾驶行为,提升行车安全性,为疫情期间仍坚守在运输和出行岗位上的人们保驾护航。

收藏
点赞
3
个赞
共6条回复 最后由用户已被禁言回复于2022-04
#7大手拉小手0123回复于2020-08
#6 worddict回复
您好: 我的邮箱联系方式是:tophawk@foxmail.com 

恭喜恭喜

0
#6worddict回复于2020-08
#4 用户已被禁言回复
您好,恭喜您此篇稿件,被我们AI战疫【百度大脑新品体验】最终评选为优质稿件,方便留下您的邮箱联系方式么?
展开

您好:

我的邮箱联系方式是:tophawk@foxmail.com 

0
#5大手拉小手0123回复于2020-06

又一个不错的新作品

 

0
#4用户已被禁言回复于2020-06

您好,恭喜您此篇稿件,被我们AI战疫【百度大脑新品体验】最终评选为优质稿件,方便留下您的邮箱联系方式么?

0
#3worddict回复于2020-06

用起来感觉很不错

0
#2worddict回复于2020-06

功能很强大

0
TOP
切换版块