Webcam

From Leo's Notes
Revision as of 03:07, 24 March 2015 by 10.1.1.22 (talk)
This page was last edited on 24 March 2015, at 03:07.

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 /dev/video0 device when the webcam is plugged into the computer. If not, check dmesg and see if the USB device is being detected. lsusb should also list it.

The default permissions set to /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 /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 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 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