Coder Social home page Coder Social logo

usb_cam's Introduction

usb_cam ROS 2 CI

A ROS 2 Driver for V4L USB Cameras

This package is based off of V4L devices specifically instead of just UVC.

For ros1 documentation, see the ROS wiki.

Supported ROS 2 Distros and Platforms

All Officially supported Linux Distros and corresponding ROS 2 releases are supported. Please create an issue if you experience any problems on these platforms.

Windows: TBD/Untested/Unproven MacOS: TBD/Untested/Unproven

For either MacOS or Windows - if you would like to try and get it working please create an issue to document your effort. If it works we can add it to the instructions here!

Quickstart

Assuming you have a supported ROS 2 distro installed, run the following command to install the binary release:

sudo apt-get install ros-<ros2-distro>-usb-cam

As of today this package should be available for binary installation on all active ROS 2 distros.

If for some reason you cannot install the binaries, follow the directions below to compile from source.

Building from Source

Clone/Download the source code into your workspace:

cd /path/to/colcon_ws/src
git clone https://github.com/ros-drivers/usb_cam.git

Or click on the green "Download zip" button on the repo's github webpage.

Once downloaded and ensuring you have sourced your ROS 2 underlay, go ahead and install the dependencies:

cd /path/to/colcon_ws
rosdep install --from-paths src --ignore-src -y

From there you should have all the necessary dependencies installed to compile the usb_cam package:

cd /path/to/colcon_ws
colcon build
source /path/to/colcon_ws/install/setup.bash

Be sure to source the newly built packages after a successful build.

Once sourced, you should be able to run the package in one of three ways, shown in the next section.

Running

The usb_cam_node can be ran with default settings, by setting specific parameters either via the command line or by loading in a parameters file.

We provide a "default" params file in the usb_cam/config/params.yaml directory to get you started. Feel free to modify this file as you wish.

Also provided is a launch file that should launch the usb_cam_node_exe executable along with an additional node that displays an image topic.

The commands to run each of these different ways of starting the node are shown below:

NOTE: you only need to run ONE of the commands below to run the node

# run the executable with default settings (without params file)
ros2 run usb_cam usb_cam_node_exe

# run the executable while passing in parameters via a yaml file
ros2 run usb_cam usb_cam_node_exe --ros-args --params-file /path/to/colcon_ws/src/usb_cam/config/params.yaml

# launch the usb_cam executable that loads parameters from the same `usb_cam/config/params.yaml` file as above
# along with an additional image viewer node
ros2 launch usb_cam camera.launch.py

Launching Multiple usb_cam's

To launch multiple nodes at once, simply remap the namespace of each one:

ros2 run usb_cam usb_cam_node_exe --remap __ns:=/usb_cam_0 --params-file /path/to/usb_cam/config/params_0.yaml
ros2 run usb_cam usb_cam_node_exe --remap __ns:=/usb_cam_1 --params-file /path/to/usb_cam/config/params_1.yaml

Supported formats

Device supported formats

To see a connected devices supported formats, run the usb_cam_node and observe the console output.

An example output is:

This devices supproted formats:
       Motion-JPEG: 1280 x 720 (30 Hz)
       Motion-JPEG: 960 x 540 (30 Hz)
       Motion-JPEG: 848 x 480 (30 Hz)
       Motion-JPEG: 640 x 480 (30 Hz)
       Motion-JPEG: 640 x 360 (30 Hz)
       YUYV 4:2:2: 640 x 480 (30 Hz)
       YUYV 4:2:2: 1280 x 720 (10 Hz)
       YUYV 4:2:2: 640 x 360 (30 Hz)
       YUYV 4:2:2: 424 x 240 (30 Hz)
       YUYV 4:2:2: 320 x 240 (30 Hz)
       YUYV 4:2:2: 320 x 180 (30 Hz)
       YUYV 4:2:2: 160 x 120 (30 Hz)

Driver supported formats

The driver has its own supported formats. See the source code for details.

After observing the devices supported formats, specify which format to use via the parameters file with the pixel_format parameter.

To see a list of all currently supported driver formats, run the following command:

ros2 run usb_cam usb_cam_node_exe --ros-args -p pixel_format:="test"

Note: "test" here could be replaced with any non-supported pixel format string. The driver will detect if the given pixel format is supported or not.

More formats and conversions can be added, contributions welcome!

Supported IO methods

This driver supports three different IO methods as of today:

  1. read: copies the video frame between user and kernal space
  2. mmap: memory mapped buffers allocated in kernel space
  3. userptr: memory buffers allocated in the user space

To read more on the different methods, check out this article that provides a good overview of each

Compression

Big thanks to the ros2_v4l2_camera package and their documentation on this topic.

The usb_cam should support compression by default since it uses image_transport to publish its images as long as the image_transport_plugins package is installed on your system. With the plugins installed the usb_cam package should publish a compressed topic automatically.

Unfortunately rviz2 and show_image.py do not support visualizing the compressed images just yet so you will need to republish the compressed image downstream to uncompress it:

ros2 run image_transport republish compressed raw --ros-args --remap in/compressed:=image_raw/compressed --remap out:=image_raw/uncompressed

Address and leak sanitizing

Incorporated into the CMakelists.txt file to assist with memory leak and address sanitizing is a flag to add these compile commands to the targets.

To enable them, pass in the SANITIZE=1 flag:

colcon build --packages-select usb_cam --cmake-args -DSANITIZE=1

Once built, run the nodes executable directly and pass any ASAN_OPTIONS that are needed:

ASAN_OPTIONS=new_delete_type_mismatch=0 ./install/usb_cam/lib/usb_cam/usb_cam_node_exe 

