我正在尝试显示模拟器拍摄的视频。我正在通过包含其头文件来实现 ROS 中的 QT 代码。我的代码正在运行。问题:: 每次打开新窗口以显示框架。我保留了 cvWaitKey(10000) 以便在一段时间延迟后出现新窗口。但是更新的框架应该在同一个窗口内。请建议我该怎么做?我的代码如下:
void imageCallback( const sensor_msgs::ImageConstPtr& msg) //const sensor_msgs::ImageConstPtr&
{
imagePublisher.publish (cv_ptr->toImageMsg());
QImage temp(&(msg->data[0]), msg->width, msg->height, QImage::Format_RGB888);
QImage image;
image=temp;
// QT Layout with button and image
static QWidget *window = new QWidget;
static QLabel *imageLabel= new QLabel;
static QPushButton* quitButton= new QPushButton("Quit");
static QPushButton* exitButton= new QPushButton("Exit Image");
QVBoxLayout* layout= new QVBoxLayout;
imageLabel->setPixmap(QPixmap::fromImage(image));
layout->addWidget(imageLabel);
layout->addWidget(exitButton);
layout->addWidget(quitButton);
window->setLayout(layout);
QObject::connect(quitButton, SIGNAL(clicked()),window, SLOT(close())); // Adding Buttons
QObject::connect(exitButton, SIGNAL(clicked()),imageLabel, SLOT(close()));
window->show();
cvWaitKey(1);
}
int main(int argc, char **argv) {
ros::init(argc, argv, "imageSelectNode");
ros::NodeHandle n("~");
image_transport::ImageTransport it(n);
image_transport::Subscriber sub = it.subscribe("/camera/image_raw",1, imageCallback);
imagePublisher = it.advertise("imagePublisherTopic", 1); //Publish the image in 'imagePublisherTopic' node
QApplication a(argc, argv);
ros::spin();
return 0;
}