Gazebo | Ignition | Community
Ask Your Question
0

How to work with camera image

asked 2020-04-17 08:39:39 -0500

kumpakri gravatar image

updated 2020-04-17 08:40:51 -0500

I am trying to create a sensor plugin for camera sensor. Following the source code for gazebo_ros_camera plugin, I assume, that a CameraPlugin has an OnNewFrame() callback function that is called whenever the camera captures a frame. The callback function than gets the image as const unsigned char *_image. But I do not understand how to get the actual image out of this data type. I want to add some information into each frame, such as simulation time, and then save the frame into a folder. How can this be done?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-04-21 02:16:32 -0500

kumpakri gravatar image

updated 2020-04-21 02:17:35 -0500

I found one way to get the image into cv::Mat format.

#include <cv.h>

void AddSimTimeToFrame::OnNewFrame(const unsigned char *_image,
                                    unsigned int _width, 
                                    unsigned int _height, 
                                    unsigned int _depth,
                                    const std::string &_format)
{
    // must be casted to void * to trigger the correct cv::Mat constructor
    void* data = (void*)_image;
    cv::Mat img(_height, _width, CV_8UC3, data);
    // the red and blue channels are switched 
    cv::cvtColor(img, img, CV_BGR2RGB);

    // image processing
}
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-04-17 08:39:39 -0500

Seen: 34 times

Last updated: Apr 21