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

Garbled image problem on usb_cam

asked 2015-09-09 20:30:30 -0500

Allen Wong gravatar image

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

garble1 tarble2

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] 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
[mjpeg @ 0x223e460] overread 8

My testing enviroment: Ubuntu 14.04.3, ROS indigo

I've search almost the whole web, can't figure it out, please help! Thanks

edit retag flag offensive close merge delete

5 Answers

Sort by ยป oldest newest most voted
1

answered 2015-10-19 07:12:47 -0500

taogashi gravatar image

updated 2015-10-20 03:12:27 -0500

Hi Allen!

I found that this problem is caused by linking wrong libraries. Try

ldd devel/lib/usb_cam/usb_cam_node

to see which lib is linked.

My ffmpeg was installed by apt-get from a ppa repository, the default location of such packages is /opt. But anyhow cmake didn't find the correct libavcodec and libswscale.

Later I install ffmpeg from source, install those libraries in /usr/local/lib, and manual set variable avcodec_LIBRARIES and INCLUDE_DIRS as:

## pkg-config libraries
# find_package(PkgConfig REQUIRED)
# pkg_check_modules(avcodec libavcodec REQUIRED)
# pkg_check_modules(swscale libswscale REQUIRED)

set(avcodec_LIBRARIES /usr/local/lib/libavcodec.so.57)
set(swscale_LIBRARIES /usr/local/lib/libswscale.so.4)
set(avcodec_INCLUDE_DIRS /usr/local/include/libavcodec)
set(swscale_INCLUDE_DIRS /usr/local/include/libswscale)

And, as the new version ffmpeg has changed some of its variable/function names, I have to modify the code of usb_cam. Lucky, only a little at the begin of usb_cam.cpp:

#define avcodec_alloc_frame av_frame_alloc
#define PIX_FMT_RGB24 AV_PIX_FMT_RGB24
#define PIX_FMT_YUV422P AV_PIX_FMT_YUV422P

Hope it helps!


Have you found the solution? I encountered exactly the same problem... the same ubuntu, the same indigo, my ffmpeg is something like:

ffmpeg version N-76045-g97be5d4 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libdcadec --enable-libfreetype --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvo-aacenc --enable-libvidstab
libavutil      55.  4.100 / 55.  4.100
libavcodec     57.  6.100 / 57.  6.100
libavformat    57.  4.100 / 57.  4.100
libavdevice    57.  0.100 / 57.  0.100
libavfilter     6. 11.100 /  6. 11.100
libavresample   3.  0.  0 /  3.  0.  0
libswscale      4.  0.100 /  4.  0.100
libswresample   2.  0.100 /  2.  0.100
libpostproc    54.  0.100 / 54.  0.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
edit flag offensive delete link more

Comments

Hi, can you specify the detail of installing the ffmpeg from source? I've tried to do that with this link: http://trac.ffmpeg.org/wiki/Compilati... but didn't come with success. The YUYV format just doesn't work with Full HD cameras (only 2 FPS!). Thanks!

EwingKang gravatar image EwingKang  ( 2015-12-02 04:02:01 -0500 )edit
0

answered 2015-10-19 08:29:21 -0500

In cases like this I'd recommend trying out things with another method to access the camera. For instance, you can check if the image looks ok with guvcview. If it looks ok, there's some likelihood that you can make things work by using a different driver or modifying the one you've been using. If things don't work with an alternative solution either, it is likely that the camera might not conform to existing standards and making it work would be much harder (or impossible). Note that for most webcams there are multiple ROS drivers that you can try out, like usb_cam, gscam or libuvc_camera.

edit flag offensive delete link more

Comments

Yeah, I tried that. The camera is OK. And I fixed it by rewrote mjpeg2rgb function with libjpeg. Thanks for replying.

Allen Wong gravatar image Allen Wong  ( 2016-06-09 07:53:30 -0500 )edit
0

answered 2016-03-31 00:51:04 -0500

I encounter this problem too.I successfully fix this problem according to taogashi's solution. When you build the ffmpeg from source,you should configure it correctly to avoid the "relocation R_X86_64_32 against" Error.And next is my configure scheme:

./configure --enable-shared --enable-pic --extra-cflags="-fPIC"
make -j8
sudo make install
edit flag offensive delete link more

Comments

Thanks for replying. I will have a try.

Allen Wong gravatar image Allen Wong  ( 2016-06-09 07:56:12 -0500 )edit
0

answered 2016-05-30 15:37:08 -0500

Hi !

I am working to on SVO (maybe the same project) and a have exactly the same issue ...

did you find a solution to this problem ?

edit flag offensive delete link more

Comments

After dive into the usb_cam code, I found problem happen in mjpeg2rgb function, so I wrote another mjpeg2rgb function with libjpeg. And it works.

Allen Wong gravatar image Allen Wong  ( 2016-06-09 07:50:57 -0500 )edit
1

Hi Allen, I'm also facing the exact same problem. Can you elaborate on the solution of rewriting mjpeg2rgb function ? Best regards

Rouno gravatar image Rouno  ( 2016-07-08 06:35:34 -0500 )edit

@Rouno Just replace the mjpeg2rgb function. Here is a example https://github.com/LuaDist/libjpeg/blob/master/example.c

You also need to add compile rules to CMakeLists.txt

Allen Wong gravatar image Allen Wong  ( 2016-07-08 20:33:54 -0500 )edit

Allen Wong: how about submitting your changes back to the usb_cam team, and/or posting a link to the whole source of your solution, rather than saying "Just" replace this function?

lukehutch gravatar image lukehutch  ( 2019-07-29 06:24:04 -0500 )edit
0

answered 2016-07-08 11:19:54 -0500

Rouno gravatar image

Hi everyone, I'm quite new to ROS and experienced also the same problem with Indigo & Ubuntu 14.04. Is there a simple yet step by step way of solving this ? I tried libuvc_camera package but my camera module doesn't seem to be uvc compliant.

Thx

edit flag offensive delete link more

Question Tools

4 followers

Stats

Asked: 2015-09-09 20:30:30 -0500

Seen: 7,801 times

Last updated: Jul 08 '16