grid_map icon indicating copy to clipboard operation
grid_map copied to clipboard

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

Open rooshm opened this issue 2 years ago • 1 comments

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.

rooshm avatar Jun 27 '22 10:06 rooshm

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.

maximilianwulf avatar Jul 04 '22 07:07 maximilianwulf