ROS下的人体姿态识别tf-pose-estimation(tensorflow版本的openpose)
相关链接:
项目:
- tf-pose-estimation https://github.com/ildoonet/tf-pose-estimation
- tf-pose-estimation for ROS https://github.com/ildoonet/tf-pose-estimation/blob/master/etcs/ros.md
论文:tf-pose其实就是openpose的tensorflow+Python版本,openpose论文:Realtime Multi-Person 2D Pose Estimation using Part Affinity Fields
环境:
- 9代i5+1660T、ubuntu18.04
- nvidia418.74、cuda10.0.130、anaconda 4.3.0、tensorflow-gpu1.13.1
- opencv3.4.1
- TensorRT
- protobuf-3.11.1
目录
一、工作空间建立
二、openpose的独立运行
(一)图片demo
(二)相机demo
(三)视频demo
(四)运行期间终端打印关节点坐标
三、openpose的ROS下运行
(一)下载其他依赖包
(二)修改launch文件为相应的输入源
(三)catkin_make
(四)运行
1、cv_bridge依赖python2,与ROS的python3环境冲突
2、Boost接口报错
3、tensorflow、cuda报错
4、运行成功
(五)终端打印关节点坐标
四、基于骨骼点的静态姿势分类
(一)数据表示
(二)分类方法
1、基于距离和角度特征的分类思路
2、KNN
3、多分类SVM
五、人机交互无人机系统运行
(一)工程描述
(二)仿真运行过程
(三)实际工程优化
1、修改输入源为小觅相机
2、订阅压缩图,减少延时跳变
3、twist_control相关控制
4、将输入图像放大检测效果更好
5、使笔记本用电池时仍保持高性能模式
一、工作空间建立
#建立ros的workspace
mkdir -p ~/gesture_recognition/catkin_tfpose/src
cd ~/gesture_recognition/catkin_tfpose/src
catkin_init_workspace #生成catkin_tfpose/src/CMakeList.txt
cd ..
catkin_make #编译生成catkin_tfpose/build/和catkin_tfpose/devel/#创建功能包
#cd src
#catkin_create_pkg bagname std_msgs roscpp rospy #后面仨是包的依赖#下载功能包
cd src
git clone https://github.com/ildoonet/tf-pose-estimation
pip install -r tf-pose-estimation/requirements.txt
roslaunch tfpose_ros demo_video.launch
二、openpose的独立运行
只需要看单独的包,用python运行
(一)图片demo
cd ~/gesture_recognition/catkin_tfpose/src/tf_pose_estimation
python run.py --model=mobilenet_thin --resize=432x368 --image=./images/p1.jpg
1、按照gayhub,最后运行时出错:Failed to initialize TensorRT. This is either because the TensorRT installation path is not in LD_LIBRARY_PATH, or because you do not have it installed,于是安装TRT:https://zhuanlan.zhihu.com/p/165359425,仍报相同错,由issues/515,注释一行代码import tensorflow.contrib.tensorrt as trt解决。位于:
- tf_pose_estimation/tf-pose/estimator.py
- /home/muxi/anaconda3/lib/python3.6/site-packages/tf_pose-0.1.1-py3.6-linux-x86_64.egg/tf_pose/estimator.py
2、又运行又报错:E tensorflow/stream_executor/cuda/cuda_dnn.cc:334] Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR,可能是因为gpu分配出现了问题,所以我们设置config,让gpu能够正常使用。见https://blog.csdn.net/icestorm_rain/article/details/105337071开头加入以下,问题解决。
import tensorflow as tf
from tensorflow.compat.v1 import InteractiveSession
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
session = InteractiveSession(config=config)
运行成功
(二)相机demo
#python run_webcam.py --model=mobilenet_thin --resize=432x368 --camera=0
python ~/gesture_recognition/catkin_tfpose/src/tf_pose_estimation/run_webcam.py --model=mobilenet_thin --resize=432x368 --camera=0
运行报错:Cannot mix incompatible Qt library (version 0x50907) with this library (version 0x50905),意思应该是需要qt5.9.7却用了5.9.5。
当初用spyder也是一堆qt相关错,当时是动态链接库的优先级问题导致的,环境很杂,这点就很烦,其实anaconda根本不是说好的虚拟环境互不干扰那么美好啊! 于是找到qt5.9.7位置
sudo find ~ -name 'libQt*' -print
如下:
bashrc加入以下:
export LD_LIBRARY_PATH=/home/muxi/anaconda3/pkgs/qt-5.9.7-h5867ecd_1/lib:$LD_LIBRARY_PATH
搞定,帧数不错,30上下。
(三)视频demo
#python run_video.py --model=mobilenet_thin --video=/home/muxi/datasets/UAVGesture/AllClear/S1_allClear_HD.mp4
python ~/gesture_recognition/catkin_tfpose/src/tf_pose_estimation/run_video.py --model=mobilenet_thin --video=/home/muxi/datasets/UAVGesture/AllClear/S1_allClear_HD.mp4
要精度就--model=cmu,但帧率只有8左右
问题:运行出视频不显示骨架
- 方法1:run_webcam.py里50多行的cam = cv2.VideoCapture(args.camera) 改为 cam = cv2.VideoCapture('/home/muxi/datasets/UAVGesture/AllClear/S1_allClear_HD.mp4'),再运行命令python run_webcam.py --model=mobilenet_thin --resize=432x368 --camera=0,成功。
- 方法2:参考Fix 'no skeleton graph' issue in run_video.py #650,成功。
(四)运行期间终端打印关节点坐标
终端打印及可视化skeleton(骨架)keypoint坐标,参考:https://github.com/ildoonet/tf-pose-estimation/issues/619,estimator.py:
def draw_humans(npimg, humans, imgcopy=False): if imgcopy: npimg = np.copy(npimg) image_h, image_w = npimg.shape[:2] #img.shape[:2] 取彩色图片的高、宽,摄像头是480,640 print("image size:", image_h, image_w) centers = {} j = 1 for human in humans:#检测到的人的循环 # print(human.body_parts.items()) print("human", j, "of", len(humans), ":") j=j+1 # draw point for i in range(common.CocoPart.Background.value):#关键点的循环 if i not in human.body_parts.keys(): continue body_part = human.body_parts[i] center = (int(body_part.x * image_w + 0.5), int(body_part.y * image_h + 0.5)) #画图用的根据输入图像规格来的像素位置 print(" ", body_part, ", image location:", center) #BodyPart:0-(0.56, 0.20) score=0.73 centers[i] = center cv2.circle(npimg, center, 2, common.CocoColors[i], thickness=2, lineType=8, shift=0) # draw line for pair_order, pair in enumerate(common.CocoPairsRender): if pair[0] not in human.body_parts.keys() or pair[1] not in human.body_parts.keys(): continue # npimg = cv2.line(npimg, centers[pair[0]], centers[pair[1]], common.CocoColors[pair_order], 3) cv2.line(npimg, centers[pair[0]], centers[pair[1]], common.CocoColors[pair_order], 2) # draw (x,y) for i in range(common.CocoPart.Background.value): if i not in human.body_parts.keys(): continue body_part = human.body_parts[i] center = (int(body_part.x * image_w + 0.5), int(body_part.y * image_h + 0.5)) centers[i] = center text = str(i) +"(" + str(center[0]) + "," + str(center[1])+")" cv2.putText(npimg, text, (center[0], center[1]), cv2.FONT_HERSHEY_PLAIN, 0.8, (255, 255, 255), thickness=1)return npimg
三、openpose的ROS下运行
(一)下载其他依赖包
1、相机包
下载摄像头包:video_stream_opencv:https://github.com/ros-drivers/video_stream_opencv
roslaunch video_stream_opencv webcam.launch #摄像头测试正常
如果是视频文件,可以修改loop参数为true循环播放
2、ros_video_recorder : https://github.com/ildoonet/ros-video-recorder
3、image_view (有,不用下载)
(二)修改launch文件为相应的输入源
如:catkin_tfpose/src/tf-pose-estimation/launch/demo_video.launch
<arg name="video" default=default="/dev/video0" />
不修改运行的就是video的default。另外,mobilenet_thin比cmu模型低延迟。
(三)catkin_make
报错:
CMake Error at /opt/ros/melodic/share/catkin/cmake/catkin_python_setup.cmake:56 (message):
catkin_python_setup() version in setup.py (0.1.1) differs from version in
package.xml (0.1.0)
Call Stack (most recent call first):
tf-pose-estimation/CMakeLists.txt:18 (catkin_python_setup)
-- Configuring incomplete, errors occurred!
See also "/home/muxi/gesture_recognition/catkin_tfpose/build/CMakeFiles/CMakeOutput.log".
See also "/home/muxi/gesture_recognition/catkin_tfpose/build/CMakeFiles/CMakeError.log".
1、注释 zip_safe=False,没解决。https://github.com/ildoonet/tf-pose-estimation/issues/394
2、由于安装的最新的Anaconda,当前的环境的python已然变为了python3.6.5,而ROS的python依赖还是2.7有冲突。没解决。https://blog.csdn.net/wubaobao1993/article/details/80686253#commentBox
python -V
dpkg -L python-catkin-pkg
conda install setuptools
pip install -U rosdep rosinstall_generator wstool rosinstall six vcstools
3、在Ubuntu 18.0中设置python3为默认环境
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150
#查看当前存在的环境
sudo update-alternatives --list python
#如果要切换Python版本,执行并按照提示输入数字按回车即可
sudo update-alternatives --config python
然后源码安装支持python3的ros(参考:知乎:ubuntu1804安装基于Python3的ROS melodic、源码安装ROS-Melodic-Python3指南+安装记录),仍报错。
#ros的py3相关依赖包
sudo apt-get install python-catkin-tools python3-dev python3-catkin-pkg-modules python3-numpy python3-yaml ros-melodic-cv-bridge
4、后来将setup.py里面改了版本居然catkin_make就成功了。
_VERSION = '0.1.0'
唉,不该源码重装ros的。
小贴士:关于ros中的catkin_python_setup()和setup.py:
- python官方文档:https://docs.python.org/2/distutils/examples.html(某翻译:纯Python包发布setup脚本编写示例)
- ROS知识(13)----基于catkin的python包安装demo
- Python的Distutils模块
catkin_python_setup()和setup.py报错及官方说明的理解和翻译
基于python3的ros melodic源代码编译安装
(四)运行
#roslaunch video_stream_opencv webcam.launch #摄像头测试
roslaunch tfpose_ros demo_video.launch
1、cv_bridge依赖python2,与ROS的python3环境冲突
roslaunch tfpose_ros demo_video.launch报错:
File "/opt/ros/melodic/lib/python2.7/dist-packages/cv_bridge/core.py", line 91, in encoding_to_cvtype2
from cv_bridge.boost.cv_bridge_boost import getCvType
ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost)
原因是因为cv_bridg默认依赖py2与支持ros-py3的冲突,解决参考:
- https://github.com/ildoonet/tf-pose-estimation/issues/616
- Ros melodic python3环境解决cv_bridge问题
- error:cv_bridge---opencv和ros连接起来的桥
- Anaconda虚拟环境中,让Python3使用ROS的cv_bridge
(1)工作空间需要根据系统自带python版本设定。16.04是python3.5。18.04是python3.6
catkin config -DPYTHON_EXECUTABLE=/home/muxi/anaconda3/bin/python -DPYTHON_INCLUDE_DIR=/home/muxi/anaconda3/include/python3.6m -DPYTHON_LIBRARY=/home/muxi/anaconda3/lib/libpython3.6m.so
#catkin config -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so
(2)cv_bridge编译(注意切换到melodic分支,且检查其CMakeLists默认版本为python3)
git clone https://github.com/ros-perception/vision_opencv/tree/melodic
apt-cache show ros-melodic-cv-bridge | grep Version
Version: 1.13.0-0bionic.20201017.091444
(3)编译好后,自己工程使用cv_bridge要在CMakeLists.txt的find_package加入set(cv_bridge_DIR
set (OpenCV_DIR ~/opencv_cuda_anacondabase/opencv-3.4.1/build )
set(cv_bridge_DIR /usr/local/share/cv_bridge/cmake)
find_package(OpenCV REQUIRED)
并且在bashrc加入
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/
(4)使用
每次都要先运行source ~/catkin_cv_bridge/devel/setup.bash --extend,然后才可以启动相关的工作空间(如catkin_tfpose)使用到cv_bridge库的相关节点。
>>> import cv_bridge
>>> cv_bridge.__file__
'/opt/ros/melodic/lib/python2.7/dist-packages/cv_bridge/__init__.py'>>> import sys
>>> sys.path
['', '/home/muxi/catkin_cv_bridge/devel/lib/python2.7/dist-packages', '/home/muxi/gesture_recognition/catkin_tfpose/devel/lib/python2.7/dist-packages', '/opt/ros/melodic/lib/python2.7/dist-packages', '/home/muxi/anaconda3/lib/python36.zip', '/home/muxi/anaconda3/lib/python3.6', '/home/muxi/anaconda3/lib/python3.6/lib-dynload', '/home/muxi/.local/lib/python3.6/site-packages', '/home/muxi/anaconda3/lib/python3.6/site-packages', '/home/muxi/anaconda3/lib/python3.6/site-packages/tf_pose-0.1.1-py3.6-linux-x86_64.egg', '/home/muxi/anaconda3/lib/python3.6/site-packages/dill-0.2.7.1-py3.6.egg']
>>> import cv_bridge
>>> cv_bridge.__file__
'/home/muxi/catkin_cv_bridge/devel/lib/python2.7/dist-packages/cv_bridge/__init__.py'
下面的路径才对,不source找的库就是上面那段。
2、Boost接口报错
roslaunch tfpose_ros demo_video.launch报错:
File "/home/muxi/catkin_cv_bridge/src/vision_opencv-melodic/cv_bridge/python/cv_bridge/core.py", line 91, in encoding_to_cvtype2
from cv_bridge.boost.cv_bridge_boost import getCvType
ImportError: /home/muxi/catkin_cv_bridge/devel/lib/python2.7/dist-packages/cv_bridge/boost/cv_bridge_boost.so: undefined symbol: _ZN5boost6python6detail11init_moduleEPKcPFvvE
是因为没有将.so与python的结合起来,利用boost将C++写成python可以调用的库,没解决。
bashrc一定要:export ROS_PYTHON_VERSION=3,或者catkin_make --cmake-args -DPYTHON_VERSION=3.6。之前没注意吧,于是重新编译cv_bridge。解决。
3、tensorflow、cuda报错
(1)显存不够
E tensorflow/stream_executor/cuda/cuda_dnn.cc:334] Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
F tensorflow/stream_executor/lib/statusor.cc:34] Attempting to fetch value instead of handling error Internal: no supported devices found for platform CUDA
终止进程:
#每1秒更新gpu监控
watch -n 1 nvidia-smi
sudo kill -9 PID
限制显存:
#我的版本
import tensorflow as tf
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.8)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
#tensorflow2.0+版本
'''
import tensorflow as tf
config =tf.compat.v1.ConfigProto(gpu_options=tf.compat.v1.GPUOptions(allow_growth=True))
sess = tf.compat.v1.Session(config=config)
# tf.compat.v1.ConfigProto() 这是tensorflow2.0+版本的写法,这个方法的作用就是设置运行tensorflow代码的时候的一些配置,例如如何分配显存,是否打印日志等;所以它的参数都是 配置名称=True/False(默认为False) 这种形式
# gpu_options=tf.compat.v1.GPUOptions(allow_growth=True) 限制GPU资源的使用,此处allow_growth=True是动态分配显存,需要多少,申请多少,不是一成不变、而是一直变化
# sess = tf.compat.v1.Session(config=config) 让这些配置生效
'''
#更好的版本
'''
import tensorflow as tf
if tf.test.is_gpu_available(): #如果GPU可用,则指定一块GPU加速os.environ["CUDA_VISIBLE_DEVICES"] = "0" #指定第一块GPU可用 config = tf.compat.v1.ConfigProto() config.gpu_options.per_process_gpu_memory_fraction = 0.8 # 程序最多只能占用指定gpu80%的显存config.gpu_options.allow_growth=True #不全部占满显存, 按需分配sess = tf.compat.v1.Session(config=config)K.set_session(sess)
'''
(2)CPU指令集和显存
I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
W tensorflow/compiler/xla/service/platform_util.cc:240] unable to create StreamExecutor for CUDA:0: failed initializing StreamExecutor for CUDA device ordinal 0: Internal: failed call to cuDevicePrimaryCtxRetain: CUDA_ERROR_OUT_OF_MEMORY: out of memory; total memory reported: 6201933824
#gpu的测试,最后没输出True都不对
Python 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 19:07:31)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> print(tf.test.is_gpu_available())
2020-12-29 15:12:40.304121: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-12-29 15:12:40.445820: W tensorflow/compiler/xla/service/platform_util.cc:240] unable to create StreamExecutor for CUDA:0: failed initializing StreamExecutor for CUDA device ordinal 0: Internal: failed call to cuDevicePrimaryCtxRetain: CUDA_ERROR_OUT_OF_MEMORY: out of memory; total memory reported: 6201933824
2020-12-29 15:12:40.449535: F tensorflow/stream_executor/lib/statusor.cc:34] Attempting to fetch value instead of handling error Internal: no supported devices found for platform CUDA
Aborted (core dumped)
AVX2 FMA警告不用管,可设置报错输出等级:
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
4、运行成功
#roslaunch video_stream_opencv webcam.launch #摄像头测试
roslaunch tfpose_ros demo_video.launch
视频demo跑原生的需要显存3000M,内存总共被占4G;ros的需要显存5000M,内存总共被占6G。
(五)终端打印关节点坐标
不知道为何,visualization.py明明也调用了draw_humans函数,但没进入estimator.py。故修改visualization.py中的回调函数cb_pose()
def cb_pose(data): #这是个回调函数# get image with pose timet = data.header.stampimage = vf.get_latest(t, remove_older=True)if image is None:rospy.logwarn('No received images.')returnh, w = image.shape[:2]if resize_ratio > 0:image = cv2.resize(image, (int(resize_ratio*w), int(resize_ratio*h)), interpolation=cv2.INTER_LINEAR)# ros topic to Person instancehumans = []for p_idx, person in enumerate(data.persons):human = Human([])for body_part in person.body_part:part = BodyPart('', body_part.part_id, body_part.x, body_part.y, body_part.confidence)human.body_parts[body_part.part_id] = parthumans.append(human)# drawimage = TfPoseEstimator.draw_humans(image, humans, imgcopy=False)global fps_timecv2.putText(image, "FPS: %f" % (1.0 / (time.time() - fps_time)), (10, 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)fps_time = time.time()# shell printprint("FRAME START", sep='')j = 1for human in humans:#检测到的人的循环# print(human.body_parts.items())print("human", j, "of", len(humans), ":")j=j+1for i in range(common.CocoPart.Background.value):if i not in human.body_parts.keys():continueprint(" ", human.body_parts[i])print("FRAME PROCESSED", sep='')# # item is a tuple with item[0] being the ID and item[1] being class instance BodyPart# print("FRAME START", sep='')# for human in humans:# print(" human", human.body_parts.items(), sep='')# for item in human.body_parts.items():## print(" ID:", item[0], sep='')# print(" (X,Y)=(", item[1].x, ",", item[1].y,") Score=", item[1].score, sep='')# print("FRAME PROCESSED", sep='')pub_img.publish(cv_bridge.cv2_to_imgmsg(image, 'bgr8'))
四、基于骨骼点的静态姿势分类
(一)数据表示
COCO数据集定义的person类的骨骼点:
openpose的skeleton输出格式有两种标准:https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/doc/02_output.md
openpose对原版的coco模型进行了修改,原版coco有17个keypoint, OpenPose增加了一个, 用两侧肩膀生成一个中心点代表脖子,就是如下右图,编号为1的人体中心点。
也就是说本文的项目用的是openpose的格式,coco修改了的表示。
(二)分类方法
1、基于距离和角度特征的分类思路
(1)危险驾驶分类案例:Openpose人体骨骼、手势--静态图像标记及分类(附源码)https://blog.csdn.net/cungudafa/article/details/104826071
(2)太极识别案例:项目:https://blog.csdn.net/wfnian/article/details/89954740#commentBox ;论文简版https://docs.qq.com/pdf/DVFpycWd3SEttWENG
2、KNN
(1)《实践人工智能从入门到进阶》大疆特洛伊无人机Tello-Gesture-Control案例: https://github.com/RobertGCNiu/UAV-Gesture-Control_Python
(2) https://github.com/nik1806/Human-Pose-Detection
3、多分类SVM
(1)一篇paper及开源代码(matlab的),提出了UAV-GESTURE数据集并SVM分类: https://github.com/asankagp/UAV-GESTURE
(2)LIBSVM使用方法:https://blog.csdn.net/yushupan/article/details/78998128
[label] [index1]:[value1] [index2]:[value2] …
[label] [index1]:[value1] [index2]:[value2] …
目标值 第1维特征编号:第1维特征值 第2维特征编号:第2维特征值…
目标值 第1维特征编号:第1维特征值 第2维特征编号:第2维特征值…
- Label 就是说class(属于哪一类), 就是你要分类的种类,通常是一些整数。
- index 是有順序的索引,通常是连续的整数。就是指特征编号,必须按照升序排列
- value 就是特征值,用来 train 的数据,通常是一堆实数组成。
例如: 15 1:5.6 2:-3.2
表示训练用的特征有两维(index为1和2),第一维特征值是5.6,第二维是-3.2,目标值是15
像是上图那种特征表示就有17+8=25维特征。
五、人机交互无人机系统运行
(一)工程描述
整个仿真工程:
包含一个工作空间,4个功能包。只有px4bag是自己加的功能包。
整个仿真通过文件whole_sim.launch一次性启动:
roslaunch px4bag whole_sim.launch
<?xml version="1.0"?>
<launch><!--启动px4、gazebo、mavros --><include file="$(find px4)/launch/mavros_posix_sitl.launch"></include><!--tfpose:输入视频流,输出实时骨骼点 IN:xx OUT:xx --><arg name="tf_path" default="../tf_pose_estimation/launch"/><include file="$(find tfpose_ros)/$(arg tf_path)/demo_video.launch"></include><!--classify:输入骨骼点,输出分类gesture IN:xx OUT:/cmd_ges --><node pkg="px4bag" name="classify" type="classify" output="screen"/><!--posecontrol:根据实时输入的好gesture給相应方向的速度,不好的不输出 IN:/cmd_ges OUT:/cmd_vel --><node pkg="px4bag" name="posecontrol" type="posecontrol" output="screen"/><!--twist_control_node:起飞,降落,及飞行 IN:/cmd_vel OUT:飞机位置 --><node pkg="px4bag" name="twist_control_node" type="twist_control_node" output="screen"/></launch>
开一个终端输出太混乱,写成脚本一次性多开终端启动:
sh ~/gesture_recognition/catkin_tfpose/src/px4bag/sim_px4.sh
#!/bin/bash
#https://blog.csdn.net/qq_23670601/article/details/100135322#commentBoxgnome-terminal --window -e 'bash -c "roscore;exec bash"' \
--tab -e 'bash -c "sleep 2 && roslaunch px4 mavros_posix_sitl.launch;exec bash"' \
--tab -e 'bash -c "rosrun px4bag twist_control_node;exec bash"' \
--window -e 'bash -c "sleep 4 && roslaunch tfpose_ros demo_video.launch;exec bash"' \
--tab -e 'bash -c "rosrun px4bag classify;exec bash"' \
--tab -e 'bash -c "rosrun px4bag posecontrol;exec bash"'
总节点图:
三个自己写的节点:
- /classify:每帧订阅骨骼点坐标数据、每帧分类,但不是发送实时的姿势给/cmd_ges。而是,若分类为left、right、up、down、forward、backward交互指令其一,则发布一次值为对应指令的/cmd_ges,等待下次为别的姿态。若未识别则不发布/cmd_ges值。
- /posecontrol:一直订阅/cmd_ges并更新x,y,z速度,若有姿态,则对/cmd_vel发布指令对应的速度2秒实现无人机飞行,否则/twist_control_node没有收到/cmd_vel消息进入hold模式定点待命。
- /twist_control_node:注意cmd_vel_c回调函数里ros::Duration(1),这个1秒要小于连续发布运动速度的时间(2秒)。
(二)仿真运行过程
sh ~/gesture_recognition/catkin_tfpose/src/px4bag/sim_px4.sh来启动,启动的效果:
然后qq解锁起飞(忽略另一个fly1窗口):
后续,随着人做出姿势,/cmd_ges的data出现值up:
当然也可以终端直接给/cmd_vel发姿态来测试:
rostopic pub -1 /cmd_ges std_msgs/String "left" #消息发送测试
后面略。
(三)实际工程优化
1、修改输入源为小觅相机
demo_video.launch里需要去掉video_stream_recorder包提供的camera.launch,把另外三个需要订阅图像的节点所传入的参数改为相应话题/mynteye/left/image_color。
openpose节点的运行指令为:
roslaunch tfpose_ros video_mynteye.launch
2、订阅压缩图,减少延时跳变
机载NUC远程传输/mynteye/left/image_color给本机的延迟巨大,所以换用压缩的,在本机转正常图。
于是采用sensor_msgs::CompressedImageConstPtr &msg类型的/mynteye/left/image_color/compressed话题,需要写个/compressed节点,通过cv_bridge转为<sensor_msgs::Image>类型的/mynteye/left/image_color1话题。
去掉video_stream_opencv的camera.launch的前提下,直接把/mynteye/left/image_color1传给/pose_estimator等进行处理。
3、twist_control相关控制
- 注意cmd_vel_c回调函数里ros::Duration(1)
- 注意坐标设置的是全局还是机体
4、将输入图像放大检测效果更好
修改三个地方,将输入给/pose_estimator,以及显示出来的图像放大一倍,检测效果倍儿棒。
#tf_pose_estimation/scripts/broadcaster_ros.py
def callback_image(data):# et = time.time()try:cv_image = cv_bridge.imgmsg_to_cv2(data, "bgr8")cv_image =cv_image[120:360,160:480]#ros-video-recorder/scripts/recorder.py
def callback_image(self, data):try:cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8")cv_image =cv_image[120:360,160:480]#tf_pose_estimation/scripts/visualization.py
# ros topic to Person instancehumans = []for p_idx, person in enumerate(data.persons):human = Human([])for body_part in person.body_part:part = BodyPart('', body_part.part_id, body_part.x, body_part.y, body_part.confidence) #BodyPart:0-(0.61, 0.16) score=0.66part = BodyPart('', body_part.part_id, 0.25+0.5*body_part.x, 0.25+0.5*body_part.y, body_part.confidence) #BodyPart:0-(0.61, 0.16) score=0.66human.body_parts[body_part.part_id] = parthumans.append(human)
5、使笔记本用电池时仍保持高性能模式
sudo apt-get install laptop-mode-tools
sudo gedit /etc/laptop-mode/laptop-mode.conf
ENABLE_LAPTOP_MODE_ON_BATTERY=O #从1改为0,即时起效,不用source,每次拔电源都要重新改
ROS下的人体姿态识别tf-pose-estimation(tensorflow版本的openpose)相关推荐
- 3D视觉——3.人体姿态估计(Pose Estimation) 算法对比 即 效果展示——MediaPipe与OpenPose
上一话 3D视觉--2.人体姿态估计(Pose Estimation)入门--OpenPose含安装.编译.使用(单帧.实时视频)https://blog.csdn.net/XiaoyYidiaodi ...
- 人体姿态识别-pose estimation
体姿态估计(pose estimation) 即识别图像中的人体关键点(人体上有一定自由度的关节,如头.颈.肩.肘.腕.腰.膝.踝等)并正确的联系起来,通过对人体关键点在三维空间相对位置的计算,来估计 ...
- Human Pose Estimation人体姿态估计综述调研
给定一幅图像或一段视频,人体姿态估计就是去恢复其中人体关节点位置的过程. 数据集 LSP 地址:http://sam.johnson.io/research/lsp.htm 样本数:2K 关节点个数: ...
- [论文阅读:姿态识别Transformer] POET: End-to-End Trainable Multi-Instance Pose Estimation with Transformers
[论文阅读:姿态识别&Transformer] 2103 POET: End-to-End Trainable Multi-Instance Pose Estimation with Tran ...
- [论文阅读:姿态识别Transformer] TFPose: Direct Human Pose Estimation with Transformers
[论文阅读:姿态识别&Transformer] TFPose: Direct Human Pose Estimation with Transformers 文章目录 [论文阅读:姿态识别&a ...
- 姿态识别(1):DeepPose : Human Pose Estimation via Deep Neural Networks
这篇文章是使用深度学习网络处理人体关节点定位的第一篇文章,发表于2014,August 20. 作者使用了级联的卷积神经网络来预测人体关节点. 1 研究背景 人体姿态识别被定义为人体关键点的定位问题, ...
- 【2020-CVPR-3D人体姿态估计】Cascaded Deep Monocular 3D Human Pose Estimation with Evolutionary Training Data
Cascaded Deep Monocular 3D Human Pose Estimation with Evolutionary Training Data 题目:<基于进化训练数据的级联深 ...
- 姿态估计之2D人体姿态估计 - (OpenPose) Realtime Multi-Person 2D Pose Estimation using Part Affinity Fields
参见 论文翻译 || openpose _magic_ll的博客-CSDN博客 OpenPose论文解读-- 知乎 Openpose论文阅读 _jmucvm的博客-CSDN博客 openpose论文总 ...
- 姿态识别入门 DeepPose: Human Pose Estimation via Deep Neural Networks
研究背景 人体姿态识别被定义为人体关键点的定位问题,一直以来是计算机视觉领域的重要关注点.这一问题有着一些常见的挑战,比如各式各样的关节姿态,小得难以看见的关节点,遮蔽的关节点,需要根据上下文判断的关 ...
最新文章
- teamcity plugin中读取js和css文件的方法
- java写方法用来调用_Java从入门到入土(79)lambda表达式和方法引用
- 填写各类表格时有时在多个选择前有小方框 在其中打勾
- html5移动端制作知识点总结
- 『飞秋』小项目心得交流
- 冰冰讲数学鸿蒙团队4年级,冰冰也曾是水肿星人?3分钟急救方案教你甩掉晨间浮肿脸!...
- 【华为云技术分享】AI 开发路漫漫,什么才是真正的极客精神?
- Safari new Date()
- 大数据之-Hadoop3.x_MapReduce_FileInputFormat切片机制---大数据之hadoop3.x工作笔记0106
- MacBook Air 是什么意思
- apache + subversion + Windows认证
- Samba 共享目录设置在Home目录下
- 读《白话统计》笔记——第七章
- c语言调光程序,dmx512协议c语言编程
- android的listview分组显示的时候layout_marginTop失效的解决办法
- 关于微信小程序Tomcat服务器后端程序搭建
- 德国的共享杯,共享碗--还有什么不能共享?
- html+css实现轮播图
- kindeditor=4.1.5文件上传漏洞复现
- 克33+9爆利拉德阿德32分 马刺24分大胜开拓者
热门文章
- 专访易快报马春荃:建设业财税档一体化体系,是企业数字化转型的关键
- 华为IVS1800 第三方目标检测算法摄像机前端图像获取
- 来领钱了,手把手教你申报 2020 个人所得税
- 第五天:全国计算机等级考试C语言专题
- 2021年山东省职业院校技能大赛高职组“信息安全管理与评估”赛项规程
- TencentOS Server镜像操作系统评测兼容CentOS生态和操作方式
- 深度学习框架Lasagne的一些总结和技巧
- React Native搭配夜神模拟器调试(windows)
- 视频图像数据处理一:分离yuv420视频图像的y、u、v分量
- 计算机考研829包括什么,2017年广东工业大学计算机学院829数据结构考研题库