关于百度AI网站上的操作和之前关于人脸识别部分的操作一样,注意要在人体识别部分再重新建立一个应用,并且获得
APP_ID = '××××××'
API_KEY = '×××××××××××'
SECRET_KEY = '××××××××××××××'
这三个关键值。
#! /usr/bin/python
# Copyright (c) 2015, Rethink Robotics, Inc.
# Using this CvBridge Tutorial for converting
# ROS images to OpenCV2 images
# http://wiki.ros.org/cv_bridge/Tutorials/ConvertingBetweenROSImagesAndOpenCVImagesPython
# Using this OpenCV2 tutorial for saving Images:
# http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_gui/py_image_display/py_image_display.html
# rospy for the subscriber
from PIL import Image
from std_msgs.msg import String
from aip import AipFace
import base64
import PIL.Image
import rospy
# ROS Image message
from sensor_msgs.msg import Image
# ROS Image message -> OpenCV2 image converter
from cv_bridge import CvBridge, CvBridgeError
# OpenCV2 for saving an image
import cv2
from aip import AipBodyAnalysis
APP_ID = '×××××××××××'
API_KEY = '×××××××××××××××××××××××'
SECRET_KEY = '×××××××××××××××××××××××××××'
client = AipBodyAnalysis(APP_ID, API_KEY, SECRET_KEY)
# Instantiate CvBridge
bridge = CvBridge()
def image_callback(msg):
try:
listen()
# Convert your ROS Image message to OpenCV2
cv2_img = bridge.imgmsg_to_cv2(msg, "bgr8")
except CvBridgeError, e:
print(e)
else:
# Save your OpenCV2 image as a jpeg
cv2.imwrite('/home/wly/catkin_ws/src/face_men/camera_photo/photo.jpeg', cv2_img)
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
def listen():
image = get_file_content('/home/wly/catkin_ws/src/face_men/camera_photo/photo.jpeg')
a = client.bodyAnalysis(image);
print(a)
def main():
rospy.init_node('image_listener')
# Define your image topic
image_topic = "/usb_cam/image_raw"
# Set up your subscriber and define its callback
rospy.Subscriber(image_topic, Image, image_callback)
print("Received an image!")
# Spin until ctrl + c
rospy.spin()
if __name__ == '__main__':
main()
a = client.bodyAnalysis(image);
此部分调用bodyAnalysis()函数,返回人体关键点的一些信息。
字段 | 是否必选 | 类型 | 说明 |
---|---|---|---|
person_num | 是 | uint32 | 人体数目 |
person_info | 是 | object[] | 人体姿态信息 |
+body_parts | 是 | object | 身体部位信息,包含21个关键点 |
++top_head | 是 | object | 头顶 |
+++x | 是 | float | x坐标 |
+++y | 是 | float | y坐标 |
+++score | 是 | float | 概率分数 |
++left_eye | 是 | object | 左眼 |
+++x | 是 | float | x坐标 |
+++y | 是 | float | y坐标 |
+++score | 是 | float | 概率分数 |
++right_eye | 是 | object | 右眼 |
+++x | 是 | float | x坐标 |
+++y | 是 | float | y坐标 |
+++score | 是 | float | 概率分数 |
++nose | 是 | object | 鼻子 |
+++x | 是 | float | x坐标 |
+++y | 是 | float | y坐标 |
+++score | 是 | float | 概率分数 |
++left_ear | 是 | object | 左耳 |
+++x | 是 | float | x坐标 |
+++y | 是 | float | y坐标 |
+++score | 是 | float | 概率分数 |
++right_ear | 是 | object | 右耳 |
+++x | 是 | float | x坐标 |
+++y | 是 | float | y坐标 |
+++score | 是 | float | 概率分数 |
++left_mouth_corner | 是 | object | 左嘴角 |
+++x | 是 | float | x坐标 |
+++y | 是 | float | y坐标 |
+++score | 是 | float | 概率分数 |
++right_mouth_corner | 是 | object | 右嘴角 |
+++x | 是 | float | x坐标 |
+++y | 是 | float | y坐标 |
+++score | 是 | float | 概率分数 |
++neck | 是 | object | 颈部 |
+++x | 是 | float | x坐标 |
+++y | 是 | float | y坐标 |
+++score | 是 | float | 概率分数 |
++left_shoulder | 是 | object | 左肩 |
+++x | 是 | float | x坐标 |
+++y | 是 | float | y坐标 |
+++score | 是 | float | 概率分数 |
++right_shoulder | 是 | object | 右肩 |
+++x | 是 | float | x坐标 |
+++y | 是 | float | y坐标 |
+++score | 是 | float | 概率分数 |
++left_elbow | 是 | object | 左手肘 |
+++x | 是 | float | x坐标 |
+++y | 是 | float | y坐标 |
+++score | 是 | float | 概率分数 |
++right_elbow | 是 | object | 右手肘 |
+++x | 是 | float | x坐标 |
+++y | 是 | float | y坐标 |
+++score | 是 | float | 概率分数 |
++left_wrist | 是 | object | 左手腕 |
+++x | 是 | float | x坐标 |
+++y | 是 | float | y坐标 |
+++score | 是 | float | 概率分数 |
++right_wrist | 是 | object | 右手腕 |
+++x | 是 | float | x坐标 |
+++y | 是 | float | y坐标 |
+++score | 是 | float | 概率分数 |
++left_hip | 是 | object | 左髋部 |
+++x | 是 | float | x坐标 |
+++y | 是 | float | y坐标 |
+++score | 是 | float | 概率分数 |
++right_hip | 是 | object | 右髋部 |
+++x | 是 | float | x坐标 |
+++y | 是 | float | y坐标 |
+++score | 是 | float | 概率分数 |
++left_knee | 是 | object | 左膝 |
+++x | 是 | float | x坐标 |
+++y | 是 | float | y坐标 |
+++score | 是 | float | 概率分数 |
++right_knee | 是 | object | 右膝 |
+++x | 是 | float | x坐标 |
+++y | 是 | float | y坐标 |
+++score | 是 | float | 概率分数 |
++left_ankle | 是 | object | 左脚踝 |
+++x | 是 | float | x坐标 |
+++y | 是 | float | y坐标 |
+++score | 是 | float | 概率分数 |
++right_ankle | 是 | object | 右脚踝 |
+++x | 是 | float | x坐标 |
+++y | 是 | float | y坐标 |
+++score | 是 | float | 概率分数 |
+location | 是 | object | 人体坐标信息 |
++height | 是 | float | 人体区域的高度 |
++left | 是 | float | 人体区域离左边界的距离 |
++top | 是 | float | 人体区域离上边界的距离 |
++width | 是 | float | 人体区域的宽度 |
++score | 是 | float | 人体框的概率分数 |
log_id | 是 | uint64 | 唯一的log id,用于问题定位 |
还有一些其他函数:bodyAttr()函数
对于输入的一张图片(可正常解码,且长宽比适宜),检测图像中的所有人体并返回每个人体的矩形框位置,识别人体的静态属性和行为,共支持20余种属性,包括:性别、年龄阶段、衣着(含类别/颜色)、是否戴帽子、是否戴眼镜、是否背包、是否使用手机、身体朝向等。
序号 | 属性 | 接口字段 | 输出项说明 |
---|---|---|---|
1 | 性别 | gender | 男性、女性、不确定 |
2 | 年龄阶段 | age | 幼儿、青少年、青年、中年、老年、不确定 |
3 | 上身服饰 | upper_wear | 长袖、短袖、不确定 |
4 | 下身服饰 | lower_wear | 长裤、短裤、长裙、短裙、不确定 |
5 | 上身服饰颜色 | upper_color | 红、橙、黄、绿、蓝、紫、粉、黑、白、灰、棕、不确定 |
6 | 下身服饰颜色 | lower_color | 红、橙、黄、绿、蓝、紫、粉、黑、白、灰、棕、不确定 |
7 | 上身服饰纹理 | upper_wear_texture | 纯色、图案、碎花、条纹或格子、不确定 |
8 | 背包 | bag | 无背包、单肩包、双肩包、不确定 |
9 | 上身服饰细分类 | upper_wear_fg | T恤、无袖、衬衫、西装、毛衣、夹克、羽绒服、风衣、外套、不确定 |
10 | 是否戴帽子 | headwear | 无帽、普通帽、安全帽、不确定 |
11 | 是否戴眼镜 | glasses | 戴眼镜、戴墨镜、无眼镜、不确定 |
12 | 是否撑伞 | umbrella | 撑伞、无撑伞、不确定 |
13 | 是否使用手机 | cellphone | 未使用手机、使用手机、不确定 |
14 | 身体朝向 | orientation | 正面、背面、左侧面、右侧面、不确定 |
15 | 是否吸烟 | smoke | 吸烟、未吸烟、不确定 |
16 | 是否有手提物 | carrying_item | 无手提物、有手提物、不确定 |
17 | 交通工具 | vehicle | 无交通工具、骑摩托车、骑自行车、骑三轮车、不确定 |
18 | 上方截断 | upper_cut | 无上方截断、有上方截断、不确定 |
19 | 下方截断 | lower_cut | 无下方截断、有下方截断、不确定 |
20 | 遮挡 | occlusion | 无遮挡、轻度遮挡、重度遮挡、不确定 |
21 | 是否是正常人体 | is_human | 非正常人体、正常人体、不确定;正常人体:身体露出大于二分之一的人体,一般以能看到腰部肚挤眼为标准;非正常人体:严重截断、严重遮挡的人体,一般是看不到肚挤眼的,比如只有个脑袋、一条腿 |
其他函数参见:https://ai.baidu.com/docs#/BodyAnalysis-Python-SDK/top