Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If you look at the OccupancyGrid message (i.e., rosmsg show nav_msgs/OccupancyGrid), there are member fields for width, height, and the binary data. There are multiple ways of creating a QImage given that data; I haven't run the following (you may need to futz with the cast of the msg->data), but you can do something like:

const unsigned char* databeg = &(msg->data.front());
QImage img(databeg, msg->info.width, msg->info.height, QImage::Format_RGB888);

Note that there are additional considerations of which you must be aware. For instance, as stated in the QImage documentation, the data buffer must remain valid throughout the life of the QImage. So you might want to store the data, say as a QByteArray:

QByteArray m_data;
void QNode::parsemap( const nav_msgs::OccupancyGrid::ConstPtr& msg ) {
    const unsigned char* databeg = &(msg->data.front());
    m_data = QByteArray(databeg, msg->data.size());
    QImage img((uchar*), msg->info.width, msg->info.height, QImage::Format_RGB888);

That should be enough to get you on your way...