After shutting down the executable with Ctrl+C, the sanitizer will report any memory leaks.

By default this is turned off since compiling with the sanatizer turned on causes bloat and slows down performance.

Documentation

Doxygen files can be found on the ROS wiki.

License

usb_cam is released with a BSD license. For full terms and conditions, see the LICENSE file.

Authors

See the AUTHORS file for a full list of contributors.

usb_cam's People

Contributors

agcooke avatar benmaidel avatar blutack avatar boitumeloruf avatar clalancette avatar cottsay avatar dekent avatar eliasm avatar evan-flynn-apexai avatar ezavesky avatar firesurfer avatar flynneva avatar friedcircuits avatar johnjamesmiller avatar jsarrett avatar k-okada avatar kaijenhsiao avatar kmhallen avatar krsche avatar lucasw avatar ludusrusso avatar mad0x60 avatar progtologist avatar pronobis avatar rctoris avatar revanthsenthil avatar rjw57 avatar sosentos avatar tzutalin avatar vrabaud avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

usb_cam's Issues

usb_cam cannot run when the pixel format is rgb24.

usb_cam cannot run when the pixel format is rgb24.
terminal output is as follows.
Please help me find out why.

roslaunch usb_cam usb_cam-test.launch
... logging to /home/nvidia/.ros/log/c21aa304-6d1f-11e8-b26d-00044b8d87aa/roslaunch-tegra-ubuntu-6800.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
WARNING: disk usage in log directory [/home/nvidia/.ros/log] is over 1GB.
It's recommended that you use the 'rosclean' command.

started roslaunch server http://tegra-ubuntu:33447/

SUMMARY

PARAMETERS

  • /rosdistro: kinetic
  • /rosversion: 1.12.13
  • /usb_cam/camera_frame_id: usb_cam
  • /usb_cam/image_height: 720
  • /usb_cam/image_width: 1280
  • /usb_cam/io_method: mmap
  • /usb_cam/pixel_format: rgb24
  • /usb_cam/video_device: /dev/video0

NODES
/
usb_cam (usb_cam/usb_cam_node)

ROS_MASTER_URI=http://localhost:11311

process[usb_cam-1]: started with pid [6818]
[ INFO] [1528697923.327253730]: using default calibration URL
[ INFO] [1528697923.327804838]: camera calibration URL: file:///home/nvidia/.ros/camera_info/head_camera.yaml
[ INFO] [1528697923.328183784]: Unable to open camera calibration file [/home/nvidia/.ros/camera_info/head_camera.yaml]
[ WARN] [1528697923.328337065]: Camera calibration file /home/nvidia/.ros/camera_info/head_camera.yaml not found.
[ INFO] [1528697923.328510858]: Starting 'head_camera' (/dev/video0) at 1280x720 via mmap (rgb24) at 30 FPS
[ WARN] [1528697923.515465061]: unknown control 'white_balance_temperature_auto'

[usb_cam-1] process has died [pid 6818, exit code -11, cmd /home/nvidia/catkin_ws/devel/lib/usb_cam/usb_cam_node __name:=usb_cam __log:=/home/nvidia/.ros/log/c21aa304-6d1f-11e8-b26d-00044b8d87aa/usb_cam-1.log].
log file: /home/nvidia/.ros/log/c21aa304-6d1f-11e8-b26d-00044b8d87aa/usb_cam-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor...
... shutting down processing monitor complete
done

Cannot use as a library for multiple cameras

Currently is is difficult to use this as a library to communicate with multiple cameras in the same node because of global state. It would be nice if usb_cam.cpp was refactored to move all of the state into a class.

I would be happy to offer a pull request if it would be accepted.

Arducam/ardushield

Hi !
I can not figure out why I can't use this library with the usb-connected arducam (using ardushield for usb connection)

Can you help me out ?
Thanks!

[ WARN] [1451228881.432495085]: sh: 1: v4l2-ctl: not found

I use this demo and run this cmd $ roslaunch usb_cam usb_cam-test.launch and it is warn the information as the title "sh: 1: v4l2-ctl:not found", and my system is Ubuntu 14.04 with jade . the video can't display . I'm sure the camera is running normal becasue I use the geese I can see the video normal, I don't know how to solve it and who can help me ?

Is there something wrong with the exposure?

PARAMETERS

  • /image_view/autosize: True
  • /rosdistro: indigo
  • /rosversion: 1.11.16
  • /usb_cam/auto_white_balance: True
  • /usb_cam/autoexposure: True
  • /usb_cam/camera_frame_id: usb_cam
  • /usb_cam/image_height: 480
  • /usb_cam/image_width: 640
  • /usb_cam/io_method: mmap
  • /usb_cam/pixel_format: mjpeg
  • /usb_cam/video_device: /dev/video0

NODES
/
image_view (image_view/image_view)
usb_cam (usb_cam/usb_cam_node)

auto-starting new master
process[master]: started with pid [20414]
ROS_MASTER_URI=http://localhost:11311

setting /run_id to d4a0e2a6-e04d-11e5-be96-5cc5d4b62664
process[rosout-1]: started with pid [20427]
started core service [/rosout]
/opt/ros/indigo/lib/python2.7/dist-packages/roslib/packages.py:447: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
if resource_name in files:
process[usb_cam-2]: started with pid [20430]
process[image_view-3]: started with pid [20440]
[ INFO] [1456906059.308717716]: Using transport "raw"
[ INFO] [1456906059.523110174]: using default calibration URL
[ INFO] [1456906059.523191021]: camera calibration URL: file:///home/chenxieyuanli/.ros/camera_info/head_camera.yaml
[ INFO] [1456906059.523240698]: Unable to open camera calibration file [/home/chenxieyuanli/.ros/camera_info/head_camera.yaml]
[ WARN] [1456906059.523276190]: Camera calibration file /home/chenxieyuanli/.ros/camera_info/head_camera.yaml not found.
[ INFO] [1456906059.523294680]: Starting 'head_camera' (/dev/video0) at 640x480 via mmap (mjpeg) at 30 FPS
[ WARN] [1456906059.926171118]: unknown control 'focus_auto'

