Ask Your Question

singleshot / photo with webcamera

asked 2012-06-15 09:36:07 -0500

dinamex gravatar image

updated 2012-08-09 04:05:02 -0500

Hi everybody,

I want to use a webcam as a photocamera which can be triggered to to take single pictures (the sensor is 3.1 MP). I'm pretty new to the imaging part and would like to know how it would be the easiest way to take a single photo? I already use the usb_cam package but this is just for streaming. Can I modify the source code to trigger a single shot? because there they only use v4l2.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-07-08 09:26:40 -0500

updated 2012-07-08 14:06:26 -0500

Right click in image_view saves the current image in the stream to file. You can use run this node with your choice of camera driver to save images at will.

EDIT: There are a number of ways in which you can store the image in a computationally efficient manner. If possible, try to avoid changing the driver code itself unless absolutely necessary. You can try something like:

  • Use a usb cam driver that provides a nodelet interface. I don't think usb_cam supports a nodelet, but I believe uvc_camera does so.
  • Create a nodelet that subscribes to the image stream (sensor_msgs/Image) produced by the camera, and an empty message (std_msgs/Empty) on a topic such as 'save_image'. Whenever you receive an empty message, you can set a boolean flag which saves the image using cv::imwrite in the image callback.
  • Launch both nodelets in to the same nodelet manager. This should remove any copy costs while saving the image. You can then save images by typing the following at the command line: rostopic pub /save_image std_msgs/Empty

This should allow you to save images programmatically as well if needed.

edit flag offensive delete link more


I'm using Ubuntu server so imageview + right klick will not work. Furthermore I would like to reduce the amount of processed data because of computational limitations.

dinamex gravatar image dinamex  ( 2012-07-08 12:37:49 -0500 )edit

@dinamex: see updated answer

piyushk gravatar image piyushk  ( 2012-07-08 14:06:42 -0500 )edit

You could run image_view on a separate machine with a GUI that was connected to the Ubuntu server over the network. See for example.

Eric Perko gravatar image Eric Perko  ( 2012-08-09 05:38:01 -0500 )edit

where is the difference between nodelet and node? @Eric: I can't use a GUI because the system should be independent. I just want to save Images (best as jpg) to use them later.

dinamex gravatar image dinamex  ( 2012-08-09 10:55:40 -0500 )edit

@dinamex: multiple nodelets can run in the same process, and do not incur any copy costs for transmitting data from 1 nodelet to another. See the ROS wiki: (and the tutorials). You can implement the above using nodes, but you'll be sending some image data over TCP.

piyushk gravatar image piyushk  ( 2012-08-10 16:05:53 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2012-06-15 09:36:07 -0500

Seen: 836 times

Last updated: Aug 09 '12