Ask Your Question
0

Problem with displaying image messages inside Qt GUI with librviz

asked 2021-03-12 01:26:14 -0600

nikko gravatar image

Hey all,

I'm having a problem that my image messages are displayed in a separate window rather than inside my self-made Qt main window where they should be. Otherwise the code works and the images are showed.

I can display my point cloud messages in the GUI very easily with librviz. There is something different with image display? What is it?

Here is code snippets of both point cloud and image view display initialization in my GUI:

    void setup_rviz_lidar()
{

    rvizLayoutWidget = new QWidget(centralwidget);
    rvizLayoutWidget->setObjectName(QStringLiteral("RvizWidget"));
    rvizLayoutWidget->setGeometry(QRect(400, 10, 600, 600));

    layoutRviz = new QHBoxLayout(rvizLayoutWidget);
    render_panel_ = new rviz::RenderPanel();
    layoutRviz->addWidget( render_panel_ );

    manager_ = new rviz::VisualizationManager( render_panel_ );
    render_panel_->initialize( manager_->getSceneManager(), manager_ );
    manager_->initialize();
    manager_->startUpdate();

    //https://answers.ros.org/question/191721/librviz-display-sensor_msgslaserscan/
    // Create point cloud display.
    manager_->setFixedFrame("livox_frame");
    laser_ = manager_->createDisplay( "rviz/PointCloud2", "Point cloud", true );
    laser_->subProp("Topic")->setValue("livox/lidar");
    laser_->subProp("Style")->setValue("Points");
    laser_->subProp("Size (Pixels)")->setValue("2");
    laser_->subProp("Color Transformer")->setValue("Intensity");
    laser_->subProp("Invert Rainbow")->setValue("true");
    laser_->subProp("Decay Time")->setValue("1");

}

void setup_rviz_video() // pops up as separate window  :(
{
    rvizLayoutWidget2 = new QWidget(centralwidget);
    rvizLayoutWidget2->setObjectName(QStringLiteral("RvizWidget2"));
    rvizLayoutWidget2->setGeometry(QRect(10, 215, 390, 390));

    layoutRviz2 = new QHBoxLayout(rvizLayoutWidget2);
    render_panel2_ = new rviz::RenderPanel();
    layoutRviz2->addWidget(render_panel2_);

    manager2_ = new rviz::VisualizationManager(render_panel2_);
    render_panel2_->initialize( manager2_->getSceneManager(), manager2_);
    manager2_->initialize();
    manager2_->startUpdate();

    image_ = manager2_->createDisplay( "rviz/Image", "Image", true );
    image_->subProp("Image Topic")->setValue("camera/ipximage");
}

Thanks in advance!

-Nikko

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-03-12 08:08:28 -0600

nikko gravatar image

I found one solution

Instead of using rviz::RenderPanel and rviz::VisualizationManager I utilized ImageView class. Got hint about it by investigating this graph here: http://docs.ros.org/en/melodic/api/rv...

This is how it is initialized in my gui (QMainwindow):

void setup_rviz_video()
    {
        rvizLayoutWidget2 = new QWidget(centralwidget);
        rvizLayoutWidget2->setObjectName(QStringLiteral("RvizWidget2"));
        rvizLayoutWidget2->setGeometry(QRect(10, 265, 390, 345));
        layoutRviz2 = new QVBoxLayout(rvizLayoutWidget2);


        mImageview = new ImageView();
        layoutRviz2->addWidget(mImageview);
        mImageview->setEnabled(true);

    }

Yet I was not able to find the ImageView files anywhere in my ROS(melodic). So I just copy pasted the source and header -files to my project from the docs: http://docs.ros.org/en/melodic/api/rv...

I just modified the image size and topic name in image_view.cpp and all worked well.

Please, if someone has a better, easier or faster way to do this, let me know!

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-03-12 01:26:14 -0600

Seen: 63 times

Last updated: Mar 12 '21