Giter Site home page Giter Site logo

node-uvc-control's Introduction

uvc-control

Control a USB Video Class compliant webcam from node. Most modern USB webcams use a common set of controls standardized by the USB Implementers Forum. You can use this set of controls to change certain things on the camera, such as the brightness, contrast, zoom level, focus and so on.

See also uvcc, which wraps uvc-control in a command line tool.

Example

const UVCControl = require('uvc-control')

// get the first camera by default
const camera = new UVCControl()
// or get a specific camera
const camera = new UVCControl({vid: 0x046d, pid: 0x082d})

camera.get('autoFocus').then(value) => console.log('AutoFocus setting:', value))
camera.set('brightness', 100).then(() => console.log('Brightness set!'))

For an interactive demo, run npm run serve and open http://localhost:3000.

Finding Your vendorId / productId

Use test/discover.js to find the right paramters.

$ node test/discover.js
[ { name: 'Logitech BRIO',
    vendorId: 1133,
    productId: 2142,
    deviceAddress: 7 },
  { name: 'Microsoft® LifeCam Studio(TM)',
    vendorId: 1118,
    productId: 1906,
    deviceAddress: 22 } ]

Installation

Libusb is included as a submodule.

On Linux, you'll need libudev to build libusb. On Ubuntu/Debian: sudo apt-get install build-essential libudev-dev

On Windows, use Zadig to install the WinUSB driver.

Then, just run npm install uvc-control

API

const UVCControl = require('uvc-control')

new UVCControl(options)

  • options - object containing options
  • options.vid - vendor id of your device
  • options.pid - product id of your device
  • options.deviceAddress - device address
const camera = new UVCControl(options)

List controls

Log the names of controls. You can get all controls, or a list of controls supported by the device.

UVCControl.controls.forEach(name => console.log(name))
console.log(cam.supportedControls)

camera.get( control_name )

Get the current value of the specified control by name.

camera.get('sharpness').then(value => console.log('sharpness', value))

camera.range( control_name )

Get the min and max value of the specified control by name. Some controls do not support this method.

camera.range('absolute_focus').then(range => {
  console.log(range) // { min: 0, max: 250 }
})

camera.set( control_name, value )

Set the value of the specified control by name.

camera.set('saturation', 100).then(() => console.log('saturation set!'))

camera.set( control_name, ...values )

Some controls have multiple fields. You can pass multiple values that align with the field offsets.

const pan = 34
const tilt = 27
camera.set('absolute_pan_tilt', pan, tilt).then(() => {
  console.log('absolute_pan_tilt set!')
})

camera.close()

Done? Good. Put away your toys and release the USB device.

camera.close()

Notes

You can find the full list of specs at the USB Implmentors Forum. Look for a document called USB Device Class Definition for Video Devices Revision 1.1 at their site here: http://www.usb.org/developers/docs/devclass_docs/ pdf mirror

To debug the USB descriptors, open chrome://usb-internals in Chrome

On Raspberry Pi, you need to run node as root in order to access USB devices. If you don't have access, you'll get a LIBUSB_ERROR_IO error on initialization. Alternatively, you can add a udev rule to grant access to the default user, as described in this AskUbuntu answer.

Pull requests and testers welcome!

Credits

Written by Pawel Szymczykowski and based on some Objective C examples by Dominic Szablewski found at http://phoboslab.org/log/2009/07/uvc-camera-control-for-mac-os-x. Maintained by Josh Beckwith.

node-uvc-control's People

Contributors

positlabs avatar makenai avatar cotejp avatar joelpurra avatar

Watchers

James Cloos avatar

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.