Uploading 2016-3-2.png…

Uploading 2016-3-2.gif…
Uploading 2016-3-2.png…

Image is not stable

My environment is raspberry Pi 3, indigo, Logitec Quickcam

when I run the usb_cam, I can get the image, but it is not stable, I got error like below:

[swscaler @ 0xd56ca0] No accelerated colorspace conversion found from yuv422p to rgb24.
[mjpeg @ 0xd758a0] mjpeg_decode_dc: bad vlc: 0:0 (0xd75e68)
[mjpeg @ 0xd758a0] error dc

[mjpeg @ 0xd758a0] error y=59 x=34

Add usb_cam to ROS Kinetic main repository

ROS Kinetic users can actually install this package from source only.

It's better to be able to install it using:

sudo apt-get install ros-kinetic-usb-cam

as it was possible for ROS Groovy, Indigo and Jade

Indigo release

I am currently migrating our software to ROS Indigo and found these packages missing. Will they be released for Indigo?

HW MJPEG decode possible?

Since the MJPEG decoding seems to be handled by FFMPEG in usb_cam and since FFMPEG is supporting HW (GPU) decoding of video streams (depending on the platform), would that be possible to leverage on the GPU for decoding MJPEG frames? That could be a solution to reduce CPU usage (currently 50% for an HD MJPEG camera).
For info, on ubuntu 16.04 with an intel Skylake CPU/iGPU, I had to install FFMPEG 3 with the following package to make HW transcoding work (tested with vp8 transcoding on the CLI):

sudo add-apt-repository -y ppa:jonathonf/ffmpeg-4
sudo add-apt-repository -y ppa:ubuntu-x-swat/updates
sudo apt-get update
sudo apt-get install -y ffmpeg
sudo apt-get install -y libvdpau-va-gl1
sudo apt-get install -y libvpx-dev libva-dev dh-autoreconf libavcodec-dev
sudo sh -c "echo 'export VDPAU_DRIVER=va_gl' >> /etc/profile"

I think I am going to give it a try one of these days, but if anybody has suggestions, please let me know.

"deprecated pixel format used" warning when using pixel format mjpeg

When launching an usb_cam ROS node with pixel_format="yuyv", everything works fine. If launching the same node with pixel_format ="mjpeg" the terminal outputs a continuing stream of these warnings:

[swscaler @ 0x1545460] deprecated pixel format used, make sure you did set range correctly

But the frames seem to be captured normally otherwhise, and the live image works fine.

Reorganization to add other generic camera drivers

@bosch-ros-pkg/owners,

I've been catkin-izing the bosch_drivers packages, and this package used to be one of them. We also have a driver/wrapper for gphoto2, which allows the control of cameras. I think that these two packages belong together in a single location/repository: camera_drivers.

As you can see here, usb_cam is a stand-alone repo. Is there a way to move it into a repo that also contains other camera drivers? I don't know what the github and ROS standards are for repositories and packages, but as you may know, I prefer a bit more structure than a flat filesystem (hence my request).

As a second note, there are some outstanding issues and pull-requests on this repo. Is @rctoris actively maintaining this package?

Thanks.

Gain setting not persistent

Hi,

I am trying to use this driver for a usb_cam (Logitech C920). I manually configured exposure, set auto_exposure to 0 and set gain to a specific value. When the camera starts up, the image looks good and running v4l2-ctl -d /dev/video2 --all shows the correct settings.

However, after running the driver for several hours, the gain setting seems to change on its own. Is there a way to fix this?

Thanks!
Marc

nodelet support

uvc_camera and libuvc_camera had nodelet support, i think usb_cam should have this too, as this is the "standard" usb camera driver for ROS

outbuff size mismatch

Greetings,

I am using your package to try visualizes images through my computer but get the following error:

>>$ roslaunch rbx1_vision usb_cam.launch 
... logging to /home/vmrguser/.ros/log/a56ffcc8-ea90-11e4-9a8d-d4bed96834ea/roslaunch-vmrguser-XPS-L521X-19669.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://vmrguser-XPS-L521X:41697/

SUMMARY
========

CLEAR PARAMETERS
 * /usb_cam/

PARAMETERS
 * /rosdistro: indigo
 * /rosversion: 1.11.10
 * /usb_cam/autofocus: True
 * /usb_cam/brightness: 32
 * /usb_cam/camera_frame_id: camera_link
 * /usb_cam/contrast: 32
 * /usb_cam/framerate: 30
 * /usb_cam/image_height: 480
 * /usb_cam/image_width: 640
 * /usb_cam/pixel_format: mjpeg
 * /usb_cam/saturation: 32
 * /usb_cam/video_device: /dev/video0

NODES
  /
    usb_cam (usb_cam/usb_cam_node)

ROS_MASTER_URI=http://localhost:11311

core service [/rosout] found
process[usb_cam-1]: started with pid [20100]
[ INFO] [1429887366.979127773]: using default calibration URL
[ INFO] [1429887366.979218120]: camera calibration URL: file:///home/vmrguser/.ros/camera_info/head_camera.yaml
[ INFO] [1429887366.979278383]: Unable to open camera calibration file [/home/vmrguser/.ros/camera_info/head_camera.yaml]
[ WARN] [1429887366.979308869]: Camera calibration file /home/vmrguser/.ros/camera_info/head_camera.yaml not found.
[ INFO] [1429887366.979342756]: Starting 'head_camera' (/dev/video0) at 640x480 via mmap (mjpeg) at 30 FPS
[ INFO] [1429887367.941776731]: V4L2_CID_FOCUS_AUTO is not supported
[ WARN] [1429887367.947014217]: unknown control 'focus_auto'

