Visualize 3d humans' skeletons(body+hands) in ros rviz. The 2d joints are detected by openpose; The depth is from depth image.
rosopenposergbd ================================== Combine Openpose 2D detection results and depth image to obtain human 3D joint positions, and draw in ROS rviz.
Demo: (Body only; 12 fps; Kind of good.) 
Demo: (Body+hand; 3 fps; Inaccurate hands' 3D positions.) 
Contents:
* 3.1. Unittest + 3.1.1. libopenposedetector.py + 3.1.2. libdraw3d_joints.py * 3.2. Test Data from Disk * 3.3. Test Data from ROS Topic * 3.4. Test Data from Realsense * 4.1. Speed * 4.2. Accuracy * 5.1. Helper Tools * 5.2. Noisy Realsense * 5.3. Bugs1. Introduction
Algorithm: The workflow is:
- Detect 2D human joints from color image by Openpose.
- Compute joints' 3D positions by getting the depth from depth image.
- Visualize them in rviz by ROS markers.
Data: See data/imagei1 and data/imagesn40.
Joints' format: I'm using COCO model for body detection. See this page, and the picture of body and hand.
Example of usage: Check the arguments by rosrun rosopenposergbd detectanddraw_joints.py -h. Read Section 3. Usage for more details.
2. Installation
Environment: Ubuntu 18.04, ROS melodic, python2.
Install some common python libraries:
pip2 install --user open3d
Openpose: First, install Openpose by following its very detailed and very long official tutorial. Please also compile its code into Python2 libraries. Tutorial is here.
The major (not complete) steps are listed below:
cd ~/githubs git clone https://github.com/CMU-Perceptual-Computing-Lab/openpose; cd openpose mkdir -p build; cd build cmake -DBUILD_PYTHON=ON \ -DPYTHON_EXECUTABLE=/usr/bin/python2.7 \ -DPYTHONLIBRARY=/usr/lib/x8664-linux-gnu/libpython2.7m.so .. make -j11 sudo make install # Install c++/python libraries to /usr/local/python.
After installation, check the environment variable OPENPOSEHOME. We will need to read model from ${OPENPOSEHOME}/models/.
echo "'${OPENPOSE_HOME}' should be the folder of your openpose."
Make sure you can run its example
cd ${OPENPOSEHOME}/build/examples/tutorialapi_python python 04keypointsfrom_images.py
Set the environment variable OPENPOSE_PYTHONPATH as the installation directory of openpose python libraries. It's probably /usr/local/python.
export OPENPOSE_PYTH
3. Usage
3.1. Unittest
3.1.1. libopenposedetector.py
python libopenposedetector.py
This test case reads a color image from data/imagei1/color/, detect the human joints, and then ouputs the results to output/.
3.1.2. libdraw3d_joints.py
python libdraw3d_joints.py
roslaunch rosopenposergbd run_rviz.launch
This test case reads the 2D joints and image from data/image_i1/, computes the 3D joint positions, and then draw the joints in rviz.
3.2. Test Data from Disk
DATA="data/images_n40/"
rosrun rosopenposergbd detectanddraw_joints.py \
--data_source disk \
--basefolder $(rospack find rosopenpose_rgbd) \
--folder_color $DATA/color \
--folder_depth $DATA/depth \
--camerainfofile $DATA/camparamsrealsense.json \
--detect_hand true # true or false
roslaunch rosopenposergbd run_rviz.launch
3.3. Test Data from ROS Topic
Please download the color/depth images pulisher:
ROOT=$(rospack find rosopenposergbd) cd ${ROOT}/.. # cd to ~/catkin_ws/src/ folder. if [ ! -d "rospubandsubrgbdandcloud" ]; then repo="https://github.com/felixchenfy/rospubandsubrgbdandcloud" git clone ${repo} cd rospubandsubrgbdandcloud chmod a+x pubrgbdand_cloud.py fi
OK. Now publish data, and start detection and drawing:
roslaunch rosopenposergbd publishtestrgbd_data.launch
rosrun rosopenposergbd detectanddraw_joints.py \
--data_source rostopic \
--rostopiccolor camera/color/image_raw \
--rostopicdepth camera/aligneddepthtocolor/imageraw \
--rostopiccamerainfo camera/color/camerainfo \
--detect_hand true # true or false
The publish rate is set as 1 image/second. Please read launch/publishtestrgbddata.launch, and change publish settings in config/publishtestrgbddataconfig.yaml.
3.4. Test Data from Realsense
In 3.3, the data is read from disk and published to ROS topics. Here we read it from Realsense D435.
roslaunch rosopenposergbd run_realsense.launch
rosrun rosopenposergbd detectanddraw_joints.py \
--data_source rostopic \
--isusingrealsense true \
--detect_hand false # My laptop is not fast enough to detect hand.
4.Results
4.1. Speed
Running speed of the main program detectanddraw_joints.py is:
- Settings: RTX 2070; Image resize to 320x240.
- Results:
4.2. Accuracy
See the two gif at the top of this README.- The 3D body joints are not too bad, but still has some "trembling" even if I'm standing still.
- The 3D hand joints are awful.
Besides the above problem, the Realsense also doesn't work well as expected. The measured depth value becomes inaccurate when the object is 1 meter away. I didn't do the experiment, but I feel it's about 1cm error at 1 meter, and up to 10cm when the object is several meters away (Let's say 4 meters). Also, the depth is fluctuating noticeably for distant objects, which can even be noticed from depth image.
5. Others
5.1. Helper Tools
- Draw point cloud of color/depth image.
python scripts/drawpointcloud.py -h
You can directly run it and see the point cloud of data/image_i1.
- Record color/depth images to disk.
- Publish color/depth images.
5.2. Noisy Realsense
Below are two screenshots of the point cloud of data/image_i1 taken from different angles. You can see that it's very noisy.
When I recorded this data, I forgot to turn on Realsense's spacial and temporal filtering of the point cloud. I tried it later, but the result was still bad.
5.3. Bugs
- The ROS marker
deletefunction sometimes doesn't work. I can't solve it right now, maybe you need to close rviz and open it again in order to clear the ROS markers. The corresponding delete function is defined in utils/librvizmarker.py anddef deletemarker.