Webcam

From Leo's Notes
Revision as of 19:13, 24 February 2017 by Leo (talk | contribs) (Text replacement - "<code>" to "{{code|")
This page was last edited on 24 February 2017, at 19:13.

Linux

To get a webcam working for Linux, ensure that it's supported. Newer webcams tend to have support though cheaper non-HD webcams from China might not. You should see a {{code|/dev/video0 device when the webcam is plugged into the computer. If not, check {{code|dmesg and see if the USB device is being detected. {{code|lsusb should also list it.

The default permissions set to {{code|/dev/video0 is set by udev. If you need to change the device permissions (say making it world read/writable), you will need to create a udev rule by creating a new file in {{code|/etc/udev/rules.d/ with the following contents:

SUBSYSTEM=="video4linux", BUS=="usb", SYSFS{idVendor}=="045e", SYSFS{idProduct}=="0761", NAME="video0", MODE="0666"

The Vendor ID and product ID must match the values from {{code|lsusb. For the example above (a Microsoft LifeCam VX-2000):

# lsusb
Bus 001 Device 005: ID 045e:0761 Microsoft Corp.


To capture images, use any one of the following utilities:

  • fswebcam
  • uvccapture

You may configure the webcam settings using {{code|v4l-utils. See http://www.techytalk.info/webcam-settings-control-ubuntu-fedora-linux-operating-system-cli/

fswebcam

fswebcam -r 640x480 --jpeg 85 -D 1 web-cam-shot.jpg

Dumping fswebcam images via HTTP

You can make a quick an dirty wrapper around the command above so that it can be viewed via the web.

<?php

system("fswebcam -r 640x480 --jpeg 85 -D 1 /tmp/out.jpg > /dev/null");
header("Content-Type: image/jpeg");
echo file_get_contents("/tmp/out.jpg");


uvccapture

Another utility to capture webcam images is {{code|uvccapture.