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

Hi, it may be because the image is empty. Before sending the image, you should check if it is not empty, and recheck its size before using it.

This callback works for me (Ubuntu 16.04, ROS kinetic, OpenCV 3) :

cv::Mat cameraFeed;
// Callback function. Serves to receive images from ROS camera's images topic
void imageCallback(const sensor_msgs::ImageConstPtr& msg)
{
    try
    {
        cameraFeed = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8)->image;
    }
    catch (cv_bridge::Exception& e)
    {
        ROS_ERROR("Could not convert from '%s' to 'bgr8'.", msg->encoding.c_str());
        return;
    }
    cv::waitKey(1);
}