[ERROR] [1429887367.950547643]: outbuf size mismatch.  pic_size: 1843200 bufsize: 614
400

I am using ROS Inidgo on Linux Ubuntu 14.04.02 on a Dell XPS 512.

When I do a rostopic list, I can see:

/camera/rgb/camera_info
/camera/rgb/image_raw
/camera/rgb/image_raw/compressed
/camera/rgb/image_raw/compressed/parameter_descriptions
/camera/rgb/image_raw/compressed/parameter_updates
/camera/rgb/image_raw/compressedDepth
/camera/rgb/image_raw/compressedDepth/parameter_descriptions
/camera/rgb/image_raw/compressedDepth/parameter_updates
/camera/rgb/image_raw/theora
/camera/rgb/image_raw/theora/parameter_descriptions
/camera/rgb/image_raw/theora/parameter_updates
/rosout
/rosout_agg

However, when trying to visual /camera/rgb/image_raw I only get a black screen. rostopic echo is all zeros.

And I have checked that my webcam works with other programs like cheese, gstreamer, vlc, mplayer, streamer, etc.

I saw that this is a widespread problems with (students) running Linux 14.04.2 and ROS Indigo.

ROS Error USB_CAM not launching---Ubuntu 16.04

~$ roslaunch /home/gpslab/catkin_wsorb/src/usb_cam/launch/usb_cam-test.launch
... logging to /home/gpslab/.ros/log/14c1bbda-6431-11e8-8ba2-b06ebf7e7a7d/roslaunch-gpslab-System-Product-Name-9465.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://gpslab-System-Product-Name:44395/

SUMMARY

PARAMETERS

  • /image_view/autosize: True
  • /rosdistro: kinetic
  • /rosversion: 1.12.13
  • /usb_cam/camera_frame_id: usb_cam
  • /usb_cam/image_height: 480
  • /usb_cam/image_width: 640
  • /usb_cam/io_method: mmap
  • /usb_cam/pixel_format: yuyv
  • /usb_cam/video_device: /dev/video0

NODES
/
image_view (image_view/image_view)
usb_cam (usb_cam/usb_cam_node)

ROS_MASTER_URI=http://localhost:11311

ERROR: cannot launch node of type [usb_cam/usb_cam_node]: usb_cam
ROS path [0]=/opt/ros/kinetic/share/ros
ROS path [1]=/opt/ros/kinetic/share
process[image_view-2]: started with pid [9482]
[ INFO] [1527703031.132855713]: Using transport "raw"

Incorrect timestamp

Hi!

I ran a simple experiment to evaluate the accuracy of the timestamps issued by usb_cam when publishing the images. It seems that the timestamps are not necessarily very accurate. Does anybody know how to fix this?

SETUP:
I have a node publishing to a topic the current rostime which is then printed to the screen with rostopic echo. My usb camera is facing the screen and I use usb_cam to stream the images. The raw (compressed) images are written to a file with rosbag. The point of the setup is to compare the timestamp that can be seen on the image (acquisition time) with the timestamp of the corresponding image message when replaying the rosbag. The parameters input into usb_cam (width=1280, height=1024, fps=30, and pixel_format="mjpeg") are consistent with what is prescribed by v4l2-ctl --list-formats-ext.

RESULT:
There is systematically a significant offset (around 0.15s for this setup) between the timestamp and the actual time acquisition time as can be seen below. This offset varies as function of the resolution of the image and the selected fps.
screenshot from 2017-06-29 19 43 13

high CPU usage

Hello,
I'm running the usb_cam node on ODROID U3 (quad core 1.7GHz ARM, 2G RAM) with a Logitech C920. I noticed that this node by itself is using about 120% of CPU. Is it normal? Are there ways to optimize it? This is the launch file:

<launch>
<node name="camera" pkg="usb_cam" type="usb_cam_node" respawn="false" output="screen">
<param name="video_device" value="/dev/video0"/>
<param name="io_method" value="mmap"/>
<param name="image_width" value="640"/>
<param name="image_height" value="480"/>
<param name="color_mode" value="mono8"/>
<param name="pixel_format" value="yuyv"/>
</node>
</launch>

Thanks!

Catkin_make failure

I followed the step, But I get such error:
CMake Error at /opt/ros/indigo/share/catkin/cmake/assert.cmake:17 (message):

Assertion failed: check for file existence, but filename
(RT_LIBRARY-NOTFOUND) unset. Message: RT Library

Call Stack (most recent call first):
/opt/ros/indigo/share/catkin/cmake/tools/rt.cmake:42 (assert_file_exists)
/opt/ros/indigo/share/catkin/cmake/all.cmake:147 (include)
/opt/ros/indigo/share/catkin/cmake/catkinConfig.cmake:20 (include)
CMakeLists.txt:52 (find_package)

-- Configuring incomplete, errors occurred!
See also "/home/darwin/work/ros_ws/usbcam_ws/build/CMakeFiles/CMakeOutput.log".
See also "/home/darwin/work/ros_ws/usbcam_ws/build/CMakeFiles/CMakeError.log".
Invoking "cmake" failed

What should I do?

Node doesn't shutdown when SIGINT -2 kill is received

