Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export tool memory optimization #1391

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

matlabbe
Copy link
Member

@matlabbe matlabbe commented Nov 24, 2024

Refactoring:

New options:

--opt #               Optimization approach:
                            0=Iterative Global Optimization (default)
                            1=Full Global Optimization
                            2=Use optimized poses already computed in the database instead
                              of re-computing them (fallback to default if optimized poses don't exist).
                            3=No optimization, use odometry poses directly.
--density_radius #    Filter poses in a fixed radius (m) to keep only one to be exported in the assembled cloud.
--density_angle #     Filter poses up to angle (deg) in the --density_radius.

Example the export a large map in multiple files.

  1. Make sure the database has optimized poses saved in the database with:
rtabmap-export --poses --save_in_db rtabmap.db
Opening database "rtabmap.db"...
Opening database "rtabmap.db"... done (0.000244s).
Optimizing the map (Iterative global optimization)...
Optimizing the map (Iterative global optimization)... done (6.975819s, poses=85934).
Saved 85934 poses to database! (min=[-105.723869,-15.019793,-2.311474] max=[167.144485,251.769775,14.714050])
  1. Look at the min/max of the poses, we will use them to adjust the ranges in that script:
#!/bin/bash

# Define ranges
min_x=-110
max_x=170
min_y=-20
max_y=260

divide=4

if [ $# -ne 1 ]; then
  echo "Usage: $0 DATABASE_PATH"
  exit
fi

database_path=$1

interval_x=$(( (max_x - min_x) / divide ))
interval_y=$(( (max_y - min_y) / divide ))

echo "min_x=$min_x max_x=$max_x interval=$interval_x meters"
echo "min_y=$min_y max_y=$max_y interval=$interval_y meters"

db_name=$(basename "$database_path")
db_name="${db_name%.*}"
        
for (( x=$min_x; x<$max_x; x+=$interval_x )); do
    for (( y=$min_y; y<$max_y; y+=$interval_y )); do
        x_end=$(( x + interval_x ))
        y_end=$(( y + interval_y ))
        echo "Export Range x=($min_x, $x_end) y=($min_y, $y_end)..."
        output_name=${db_name}_${x}_${x_end}_${y}_${y_end}
        rtabmap-export --cloud --xmin $x --xmax $x_end --ymin $y --ymax $y_end --voxel 0.05 --decimation 4 --ascii --opt 2 --output $output_name $database_path
    done
done

The script uses --opt 2 to make sure we use always the same poses between the exports. The resulting files would look like this with the ranges in the file name:

rtabmap_-110_-40_-20_50_cloud.ply
rtabmap_-110_-40_120_190_cloud.ply

rtabmap_-40_30_-20_50_cloud.ply
rtabmap_-40_30_50_120_cloud.ply
rtabmap_-40_30_120_190_cloud.ply
rtabmap_-40_30_190_260_cloud.ply

rtabmap_30_100_-20_50_cloud.ply 
rtabmap_30_100_50_120_cloud.ply
rtabmap_30_100_120_190_cloud.ply
rtabmap_30_100_190_260_cloud.ply
    
rtabmap_100_170_50_120_cloud.ply  
rtabmap_100_170_120_190_cloud.ply      
rtabmap_100_170_190_260_cloud.ply

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant