ANYbotics / grid_map

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

Grid Map projection to a color image #271

Closed brunoeducsantos closed 3 years ago

brunoeducsantos commented 3 years ago

Hi,

I was trying to project a grid map keeping the colors to a image like this:

cv::Mat map; GridMapCvConverter::toImage<unsigned char,3>(gridMap, layer, CV_16UC3,map);

Although, I am getting a mix of gray and yellow colors. test Could you help me with this issue?

Thanks, Bruno

maximilianwulf commented 3 years ago

Hey @brunoeducsantos, the function does not directly generate a colorful image. Your output is expected.

In case you want a color map, you have to apply a color map to the image.

This snippet should roughly do what you want:

       // Holds the colormap version of the image:
        Mat cm_img0;
        // Apply the colormap:
        applyColorMap(img0, cm_img0, COLORMAP_JET);
        // Show the result:
        imshow("cm_img0", cm_img0);
        waitKey(0);

Inspired by this stackoverflow thread: https://stackoverflow.com/questions/13840013/opencv-how-to-visualize-a-depth-image

Hope that answers your question.

brunoeducsantos commented 3 years ago

Thanks for your hint. I will try it out and let you know.

brunoeducsantos commented 3 years ago

@maximilianwulf It worked like a charm. Thanks a lot!

maximilianwulf commented 3 years ago

Glad to hear.