On Raspberry Pi, when node is run, killed with a Ctrl-C and then re-ran, gives the following error: VIDIOC_S_FMT error 5, Input/output error because node doesn't release video device since a.spin() never returns. Requires restarting the Raspberry pi before node can be run again.

Self Test

Hi,

I noticed the one line for self test is commented out but self test is still included. I am having problems cross compiling self-test and was wonder if you can remove requirement for self-test?

Thanks

Compilation fails on Arch Linux

While packaging the latest release of usb_cam on Arch Linux, I stumbled across the following error:

Scanning dependencies of target usb_cam
[ 50%] Building CXX object CMakeFiles/usb_cam.dir/src/usb_cam.cpp.o
/tmp/usb_cam/src/usb_cam/src/usb_cam.cpp: In function ‘int init_mjpeg_decoder(int, int)’:
/tmp/usb_cam/src/usb_cam/src/usb_cam.cpp:284:16: error: ‘avcodec_init’ was not declared in this scope
   avcodec_init();
                ^
/tmp/usb_cam/src/usb_cam/src/usb_cam.cpp:294:43: error: ‘avcodec_alloc_context’ was not declared in this scope
   avcodec_context = avcodec_alloc_context();
                                           ^
/tmp/usb_cam/src/usb_cam/src/usb_cam.cpp:313:44: error: ‘avcodec_open’ was not declared in this scope
   if (avcodec_open(avcodec_context, avcodec) < 0)
                                            ^

This is probably due to changes in ffmpeg:

$ ffmpeg --version
ffmpeg version 2.1.4

Published topics are a bit wonky

