costar_stack

Integrated ROS capabilities for planning, predicate inference, gripper control, and perception for use with the KUKA LBR IIWA and Universal Robots.

View the Project on GitHub cpaxton/costar_stack

SP Segmenter

Thank you for your interest at our semantic segmentation software.

This software implements a modified version of the algorithm described in the papers:

If you find this software useful, please site the aforementioned papers above in any resulting publication.

This software repository is maintained by:

Prerequisites

Code has all been developed and tested with Ubuntu 14.04 / OSX 10.11.x and ROS Indigo. You will need OpenCV 2.4 and OpenCV nonfree.

If you’re using standard opencv2 library from ros, you may be able to install the nonfree with:

sudo add-apt-repository --yes ppa:xqms/opencv-nonfree
sudo apt-get update 
sudo apt-get install libopencv-nonfree-dev

If you receive errors compiling sp_segmenter because of include problem in opencv nonfree headers, uninstall the nonfree package from the apt-get and build opencv2 by yourself with these commands:

git clone https://github.com/opencv/opencv.git
cd opencv
git checkout 2.4.13.2
mkdir build
cd build
cmake ..
make -j4
sudo make install

If you want to build the code with pose estimation, you will need to build and install ObjRecRANSAC:

git clone https://github.com/jhu-lcsr/ObjRecRANSAC
cd ObjRecRANSAC
mkdir build
cmake ..
make -j4
sudo make install

To run this code you need:

Training Model

Application for training:

main_sp_compact

This has the training script that loads a library that figures out how to separate the different objects you wish to recognize. Put the different object names in different folders as documented in the list of folders.

This training code will perform feature extraction including LAB, FPFH, and SIFT features. You can choose which of these to use for SVM learning. These features are all saved to a sparse matrix for the provided data set. When doing SVM training, you choose the features.

SVM learning is done in main_sp_svm.cpp.

Training data is in seperate folders, one for each class. For example:

.
├── costar_link
├── costar_node
├── fea_pool
├── gripper
├── link
├── link_node
├── node
├── sander
├── svm_pool
└── UR5

10 directories

Here, “link”, “node”, and “sander” are classes, and “UR5” is background data.

Example execution for data in ~/data/primesense:

roslaunch sp_segmenter SPCompact.launch training_folder:=$HOME/data/primesense object:=link,node,sander bg_names:=UR5
roslaunch sp_segmenter SPCompact.launch object:=link,node,sander training_folder:=$HOME/data/primesense bg_sample_num:=100 obj_sasmple_num:=30

We use bg_sample_num to set the number of samples drawn from each negative training data (background data), and obj_sample_num to determine the number of samples drawn from each foreground (object) partial view.

handling recognizing specific objects

Objects are divided into “classes” drill, hammer, cube, rod.

Two sections in main for training:

float CC foregroundBackgroundCC binary cc, “C” parameter in SVM algorithm (see papers on Support Vector Machines) this is the weight/cost of misclassifying objects in training data.

parameters:

obj_sample_num, bg_sample_num

Data is resampled in the algorithm so it is important that the weights of the data being classified is appropriate. Therefore it is important to set the number of samples in foreground and the background.

The total number of background data should be equal to the total number of the background data. We randomly sample patches

Example:

A is foreground B is background

relationship between foreground and background should be the following for obj_samplenum and bg_sample_num:

numObjectTrainingDataObjSamples = numBackgroundTrainingDataNumBackgroundSamples

Note that there is only one foreground and one background class, so the foreground data consists of all foreground data.

Feature scales

CSHOT features work on a scale defined at training time. This must be kept constant from training through to the runtime of your algorithm. Scale is very important because if it is too small it will see part of an object and not get information about larger scales, and if it is too large it will it will run slower and it won’t get useful information about the boundaries of objects.

Numbering classes

There are two occasions classification occurs. First in an optional “binary classification” that separates foreground data you care about from background you aren’t worrying about.

After foreground and background are separated, each class of “foreground” data needs to be seaparted with a multi class SVM as “drill”, “wood_block”, or “sander” needs to be classified. Each of these classes needs to be assigned a class id number.

Assign class ids like the following 4 class example:

  1. background
  2. drill
  3. wood_block
  4. sander

Training using roslaunch

How to train using roslaunch:

roslaunch sp_segmenter SPCompact.launch object:=object1,object2,object3 bg_names:=background1,background2,background3

By default, this will read all pcd files in the $(find sp_segmenter)/data/training/(object OR background folder) for every object and background that being passed to roslaunch. Separate every object/background name with ,

Args list:

Executing

How to run the code (with the default SVM):

rosrun sp_segmenter SPSegmenterServer

You need to run this from the root of the directory right now.

By default, the segmenter node listens to the /camera/depth_registered/points topic and publishes its output on the points_out topic. You can remap these on the command line to deal with different sources.

Execute using roslaunch

How to run using roslaunch:

roslaunch sp_segmenter SPSegmenter.launch

By default, this roslaunch is exactly the same as rosrun sp_segmenter SPSegmenterNode -p except that it can be run without the need to be on the root of sp_segmenter directory. The data folder in default is located in "$(find sp_segmenter)/data/", and can be modified by changing parameters.launch.

It is possible to pass some arguments to set the object type, input point cloud topic, the segmenter outputs, and some additional parameters that is used by the segmenter. See launch/SPServer.launch for more ros parameters that can be costumized.

Args list:

Example:

roslaunch sp_segmenter SPServer.launch object:=mallet_ball_pein pcl_in:=/kinect_head/qhd/points

After one service call, it will constantly publishes TF frames. The object TF naming convension generated from SPServer is: Obj_<the name of object>_<objectIndex>.

Example (to update the TF frames):

rosservice call /SPServer/SPSegmenter

To segment grabbed object on the gripper and update a particular object TF (in this case: Obj::link_uniform::1) :

rosservice call /SPServer/segmentInGripper Obj::link_uniform::1 link_uniform

debugging

There are several facilities for debugging both the runtime execution performance of sp_segmenter and the detection/pose estimation performance.

To view detection, set the visualization flag to true with

roslaunch sp_segmenter SPServerNode.launch visualization:=true

Python Binding

In addition to using ros for training and doing semantic segmentation, we can also uses python.

We provided a sample code for training in python_binding/sample_training.py and a sample code for semantic segmentation in python_binding/sample_segmentation.py

SpCompact parameters

SpCompact is our main library we use for generating svm model. There are various parameters that can be set for SpCompact:

SemanticSegmentation parameters

SemanticSegmentation is our main library we use for labeling point cloud and possibly calculating object poses if ObjRecRANSAC is used. It contains various parameters that can be costumized to suit user’s specific needs.

Main parameters that needs to be set for point cloud classification:

Optional parameters for modifying point cloud before doing classification with SVM model:

The point cloud modification is processed in this following order: Raw point cloud -> Crop boxed point cloud -> Table segmented point cloud -> Foreground/Background SVM -> Multiclass SVM -> Object Pose computation

Main parameters that needs to be set for pose computation:

Optional parameters that can be set for pose computation: