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

how can I receive single images from an image_transport stream using a service client

asked 2014-04-01 10:48:42 -0600

HXP2 gravatar image

Hello,

I try to setup a Service which provides single images out of an image_transport stream to a client requesting an image. I found this Question 42909 (Karma not sufficient to post links, sorry.) which is in principal what I need.

answers.ros.org/question/42909/how-can-i-use-a-servicerequest-to-capture-a-single-callback-from-a-subscription/

Since I'm new to ROS and the example is simplified I'm stuck at the point where the image is presented to the client. What I would need to know is: 1) How does the srv file look like to use the example. (If a srv file is needed at all) 2) How can I actually get access to the image on client side to do image processing on it. In the example this part is simplified with the comment: read_grab() ?

I searched ROS answers for hours with no success so I hope somebody understands my problem description and is willing to help.

thanks in advance HXP2

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
1

answered 2014-04-02 03:04:53 -0600

demmeln gravatar image

updated 2014-04-02 10:56:52 -0600

You could have a look at this node, which does something similar for kinect data. You should be able to take the general idea and adapt it to your needs with only color images instead of kinect data: https://github.com/SharedAutonomyTool...

The .srv file used in for this node is here: https://github.com/SharedAutonomyTool...

I'm not saying this is the best solution, but maybe it helps.

Edit:

In response to your clarification of what you want to do: You could build a node along the following lines:

  1. Create class to implement your node. In particular you have one Image message member variable to store the latest received input image, and you have another image object as member variable (message or cv::Mat or whatever) that will contain the first image without the laser line.
  2. Subscribe to the image topic, and in the callback always save the the incoming image to the corresponding member variable
  3. Subscribe to some sort of command topic (maybe of type std_msgs/String) with which you tell your node to store the current image as the first image. In the callback you copy the one member variable to the other
  4. When you receive a second command (you could either count the commands, or use different strings or whatever), you take the current image and compare it to the one you saved on the first command.

For help on converting between ROS image messages and OpenCV images, see http://wiki.ros.org/cv_bridge/Tutoria...

edit flag offensive delete link more
0

answered 2014-04-02 10:40:27 -0600

HXP2 gravatar image

updated 2014-04-11 11:27:53 -0600

First, thank you for your answers. Let me describe what I try to do so maybe someone has solved this already:

I want to write a node which is performing the following steps:

  1. read a first image from usb_cam and store it as an image which can be processed using openCV
  2. switch on a line laser to draw a line within the field of view of the usb_cam
  3. read a second image from the usb_cam and store it
  4. subtract both images using openCV so only the laser line is visible in the resulting image.

If I can perform this operation using messages only, it's fine to me but I thought in this case a service call to get the first and the second image is the better approach.

Since I'm a ROS beginner, sample code would be great...

Thank you in advance, HXP2

Solution:

Thank you demmeln, I followed your suggestion and erverything works well now !

edit flag offensive delete link more

Comments

This is not a chat. Don't post answers that don't answer your question. Edit your original question instead.

demmeln gravatar image demmeln  ( 2014-04-02 10:50:10 -0600 )edit
0

answered 2014-04-01 12:09:40 -0600

metal gravatar image

As suggested in the given link. It is much easier and efficient, if you subscribe to the image topic and it can be processed in your callback function. This link might be helpful.

Also here is an example from my tutorial. i have used opencv to process the image stream. Hope this is helpful.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-04-01 10:48:42 -0600

Seen: 3,325 times

Last updated: Apr 11 '14