The ROS wiki ( http://wiki.ros.org/usb_cam ) says that images will be published on ~<camera_name>/image, when in fact they will be published on ~/image_raw (the camera_name parameter is not used at all for the topics).

It's also a bit odd to use a private node handle for advertising topics. The more common thing to do is to use public node handles for publishing/subscribing, and to use private node handles for reading parameters. Then if people want to put the topics into a namespace, they can use the ns="foo" attribute in the node element in the launchfile.

Weird framerate problems on Odroid U3

@bosch-ros-pkg,

I am using the usb_cam node on the odroid u3 to get video from a Logitech c270. I was able to acheive 800x600 and 1280x960 @ 30 and 25fps respectively by using MJPG format.

I did this by using
odroid@odroid-server:~$ v4l2-ctl -d /dev/video6 --set-fmt-video=width=800,height=600,pixelformat=MJPG

before starting the usb_cam node. Rostopic showed that the image was published @ 30Hz.

The thing is, after rebooting the computer, I haven't been able to achieve the same framerate, even after trying literally 100 times. The image is published at only 15Hz. Also, when I try setting other framerates like 20fps in the node, I only get half of it like 10fps or so.

PLEASE HELP!!

/usb_cam/image_raw/compressed is not published

I'm running usb_cam, but the topic /usb_cam/image_raw/compressed is never started/published.
Since I want to record (using rosbag) the camera feed, I want to use the compressed format since the raw data is really big.

What might be happening?

Problem with <param name="pixel_format" value="mjpeg" />

Hi alls,
I tried to get video in mjpeg format, however, I always got

Webcam: expected picture but didn't get it...

If I put yuyv instead of mjpeg, it is ok.

What can I do in order to got mjpeg format?

Any suggests or advices are well come. Thanks

Re-open failure with ELP-USB500W02M

===Summary===
Opening camera with roslaunch usb_cam usb_cam-test.launch works, but after closing it, I cannot launch the launch file again successfully unless I unplug and re-plug in the camera I am using (ELP-USB500W02M).

===Details===
After attempting to launch the launch file the second time, the window appears as so:
image

Here is the output, with an attempt to close with ctrl+c:
image
NOTE: The camera calibration file warning appears even when the camera view works (on the first attempt)

My launch file:
image

===System Info===

  • Dell XPS 15 9560
  • Ubuntu 16.04
  • ROS Kinetic

camera compatible(Driver Info (not using libv4l2))

cannot work with my usb-camera, but it works well with the camera on Laptop
on my desktop, the result is
sean@sean:~/catkin_ws2$ rosrun usb_cam usb_cam_node video_device:=/dev/video0
[ INFO] [1478762088.909523506]: using default calibration URL
[ INFO] [1478762088.909587553]: camera calibration URL: file:///home/sean/.ros/camera_info/head_camera.yaml
[ INFO] [1478762088.909645960]: Unable to open camera calibration file [/home/sean/.ros/camera_info/head_camera.yaml]
[ WARN] [1478762088.909670478]: Camera calibration file /home/sean/.ros/camera_info/head_camera.yaml not found.
[ INFO] [1478762088.909700946]: Starting 'head_camera' (/dev/video0) at 640x480 via mmap (mjpeg) at 30 FPS
[ WARN] [1478762089.207429365]: unknown control 'focus_auto'

Segmentation fault (core dumped)

while, on my laptop , it can will fail to open /dev/video1, and then switch to /dev/video0(which is work well )
below is the infomation about my usb-camera, I am wondering that My USB-Camera is not compatible
sean@sean:~/catkin_ws2$ v4l2-ctl --all
Driver Info (not using libv4l2):
Driver name : uvcvideo
Card type : Microsoft® LifeCam HD-3000
Bus info : usb-0000:00:14.0-7
Driver version: 3.16.7
Capabilities : 0x84000001
Video Capture
Streaming
Device Capabilities
Device Caps : 0x04000001
Video Capture
Streaming
Priority: 2
Video input : 0 (Camera 1: ok)
Format Video Capture:
Width/Height : 640/480
Pixel Format : 'YUYV'
Field : None
Bytes per Line: 1280
Size Image : 2257887232
Colorspace : SRGB
Crop Capability Video Capture:
Bounds : Left 0, Top 0, Width 640, Height 480
Default : Left 0, Top 0, Width 640, Height 480
Pixel Aspect: 1/1
Streaming Parameters Video Capture:
Capabilities : timeperframe
Frames per second: 0.003 (1/349)
Read buffers : 0
brightness (int) : min=30 max=255 step=1 default=133 value=66
contrast (int) : min=0 max=10 step=1 default=5 value=10
saturation (int) : min=0 max=200 step=1 default=83 value=50
white_balance_temperature_auto (bool) : default=1 value=1
power_line_frequency (menu) : min=0 max=2 default=2 value=2
white_balance_temperature (int) : min=2800 max=10000 step=1 default=4500 value=4500 flags=inactive
sharpness (int) : min=0 max=50 step=1 default=25 value=50
backlight_compensation (int) : min=0 max=10 step=1 default=0 value=0
exposure_auto (menu) : min=0 max=3 default=1 value=3
exposure_absolute (int) : min=5 max=20000 step=1 default=156 value=156 flags=inactive
pan_absolute (int) : min=-201600 max=201600 step=3600 default=0 value=0
tilt_absolute (int) : min=-201600 max=201600 step=3600 default=0 value=0
zoom_absolute (int) : min=0 max=10 step=1 default=0 value=0

Camera FLIP / ROTATE Support

TLDR: Would be good to have FLIP / ROTATE Support by means of ROS parameters.

So, I tested everything and it worked fine, then I placed/fixed the cameras on my robot and the view is rotated.

I looked at options, rotate_image and others, but I think this needs to be done at the camera acquisition level, I tried doing something, so modified the code and added CVBRIDGE, used OpenCV code to rotate the video and then re-publish as the ROS Message.

Now, I will fork and commit my changes for review - but putting it here for easy review for now:

  bool take_and_send_image()
  {
    // grab the image
    cam_.grab_image(&img_);

    cv_bridge::CvImagePtr cv_ptr; // pointer for image
    cv_bridge::CvImagePtr cv_ptr_flip; // pointer for image - another copy
    try
    {
      cv_ptr = cv_bridge::toCvCopy(img_, "bgr8");
      cv_ptr_flip = cv_bridge::toCvCopy(img_, "bgr8");
    }
    catch (cv_bridge::Exception& e)
    {
      ROS_ERROR("cv_bridge exception: %s", e.what());
      return false;
    }
    // Update GUI Window
    if(img_flip_) // flip if flip parameter is TRUE
        cv::flip(cv_ptr->image, cv_ptr_flip->image, img_flip_mode_);    // -1 = 180

    // grab the camera info
    sensor_msgs::CameraInfoPtr ci(new sensor_msgs::CameraInfo(cinfo_->getCameraInfo()));
    ci->header.frame_id = img_.header.frame_id;
    ci->header.stamp = img_.header.stamp;

    cv_ptr_flip->toImageMsg(img_); // convert back to ROS MSG

    // publish the image
    image_pub_.publish(img_, *ci);
    return true;
  }

Release for kinetic

The current development version (f80cff3) is building and running successfully on ROS kinetic (Ubuntu 16.04).

Can this package be released to the official rosdistro for kinetic?
This would also solve issues #56 #53 .

usb_cam with ffmpeg 3.0 incompatibility

Seems that a few things changes with avcodec/ffmpeg:

/opt/ros/ros_catkin_ws/src/usb_cam/src/usb_cam.cpp: In member function 'int usb_cam::UsbCam::init_mjpeg_decoder(int, int)':
/opt/ros/ros_catkin_ws/src/usb_cam/src/usb_cam.cpp:378:41: error: 'avcodec_alloc_frame' was not declared in this scope
avframe_camera_ = avcodec_alloc_frame();

full log:
usb_cam_error.txt

relationship to libuvc_camera ?

Please excuse me if this question is overly direct/rude, but: Any comments about how this compares to libuvc_camera? Care to add them to the README? I'm guessing wildly here: prehaps this is for all those cameras that cannot talk UVC correctly ???

I'm not quite sure, I think the uvc_camera code can be found here: https://github.com/ktossell/camera_umd .. maybe . Documentation is not quite clear about it.

No way to filter camera by product and brand id

Hi,
I am a new user to this package and i did not find any way to filter properly which camera to use. This can be a problem when the video device name is inconsistent.
There should be a way of filtering by product and brand id (like the uvc driver similar package).
As a workaround I created a simlink with a udev rule but I get a error when trying to open it:

/dev/bottom_front_cam is no V4L2 device
[usb_cam-2] process has died

Any suggestion or I would need to dig on the source code?

Is usb_cam supposed to publish camera_info messages?

Hello,

I found that your usb_cam driver works very nicely with a number of webcams under ROS Indigo and Ubuntu 14.04. However, it appears that the camera_info message being published by the driver is all zeros. In particular, it does not appear to publish the frame height and width. Is this a bug or is the driver not designed to publish this info?

Thanks!
patrick

ERROR Compressed Depth Image Transport

running usb_cam (newest version), Ubuntu 14.04, ROS Indigo

Error occurs after recording data with rosbag record -a

SUMMARY
========

PARAMETERS
 * /image_view/autosize: True
 * /rosdistro: indigo
 * /rosversion: 1.11.19
 * /usb_cam/camera_frame_id: usb_cam
 * /usb_cam/image_height: 480
 * /usb_cam/image_width: 640
 * /usb_cam/io_method: mmap
 * /usb_cam/pixel_format: yuyv
 * /usb_cam/video_device: /dev/video0

NODES
  /
    image_view (image_view/image_view)
    usb_cam (usb_cam/usb_cam_node)

ROS_MASTER_URI=http://localhost:11311

core service [/rosout] found
process[usb_cam-1]: started with pid [30444]
process[image_view-2]: started with pid [30445]
[ INFO] [1465419489.717901867]: Using transport "raw"
[ INFO] [1465419489.953802266]: using default calibration URL
[ INFO] [1465419489.953882988]: camera calibration URL: file:///home/rcac/.ros/camera_info/head_camera.yaml
[ INFO] [1465419489.953986649]: Unable to open camera calibration file [/home/rcac/.ros/camera_info/head_camera.yaml]
[ WARN] [1465419489.954051934]: Camera calibration file /home/rcac/.ros/camera_info/head_camera.yaml not found.
[ INFO] [1465419489.954087595]: Starting 'head_camera' (/dev/video0) at 640x480 via mmap (yuyv) at 30 FPS
[ WARN] [1465419490.113573670]: unknown control 'focus_auto'

[ERROR] [1465419494.835902836]: Compressed Depth Image Transport - Compression requires single-channel 32bit-floating point or 16bit raw depth images (input format is: rgb8).

Do you know a solution?

[ERROR] [1529929307.814365739]: select timeout

lee@lee-virtual-machine:~$ roslaunch usb_cam usb_cam-test.launch
... logging to /home/lee/.ros/log/514c360c-7872-11e8-87f0-000c2941b815/roslaunch-lee-virtual-machine-10288.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://192.168.206.146:38513/

SUMMARY

PARAMETERS

  • /image_view/autosize: True
  • /rosdistro: kinetic
  • /rosversion: 1.12.13
  • /usb_cam/camera_frame_id: usb_cam
  • /usb_cam/image_height: 480
  • /usb_cam/image_width: 640
  • /usb_cam/io_method: mmap
  • /usb_cam/pixel_format: yuyv
  • /usb_cam/video_device: /dev/video0

NODES
/
image_view (image_view/image_view)
usb_cam (usb_cam/usb_cam_node)

auto-starting new master
process[master]: started with pid [10298]
ROS_MASTER_URI=http://192.168.206.146:11311

setting /run_id to 514c360c-7872-11e8-87f0-000c2941b815
process[rosout-1]: started with pid [10311]
started core service [/rosout]
process[usb_cam-2]: started with pid [10322]
process[image_view-3]: started with pid [10329]
[ INFO] [1529929302.573080363]: using default calibration URL
[ INFO] [1529929302.573316916]: camera calibration URL: file:///home/lee/.ros/camera_info/head_camera.yaml
[ INFO] [1529929302.573445173]: Unable to open camera calibration file [/home/lee/.ros/camera_info/head_camera.yaml]
[ WARN] [1529929302.573504926]: Camera calibration file /home/lee/.ros/camera_info/head_camera.yaml not found.
[ INFO] [1529929302.573536692]: Starting 'head_camera' (/dev/video0) at 640x480 via mmap (yuyv) at 30 FPS
[ WARN] [1529929302.808683355]: unknown control 'focus_auto'

[ INFO] [1529929302.820050806]: Using transport "raw"
[ERROR] [1529929307.814365739]: select timeout
[usb_cam-2] process has died [pid 10322, exit code 1, cmd /opt/ros/kinetic/lib/usb_cam/usb_cam_node __name:=usb_cam __log:=/home/lee/.ros/log/514c360c-7872-11e8-87f0-000c2941b815/usb_cam-2.log].
log file: /home/lee/.ros/log/514c360c-7872-11e8-87f0-000c2941b815/usb_cam-2*.log

Release for Hydro?

We were using usb_cam from source with Hydro, and it worked well. Could this be released for Hydro too?

outbuf size mismatch; YUV420P vs. YUV422P

I'm getting errors of the form:

[ERROR] ros.usb_cam: outbuf size mismatch. pic_size: 720000 bufsize: 960000

I believe that this is because libavcodec is returning frames with YUV 4:2:0 pixels (1.5 bytes/pixel), but the buffer size is allocated for YUV 4:2:2 pixels (2 bytes per pixel). If I replace AV_PIX_FMT_YUV422P with AV_PIX_FMT_YUV420P in the following line the problem is resolved.

avframe_camera_size_ = avpicture_get_size(AV_PIX_FMT_YUV422P, image_width, image_height);

I'm not sure what the fix is here. I doubt just replacing AV_PIX_FMT_YUV422P with AV_PIX_FMT_YUV420P works for all cameras.

segmentation fault on hydro

[ 50%] Building CXX object usb_cam/CMakeFiles/usb_cam.dir/src/usb_cam.cpp.o
c++: internal compiler error: Segmentation fault (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See file:///usr/share/doc/gcc-4.6/README.Bugs for instructions.
make[2]: *** [usb_cam/CMakeFiles/usb_cam.dir/src/usb_cam.cpp.o] Error 4
make[1]: *** [usb_cam/CMakeFiles/usb_cam.dir/all] Error 2
make: *** [all] Error 2
Invoking "make" failed
rushi@rushi-pc:ros_ws$ catkin_make -DCATKIN_WHITELIST_PACKAGES=usb_cam >>error.txt
c++: internal compiler error: Segmentation fault (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See file:///usr/share/doc/gcc-4.6/README.Bugs for instructions.
make[2]: *** [usb_cam/CMakeFiles/usb_cam.dir/src/usb_cam.cpp.o] Error 4
make[1]: *** [usb_cam/CMakeFiles/usb_cam.dir/all] Error 2
make: *** [all] Error 2
Invoking "make" failed

usb_cam use web camera not usb camera

i changed camera_frame_id parameter to usb_camera no use.
i connected usb camera to my laptop. but still it use my web camera. i have creative camera.

Change fps and size online

Hello,
do you think it is possible to change FPS and size of the image runtime?
Or when the sensor get initialized then it is impossible to change?

Invalid camera calibration URL

After calibrating my camera using camera_calibration, I saved the calibration file.

The calibration file - Gsou.yaml looks like this:

Gsou.yaml.txt

Then I restart the usb_camera:
usb_cam.launch.txt

However, it always says, 'Invalid camera calibration URL: home/xx/catkin_ws/src/usb_cam/param/Gsou.yaml', is there anything wrong? please provide some help, thansk.

Problem launching usb_cam with mjpeg pixel format

Hi,

I am trying to integrate my webcam with this driver.

The webcam is a Logitech C922. It supports 60fps at 720p, however only in MJPEG format.

When setting pixel format to mjpeg, I get the following output:

nvidia@nvidia:~$ roslaunch usb_cam webcam_left.launch 
... logging to /home/nvidia/.ros/log/b7557f3c-72ee-11e8-8aa0-00044b8d995f/roslaunch-nvidia-4857.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://nvidia:38662/

SUMMARY
========

PARAMETERS
 * /rosdistro: kinetic
 * /rosversion: 1.12.12
 * /webcam_left/auto_white_balance: True
 * /webcam_left/autoexposure: True
 * /webcam_left/camera_frame_id: usb_cam
 * /webcam_left/camera_info_url: file://${ROS_HOME...
 * /webcam_left/camera_name: webcam_left
 * /webcam_left/framerate: 60
 * /webcam_left/image_height: 720
 * /webcam_left/image_width: 1280
 * /webcam_left/io_method: mmap
 * /webcam_left/pixel_format: mjpeg
 * /webcam_left/video_device: /dev/video0

NODES
  /
    webcam_left (usb_cam/usb_cam_node)

ROS_MASTER_URI=http://localhost:11311

process[webcam_left-1]: started with pid [4875]
[ INFO] [1529323613.028018588]: camera calibration URL: file:///home/nvidia/.ros/camera_info/cal_webcam_left.yml
[ INFO] [1529323613.030089656]: Starting 'webcam_left' (/dev/video0) at 1280x720 via mmap (mjpeg) at 60 FPS
[mjpeg @ 0x5e2670] Changeing bps to 8
[swscaler @ 0x5ec160] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5ec160] No accelerated colorspace conversion found from yuv422p to rgb24.

The last lines repeat indefinitely.

I have looked into #67, however the solution didn't work for me.

Garbled image problem on usb_cam

@bosch-ros-pkg
I am testing usb_cam_node with a usb camera, when I use the follow launch file, everything is ok,

<launch>
    <node name="camera" pkg="usb_cam" type="usb_cam_node" output="screen">
        <param name="video_device" value="/dev/video0" />
        <param name="image_width" value="640" />
        <param name="image_height" value="480" />
        <param name="pixel_format" value="yuyv" />
        <param name="framerate" value="30" />
        <param name="camera_frame_id" value="usb_cam" />
        <param name="io_method" value="mmap" />
        <param name="camera_info_url" type="string" value="file://$(find pixhawk)/launch/camera.yaml" />
    </node>

    <node name="viewer" pkg="image_view" type="image_view" output="screen">
        <remap from="image" to="/camera/image_raw" />
    </node>
</launch>

but when I change pixel_format to mjpeg, the video become garbled

garbled

v4l2-ctl --list-format-ext -d /dev/video0 output:

ioctl: VIDIOC_ENUM_FMT
    Index       : 0
    Type        : Video Capture
    Pixel Format: 'MJPG' (compressed)
    Name        : MJPEG
        Size: Discrete 1920x1080
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 1280x720
            Interval: Discrete 0.017s (60.000 fps)
        Size: Discrete 1024x768
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 640x480
            Interval: Discrete 0.008s (120.101 fps)
        Size: Discrete 800x600
            Interval: Discrete 0.017s (60.000 fps)
        Size: Discrete 1280x1024
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 320x240
            Interval: Discrete 0.008s (120.101 fps)

    Index       : 1
    Type        : Video Capture
    Pixel Format: 'YUYV'
    Name        : YUV 4:2:2 (YUYV)
        Size: Discrete 1920x1080
            Interval: Discrete 0.167s (6.000 fps)
        Size: Discrete 1280x720
            Interval: Discrete 0.111s (9.000 fps)
        Size: Discrete 1024x768
            Interval: Discrete 0.167s (6.000 fps)
        Size: Discrete 640x480
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 800x600
            Interval: Discrete 0.050s (20.000 fps)
        Size: Discrete 1280x1024
            Interval: Discrete 0.167s (6.000 fps)
        Size: Discrete 320x240
            Interval: Discrete 0.033s (30.000 fps)

And the error message:

[mjpeg @ 0x223e460] overread 8
[mjpeg @ 0x223e460] error count: 68
[mjpeg @ 0x223e460] error y=38 x=1
[mjpeg @ 0x223e460] error count: 64
[mjpeg @ 0x223e460] error y=34 x=1
[mjpeg @ 0x223e460] error count: 68
[mjpeg @ 0x223e460] error y=40 x=4
[mjpeg @ 0x223e460] error count: 64
[mjpeg @ 0x223e460] error y=42 x=1
[mjpeg @ 0x223e460] error count: 64
[mjpeg @ 0x223e460] error y=31 x=0
[mjpeg @ 0x223e460] error count: 64
[mjpeg @ 0x223e460] error y=30 x=37

My testing enviroment:
Ubuntu 14.04.3
ROS indigo
I've search almost the whole web, can't figure it out, please help! Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.