PDA

View Full Version : Creating QImage with OccupancyGrid message data.



xtrememoo
5th August 2014, 08:41
Hello guys, I'm currently using LIDAR and an aerial vehicle. I'm stucked at this situation where I don't know how am I gonna find out the OccupancyGrid message data and how to use it and copy the map from the message data to mapImage (QImage). I'm a real amateur so... I really need obvious hints/help. Thanks a ton!




void QNode::parsemap(const nav_msgs::OccupancyGrid::ConstPtr& msg) {
if (mapImage == NULL) {
// copy map from message to mapImage.
mapImage = new QImage(240, 350, QImage::Format_RGB888);
}
...
}


I've asked this on another forum and they gave me this, but I don't know how do I get around with it too...

"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*)m_data.data(), msg->info.width, msg->info.height, QImage::Format_RGB888);
...
}

"


I've heard I needed to use Scanline to create the QImage, but I'm not sure how to really use it either. I've been trying to read up on QByteArray, QPixmap, Scanline(), and many more but I still don't get a single thing.. I'd really appreciate you guys' help. :)