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

Revision history [back]

sensor_msgs::ImagePtr msgf = cv_bridge::CvImage(std_msgs::Header(), "mono8", imdx).toImageMsg(); //Transforms OpenCV image to ROS Image Message
while(nh.ok()){
    pub.publish(msgf); //Publish Image message in topic /image_dewrapped P.S.:Does not work properly
}

You need to convert the cv image to a ROS Image on every update to cv image.

You also should restructure so the while loop doesn't publish if the image hasn't been updated and won't have issues with multi-threading or single threading, the callback never gets a chance to get called if the while loop never sleeps, or if multithreading the callback may be in the middle of changing the message when the publish is called. One approach that ought to fix all of the above would be to publish at the end of the callback and use a ros msg and cv mat instead of a global local to the callback, the publisher could be global.

See http://wiki.ros.org/roscpp/Overview/Callbacks%20and%20Spinning

sensor_msgs::ImagePtr msgf = cv_bridge::CvImage(std_msgs::Header(), "mono8", imdx).toImageMsg(); //Transforms OpenCV image to ROS Image Message while(nh.ok()){ pub.publish(msgf); //Publish Image message in topic /image_dewrapped P.S.:Does not work properly }

}

You need to convert the cv image to a ROS Image on every update to cv image.image (actually this is worth double checking...).

You also should restructure so the while loop doesn't publish if the image hasn't been updated and won't have issues with multi-threading or single threading, the callback never gets a chance to get called if the while loop never sleeps, or if multithreading the callback may be in the middle of changing the message when the publish is called. One approach that ought to fix all of the above would be to publish at the end of the callback and use a ros msg and cv mat instead of a global local to the callback, the publisher could be global.

See http://wiki.ros.org/roscpp/Overview/Callbacks%20and%20Spinning

:

sensor_msgs::ImagePtr msgf = cv_bridge::CvImage(std_msgs::Header(), "mono8", imdx).toImageMsg(); //Transforms OpenCV image to ROS Image Message while(nh.ok()){ pub.publish(msgf); //Publish Image message in topic /image_dewrapped P.S.:Does not work properly }

You need to convert the cv image to a ROS Image on every update to cv image (actually this is worth double checking...).

You also should restructure so the while loop doesn't publish if the image hasn't been updated and won't have issues with multi-threading or single threading, the callback never gets a chance to get called if the while loop never sleeps, or if multithreading the callback may be in the middle of changing the message when the publish is called. One approach that ought to fix all of the above would be to publish at the end of the callback and use a ros msg and cv mat instead of a global local to the callback, the publisher could be global.

See http://wiki.ros.org/roscpp/Overview/Callbacks%20and%20Spinning

:

sensor_msgs::ImagePtr msgf = cv_bridge::CvImage(std_msgs::Header(), "mono8", imdx).toImageMsg(); //Transforms OpenCV image to ROS Image Message
 while(nh.ok()){
     pub.publish(msgf); //Publish Image message in topic /image_dewrapped P.S.:Does not work properly
    }

}

You need to convert the cv image to a ROS Image on every update to cv image (actually this is worth double checking...).

You also should restructure so the while loop doesn't publish if the image hasn't been updated and won't have issues with multi-threading or single threading, the callback never gets a chance to get called if the while loop never sleeps, or if multithreading the callback may be in the middle of changing the message when the publish is called. One approach that ought to fix all of the above would be to publish at the end of the callback and use a ros msg and cv mat instead of a global local to the callback, the publisher could be global.

See http://wiki.ros.org/roscpp/Overview/Callbacks%20and%20Spinning

:

sensor_msgs::ImagePtr msgf = cv_bridge::CvImage(std_msgs::Header(), "mono8", imdx).toImageMsg(); //Transforms OpenCV image to ROS Image Message
while(nh.ok()){
    pub.publish(msgf); //Publish Image message in topic /image_dewrapped P.S.:Does not work properly
}

You need to convert the cv image to a ROS Image on every update to cv image (actually this is worth double checking...).

You also should restructure so the while loop doesn't publish if the image hasn't been updated and won't have issues with multi-threading or single threading, the callback never gets a chance to get called if the while loop never sleeps, or if multithreading the callback may be in the middle of changing the message when the publish is called. One approach that ought to fix all of the above would be to publish at the end of the callback and use a ros msg and cv mat instead of a global local to the callback, the publisher could be global.

See http://wiki.ros.org/roscpp/Overview/Callbacks%20and%20Spinning

:

sensor_msgs::ImagePtr msgf = cv_bridge::CvImage(std_msgs::Header(), "mono8", imdx).toImageMsg(); //Transforms OpenCV image to ROS Image Message
while(nh.ok()){
    pub.publish(msgf); //Publish Image message in topic /image_dewrapped P.S.:Does not work properly
}

You need to convert the cv image to a ROS Image on every update to cv image (actually this (http://docs.ros.org/kinetic/api/cv_bridge/html/c++/classcv__bridge_1_1CvImage.html says the underlying image data is worth double checking...).copied).

You also should restructure so the while loop doesn't publish if the image hasn't been updated and won't have issues with multi-threading or single threading, the callback never gets a chance to get called if the while loop never sleeps, or if multithreading the callback may be in the middle of changing the message when the publish is called. One approach that ought to fix all of the above would be to publish at the end of the callback and use a ros msg and cv mat local to the callback, the publisher could be global.

See http://wiki.ros.org/roscpp/Overview/Callbacks%20and%20Spinning