Skip to content
EddieCTian edited this page Mar 28, 2021 · 3 revisions

Webcam streaming on a Webserver

This section allows us to view a webcam's output on a different device on the same network.

Requirements:

  • ROS Melodic on Ubuntu 18.04
  • A UVC enabled camera (most integrated and standalone webcams)
  • Internet

NOTE: If you're using VM Virtualbox, you'll have to install an extension. Instructions here. Also, the virtual machine might not recognize the webcam, and you'll have to use a dual-boot system.

Camera setup

Installing programs:

sudo apt install udev v4l-utils net-tools ros-melodic-libuvc-camera ros-melodic-web-video-server -y

Type the following with the external webcam unplugged (if using).

ls /dev/video*

If you're using an integrated webcam, you'll probably want to use /dev/video0.

If you're using an external webcam, plug it in and run the above command again. The one that appears is the /dev/video# you want to use. You'll want to replace video# with your number.

udevadm info --name=/dev/video0 --attribute-walk | grep -E 'idProduct|idVendor'

The command will output a list of values. Remember the first idProduct and idVendor values.

sudo touch /etc/udev/rules.d/99-uvc.rules
sudo nano /etc/udev/rules.d/99-uvc.rules

In 99-uvc.rules file put

SUBSYSTEMS=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="####", ATTRS{idProduct}=="####", MODE="0666"

Where #### and #### are replaced with the respective values from above.

Now type

sudo udevadm control --reload-rules

and unplug then replug your camera. If you're using an integrated webcam, you may have to restart your computer.

This tells the Ubuntu device manager that this camera can be used by external programs.

Camera parameters

v4l2-ctl --list-formats-ext -d /dev/video0

replacing video0 as necessary.

It will show a bunch of possible output formats. We're only interested in Motion-JPEG. Keep these values handy as we'll use them later. A higher resolution/framerate is good for clarity, but bad for bandwidth.

ROS Setup

The code is currently in origin/feature/drive_control and might've graduated to origin/master.

On the corresponding branch:

cd ~/catkin_wc
git pull
catkin_make
source /opt/ros/melodic/setup.bash

You must change the params vendor and product in FILL ME IN/camera_webstream/launch/camera_webstream.launch to those in the 99-uvc.rules file.

You can change the params width, height and frame_rate to a combination listed in v4l2-ctl.

You can test out the camera locally with:

roslaunch camera.launch
rosrun rqt_image_view rqt_image_view

Then choosing /image_raw in the dropdown of the upper left corner of the rqt window.

Viewing the camera feed on a different computer

On the computer with the webcam:

roslaunch camera.launch
rosrun web_video_server web_video_server

You can modify the address or port of the server with the params _address:="#.#.#.#" and _port:=###

Find your ip address with arp -a. You're looking for an IPv4 address of the form [0-255].[0-255].[0-255].[0-255].

On a different computer on the same network

Visit http://{your ip address}:8080/ in your browser.

{your ip address} is determined above, or if you're using the same computer as the webcam computer it'll be 0.0.0.0.

8080 is the default port if you haven't changed the port number above.

Click on image_raw for a live feed or snapshot for a picture.

Adjust the resolution and framerate in camera.launch until suitable.

See more options at the web_video_server documentation.

Instructions adapted from: