ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The answer seems to add the following in the callback. Although, this seems wrong to me, but it does work

    cv::namedWindow("view", cv::WINDOW_AUTOSIZE);
    cv::startWindowThread();

The full function:

void CameraDisplayNode::display_image_callback(const sensor_msgs::msg::Image::SharedPtr msg){
    //--------------------------
    cv::namedWindow("view", cv::WINDOW_AUTOSIZE);
    cv::startWindowThread();
    //--------------------------
    try{
        cv::imshow("view", cv_bridge::toCvShare(msg, "bgr8")->image);
        int keycode = cv::waitKey(30) & 0xff;
        if(keycode == 27){
            RCLCPP_INFO(this->get_logger(),"Exit Display");
        }// end if(keycode == 27)
    }// end try
    catch (cv_bridge::Exception& e){
        RCLCPP_ERROR(this->get_logger(),"Could not convert from '%s' to 'bgr8'.", msg->encoding.c_str());
    }// end catch
}// end display_image_callback