diff --git a/.gitignore b/.gitignore index 4280df8..1a17d42 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ data/ *pyc automation/scp_config.yaml -src/ply \ No newline at end of file +src/ply +docker/director-build/* \ No newline at end of file diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..4712731 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +2.7.12 diff --git a/README.rst b/README.rst index 58bf576..94621f7 100644 --- a/README.rst +++ b/README.rst @@ -26,6 +26,23 @@ This is the quick version. If you'd prefer to go step-by-step manually, see Pip .. _Pipeline_Instructions: https://github.com/RobotLocomotion/LabelFusion/blob/master/docs/pipeline.rst +Camera intrinsic calibration +--------------------------- + +For ElasticFusion calibration, create camera.cfg file into your lcm-log folder. camera.cfg is :code:`fx fy px py` in one line. + +For render training image, edit :code:`LabelFusion/modules/labelfusion/rendertrainingimages.py` "setCameraInstrinsicsAsus" fuction. + +.. code-block:: python + + def setCameraInstrinsicsAsus(view): + principalX = 320.0 + principalY = 240.0 + focalLength = 617.0 # fx = fy = focalLength + setCameraIntrinsics(view, principalX, principalY, focalLength) + + + Collect raw data from Xtion --------------------------- @@ -44,6 +61,64 @@ In another, run: Your data will be saved in current directory as :code:`lcmlog-*`. +Collect raw data from Realsense +--------------------------- + +First, install `librealsense `_ +, `intel_ros_relasense `_ +and `rgbd_ros_to_lcm `_ + +Second, :code:`cdlf && cd data/logs`, then make a new directory for your data. In one terminal, run: + +:: + + roscore + +In one, run: + +:: + + roslaunch realsense2_camera rs_rgbd.launch + +modify rgbd_ros_to_lcm topic: +modify this file ~/catkin_ws/src/rgbd_ros_to_lcm/launch/lcm_republisher.launch to + +.. code-block:: + + + + + + # input parameters + subscribe_point_cloud: false + rgb_topic: /camera/color/image_raw + depth_topic: /camera/aligned_depth_to_color/image_raw + cloud_topic: /camera/depth_registered/points + + # output parameters + output_lcm_channel: "OPENNI_FRAME" + compress_rgb: true + compress_depth: true + + debug_print_statements: true + + + + +and run + +:: + + roslaunch rgbd_ros_to_lcm lcm_republisher.launch + +In another, run: + +:: + + lcm-logger + +Your data will be saved in current directory as :code:`lcmlog-*`. + Process into labeled training data ---------------------------------- diff --git a/docker/compile_all.sh b/docker/compile_all.sh deleted file mode 100755 index ded201e..0000000 --- a/docker/compile_all.sh +++ /dev/null @@ -1,89 +0,0 @@ -#!/bin/bash -# -# This script is run by the dockerfile during the docker build. -# - -set -exu - -root_dir=$(pwd) -install_dir=$root_dir/install - -build_director() -{ - cd $root_dir - git clone https://github.com/RobotLocomotion/director.git - cd director - git remote add pf https://github.com/peteflorence/director.git - git fetch pf - git checkout pf/corl-master - cd .. - - mkdir director-build - cd director-build - - cmake ../director/distro/superbuild \ - -DUSE_EXTERNAL_INSTALL:BOOL=ON \ - -DUSE_DRAKE:BOOL=OFF \ - -DUSE_LCM:BOOL=ON \ - -DUSE_LIBBOT:BOOL=ON \ - -DUSE_SYSTEM_EIGEN:BOOL=ON \ - -DUSE_SYSTEM_LCM:BOOL=OFF \ - -DUSE_SYSTEM_LIBBOT:BOOL=OFF \ - -DUSE_SYSTEM_VTK:BOOL=ON \ - -DUSE_PCL:BOOL=ON \ - -DUSE_APRILTAGS:BOOL=ON \ - -DUSE_KINECT:BOOL=ON \ - -DCMAKE_INSTALL_PREFIX:PATH=$install_dir \ - -DCMAKE_BUILD_TYPE:STRING=Release - - make -j$(nproc) - - # cleanup to make the docker image smaller - cd .. - rm -rf director-build -} - -build_elasticfusion() -{ - cd $root_dir - git clone https://github.com/peteflorence/ElasticFusion.git - cd ElasticFusion - git checkout pf-lm-debug-jpeg - - git clone https://github.com/stevenlovegrove/Pangolin.git - cd Pangolin - mkdir build - cd build - cmake ../ -DAVFORMAT_INCLUDE_DIR="" -DCPP11_NO_BOOST=ON - make -j$(nproc) - cd ../.. - - export CMAKE_PREFIX_PATH=$install_dir - cd Core - mkdir build - cd build - cmake ../src - make -j$(nproc) - - cd ../../GPUTest - mkdir build - cd build - cmake ../src - make -j$(nproc) - - cd ../../GUI - mkdir build - cd build - cmake ../src - make -j$(nproc) - - ln -s $(pwd)/ElasticFusion $install_dir/bin - - # cleanup to make the docker image smaller - cd ../.. - find . -name \*.o | xargs rm -} - - -build_director -build_elasticfusion diff --git a/docker/config.sh b/docker/config.sh new file mode 100644 index 0000000..ddaad2a --- /dev/null +++ b/docker/config.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# +# This script define the name of the labelfusion docker image. +# + +#image_name=robotlocomotion/labelfusion:latest +image_name=ianre657/labelfusion:16.04-latetest \ No newline at end of file diff --git a/docker/docker_build.sh b/docker/docker_build.sh index c7413ac..d4c474e 100755 --- a/docker/docker_build.sh +++ b/docker/docker_build.sh @@ -4,9 +4,11 @@ # set -exu +source ./config.sh root_dir=$(cd $(dirname $0)/../ && pwd) -tag_name=robotlocomotion/labelfusion:test - -docker build -f $root_dir/docker/labelfusion.dockerfile -t ${tag_name} $root_dir/docker +docker build \ + -f $root_dir/docker/labelfusion.dockerfile \ + -t ${image_name} \ + $root_dir/docker diff --git a/docker/docker_run.sh b/docker/docker_run.sh index b29f5fc..a6af3c3 100755 --- a/docker/docker_run.sh +++ b/docker/docker_run.sh @@ -2,17 +2,15 @@ # # Usage: ./docker_run.sh [/path/to/data] # -# This script calls `nvidia-docker run` to start the labelfusion -# container with an interactive bash session. This script sets -# the required environment variables and mounts the labelfusion -# source directory as a volume in the docker container. If the -# path to a data directory is given then the data directory is -# also mounted as a volume. +# This script calls `docker` with `nvidia-docker2 runtime` to start the +# labelfusion container with an interactive bash session. This script +# sets the required environment variables and mounts the labelfusion +# source directory as a volume in the docker container. If the path +# to a data directory is given then the data directory is also mounted +# as a volume. # -image_name=robotlocomotion/labelfusion:latest - - +source ./config.sh source_dir=$(cd $(dirname $0)/.. && pwd) if [ ! -z "$1" ]; then @@ -26,6 +24,15 @@ if [ ! -z "$1" ]; then data_mount_arg="-v $data_dir:/root/labelfusion/data" fi -xhost +local:root; -nvidia-docker run -it -e DISPLAY -e QT_X11_NO_MITSHM=1 -v /tmp/.X11-unix:/tmp/.X11-unix:rw -v $source_dir:/root/labelfusion $data_mount_arg --privileged -v /dev/bus/usb:/dev/bus/usb $image_name -xhost -local:root; +xhost + +docker run -it \ + --rm \ + --runtime=nvidia \ + -e DISPLAY \ + --privileged \ + -e QT_X11_NO_MITSHM=1 \ + -v /tmp/.X11-unix:/tmp/.X11-unix:rw \ + -v $source_dir:/root/labelfusion $data_mount_arg \ + -v /dev/bus/usb:/dev/bus/usb \ + $image_name +xhost - diff --git a/docker/install_dependencies.sh b/docker/install_dependencies.sh deleted file mode 100755 index 6a7c819..0000000 --- a/docker/install_dependencies.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash -# -# This script is run by the dockerfile during the docker build. -# - -set -ex - -apt-get update - -apt-get install -y \ - bash-completion \ - build-essential \ - cmake \ - freeglut3-dev \ - git \ - libboost-all-dev \ - libglew-dev \ - libjpeg-dev \ - libeigen3-dev \ - libopencv-dev \ - libopenni2-dev \ - libqhull-dev \ - libqt4-dev \ - libqwt-dev \ - libsuitesparse-dev \ - libudev-dev \ - libusb-1.0-0-dev \ - libvtk5-dev \ - libvtk5-qt4-dev \ - mesa-utils \ - openjdk-8-jdk \ - zlib1g-dev \ - libyaml-cpp-dev \ - python-dev \ - python-matplotlib \ - python-numpy \ - python-pip \ - python-scipy \ - python-vtk \ - python-yaml \ - sudo - - - # optional cleanup to make the docker image smaller - # rm -rf /var/lib/apt/lists/* diff --git a/docker/labelfusion.dockerfile b/docker/labelfusion.dockerfile old mode 100644 new mode 100755 index 1de14fa..b1e5ce5 --- a/docker/labelfusion.dockerfile +++ b/docker/labelfusion.dockerfile @@ -1,11 +1,108 @@ -FROM nvidia/cuda:8.0-devel-ubuntu16.04 +FROM ianre657/cuda8gl:latetest WORKDIR /root -COPY install_dependencies.sh /tmp -RUN /tmp/install_dependencies.sh +#COPY build_scripts /tmp/build_scripts -COPY compile_all.sh /tmp -RUN /tmp/compile_all.sh +RUN apt-get update && apt-get upgrade -y +# install_dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + apt-utils \ + && apt-get install -y --no-install-recommends \ + \ + # basic packages + sudo git bash-completion lsb-core wget software-properties-common \ + \ + # for debugging + \ + cmake-curses-gui vim apt-file \ + && apt-file update \ + \ + \ && apt-get update && apt-get install -y --no-install-recommends \ + # vtk5 with qt4 + qt4-default qt4-dev-tools libqt4-opengl-dev libqt4-dev libgl1-mesa-dev \ + libglu1-mesa-dev freeglut3-dev libvtk-java openjdk-8-jdk \ + \ + # dependency for Director + build-essential cmake libglib2.0-dev libqt4-dev \ + libx11-dev libxext-dev libxt-dev \ + python-dev python-pip python-lxml python-numpy python-scipy python-yaml python-vtk python-matplotlib \ + libvtk5-qt4-dev libvtk5-dev \ + libqwt-dev openjdk-8-jdk qtbase5-private-dev \ + libboost-all-dev libeigen3-dev liblua5.2-dev libyaml-cpp-dev libopencv-dev libqhull-dev \ + \ + # dependency for ElasticFusion + git libsuitesparse-dev cmake-qt-gui build-essential libusb-1.0-0-dev libudev-dev \ + freeglut3-dev libglew-dev libeigen3-dev zlib1g-dev libjpeg-dev libopenni2-dev \ + gcc-5 g++-5 -ENTRYPOINT bash -c "source /root/labelfusion/docker/docker_startup.sh && /bin/bash" + +# fix some path issue +RUN ln -sf /usr/include/eigen3/Eigen /usr/include/Eigen && \ + ln -sf /usr/include/eigen3/unsupported /usr/include/unsupported && \ + ln -s /usr/lib/python2.7/dist-packages/vtk/libvtkRenderingPythonTkWidgets.x86_64-linux-gnu.so /usr/lib/x86_64-linux-gnu/libvtkRenderingPythonTkWidgets.so && \ + ln -s /usr/local/cuda-8.0 /usr/local/cuda + + +# compile director +#RUN /tmp/build_scripts/compile_director.sh +RUN git clone -b labelFusion-director https://github.com/ianre657/director.git \ + && mkdir director-build && cd director-build \ + && cmake ../director/distro/superbuild \ + -DUSE_EXTERNAL_INSTALL:BOOL=ON \ + -DUSE_DRAKE:BOOL=OFF \ + -DUSE_LCM:BOOL=ON \ + -DUSE_LIBBOT:BOOL=ON \ + -DUSE_SYSTEM_EIGEN:BOOL=ON \ + -DUSE_SYSTEM_LCM:BOOL=OFF \ + -DUSE_SYSTEM_LIBBOT:BOOL=OFF \ + -DUSE_SYSTEM_VTK:BOOL=ON \ + -DUSE_PCL:BOOL=ON \ + -DUSE_APRILTAGS:BOOL=OFF \ + -DUSE_KINECT:BOOL=ON \ + -DCMAKE_INSTALL_PREFIX:PATH=/root/install \ + -DCMAKE_BUILD_TYPE:STRING=Release \ + -DDD_QT_VERSION:STRING=4 \ + && make -j"$(nproc)" -l"$(nproc)" \ + #cleanup to make the docker image smaller + && cd .. && rm -rf director-build + +# compile elasticfusion +#RUN /tmp/build_scripts/compile_elasticfusion.sh +ARG root_dir=/root +ARG install_dir=/root/install +RUN git clone -b pf-lm-debug-jpeg https://github.com/ianre657/ElasticFusion.git \ + && cd ElasticFusion \ + \ + # Build Pangolin + && git clone https://github.com/stevenlovegrove/Pangolin.git && cd Pangolin \ + && mkdir build && cd build \ + && cmake ../ -DAVFORMAT_INCLUDE_DIR="" -DCPP11_NO_BOOST=ON \ + && make -j$(nproc) -l$(nproc) \ + && cd ../.. \ + \ + # Build Elasticfusion + && export CMAKE_PREFIX_PATH=$install_dir \ + && cd Core \ + && mkdir build && cd build \ + && cmake ../src \ + && make -j$(nproc) -l$(nproc) \ + && cd ../.. \ + && cd GPUTest \ + && mkdir build && cd build \ + && cmake ../src \ + && make -j$(nproc) -l$(nproc) \ + && cd ../.. \ + && cd GUI \ + && mkdir build && cd build \ + && cmake ../src \ + && make -j$(nproc) -l$(nproc) \ + && cd ../.. \ + && ln -s /root/ElasticFusion/GUI/build/ElasticFusion $install_dir/bin \ + \ + # cleanup to make the docker image smaller + && find . -name \*.o | xargs rm + + +RUN rm -rf /var/lib/apt/lists/* +ENTRYPOINT bash -c "source /root/labelfusion/docker/docker_startup.sh && /bin/bash" \ No newline at end of file diff --git a/scripts/prepareForObjectAlignment.py b/scripts/prepareForObjectAlignment.py index c2dc6ec..0f58680 100644 --- a/scripts/prepareForObjectAlignment.py +++ b/scripts/prepareForObjectAlignment.py @@ -34,7 +34,10 @@ lcmlog_filename = dataMap["lcmlog"] # call ElasticFusion -os.system(path_to_ElasticFusion_executable + " -l ./" + lcmlog_filename) +cameraConfig_arg = "" +if os.path.isfile("camera.cfg"): + cameraConfig_arg += " -cal camera.cfg" +os.system(path_to_ElasticFusion_executable + " -l ./" + lcmlog_filename + cameraConfig_arg) # rename posegraph # TODO: give error if multiple posegraph files