ANYbotics / grid_map

Universal grid map library for mobile robotic mapping
BSD 3-Clause "New" or "Revised" License
2.67k stars 806 forks source link

Improving Performance of GridMapCvConverter::toImage and addLayerFromImage on large grids #359

Open rooshm opened 2 years ago

rooshm commented 2 years ago

on a 501x501 gridmap, the toImage function takes about 200ms on an i7-8700 CPU. Same is true for the addLayerFromImage for the same. I need to perform a behaviour similar to the one illustrated in the opencv_demo, using OpenCV's functions to perform manipulations on a layer and save as another layer. Setting the geometry of the map in the opencv_demo_node as map.setGeometry(Length(5, 5), 0.01); replicates the performance.

On a look at the source code, the iterators can be parallelised with TBB (as used in in grid_map_filters), which upped my performance to 40 ms or so, but even more advantage is gained by the use of <opencv2/core/eigen.hpp> eigen2cv and cv2eigen functions, with performance in the order of 5 ms or so. This leverages that grid_map::Matrix is a typedef of eigen:Matrix. I'd be happy to submit a pull request either way.

maximilianwulf commented 2 years ago

eigen2cv and cv2eigen functions, with performance in the order of 5 ms or so. This leverages that grid_map::Matrix is a typedef of eigen:Matrix. I'd be happy to submit a pull request either way.

A new overloaded function?

But I agree eigen will do it much more efficiently thanks to vectorization.