Skip to content

Latest commit

 

History

History
81 lines (66 loc) · 3.51 KB

README.md

File metadata and controls

81 lines (66 loc) · 3.51 KB

center-line-fitting

Takes track images output by SLAM and outputs points along the center-line in a csv file.

image

Prerequisites

Get track image and info files from Cartographer or some other SLAM tool. The image file should be in pgm format and the info file should be in yaml format. Here is an example track pgm and yaml combination:

track.pgm

image

track.yaml
image: track.pgm
resolution: 0.050000
origin: [-5.659398, -4.766974, 0.000000]
negate: 0
occupied_thresh: 0.65
free_thresh: 0.196

How It Works

This center-line-fitting algorithm uses four steps:

  1. Denoise
  2. Skeletonize
  3. Prune and Order
  4. Subsample

Denoise

In this step, we run the DBSCAN clustering algorithm on the image twice. The first time, we run it on the positive space and keep only the pixels from the largest cluster. The second time, we run it on the negative space and keep only the pixels from the two largest clusters.

Denoised Image:

image

Skeletonize

Next we run Zhang's Skeletonize algorithm on the image. Here is the output of "Skeletonize" overlayed over the denoised image:

Skeletonized Image:

image

Prune

Next we use a Depth First Search to try to find a large cycle in graph defined by adjacent pixels in the image. We remove all pixels that do not fall along the cycle. Not only does pruning remove extra branches in the skeleton, it gives us an ordering of the pixels that goes around the track. Here is the output of "Pruning" overlayed over the denoised image:

Pruned Image:

image

Subsample

Finally, we subsample pixels along the cycle we came up with. Basically, if the x is the subsample period, we keep every xth pixel on the cycle. The result with subsample period 6 looks like this:

Subsampled Image:

image

Usage

Clone the repository and run the center-line-fitting script:

git clone https://github.com/mlab-upenn/center-line-fitting.git
cd center-line-fitting
python src/fit_centerline.py

Plots

To control the plots that are displayed, use

python center-line-fitting.py --plot_mode <0, 1, or 2>

0 shows no plots, 1 (default) shows basic plots, and 2 shows all plots

I/O

You can specify the input file paths and output directory using the command line:

python center-line-fitting.py --pgm_path <path to track image> --yaml_path <path to track info> --out_dir <path to output directory>

Subsampling Period

You can change the subsampling period as follows:

python center-line-fitting.py --subsample_period 20

This changes how sparesly the points are sampled from the center-line path

subsample_period = 20

image

subsample_period = 6

image