npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ptz

v0.0.7

Published

ptz

Downloads

50

Readme

Build Status

PTZ

A camera control module for pan/tilt/zoom operations. Oh yea, in nodejs.

Installing

Install dependencies first (see below).

npm install ptz

Goals

Works with any plug & play UVC camera to perform pan/tilt/zoom operations.

Reference

var ptz = require('ptz');

List Devices

ptz.listDevices(function(err, devices){
    devices.forEach(function(device){
        console.log(device.type, device.vendorId, device.productId, device.description);
    });
});

Or, using promises. Generally, all operations can be done via callback or promises, whatever floats your boat :)

ptz.listDevices().then(function(devices){
    devices.forEach(function(device){
        console.log(device.type, device.vendorId, device.productId, device.description);
    });
});

Get Camera Instance

Before any operations can be performed, get a camera instance using the code below. The camera details can be retrieved from listDevices(). Then you can call getCapabilities() to see what operations are supported by the camera.

var camera = ptz.getCamera({
    vendorId: 0, // use 0 to get the first camera
    productId: 0 // use 0 to get the first camera
});

// perform ptz operations here, or get camera ptz capabilities
camera.getCapabilities().then(function(capabilities){
    console.log(capabilities);
});

Pan/Tilt/Zoom Operations

Let's get to the fun part.

Zoom

There are two methods of performing zoom operations, absolute and relative.

Absolute allows you to specify the exact zoom level to go to and the camera goes there regardless of current zoom level.

Relative lets you send a zoom-in or zoom-out commands, then the camera will beginning changing its zoom level towards that direction. Once its where you want it to be, send a stop command.

Absolute Zoom

// Get the camera's zoom info so you know the min, max, and resolution values for zoom level.
camera.getAbsoluteZoom().then(function(zoom){
    console.log(zoom);

    var zoomLevel = 10; // must be between min and max and divisible by resolution, without remainder.
    camera.absoluteZoom(zoomLevel).then(function(){
        console.log('absolute zoom command sent!');
    });
});

Relative Zoom

// Get the camera's zoom info so you know the min, max, and resolution values for speed.
camera.getRelativeZoom().then(function(zoom){
    console.log(zoom);

    var speed = 10; // must be between min and max and divisible by resolution, without remainder.
    camera.relativeZoomIn(speed).then(function(){
        console.log('relative zoom-in command sent!');
        camera.relativeZoomStop().then(function(){ // usually we would wait for a bit before stopping
            console.log('relative zoom stop command sent!');
            camera.relativeZoomOut(speed).then(function(){
                console.log('relative zoom-out command sent!');
                camera.relativeZoomStop().then(function(){
                    console.log('relative zoom stop command sent!');
                });
            });
        });
    });
});

Pan/Tilt

There are two methods of performing pan/tilt operations, absolute and relative. For some reason both pan and tilt go hand-in-hand in the UVC standards specification. We cannot change these two independently. We must provide both values together when sending commands to the device. They are like stuck together, like, well, glue.

Absolute allows you to specify the exact pan and tilt location to go to and the camera goes there regardless of current location.

Relative lets you send up, down, left, right commands, then the camera will beginning changing its location towards those directions. Once its where you want it to be, send a stop command.

Also, pan and tilt settings are in arc second units. 1 arc second is 1/3600 of a degree. Values range from –180*3600 arc second to +180*3600 arc second. Positive values are clockwise from the origin (the camera rotates clockwise when viewed from above), and negative values are counterclockwise from the origin. For tilt, positive values point the imaging plane up, and negative values point the imaging plane down.

Absolute Pan/Tilt

// Get the camera's pan and tilt info so you know the min, max, and resolution values for both.
camera.getAbsolutePanTilt().then(function(panTilt){
    console.log(panTilt);

    var pan = 90 * 3600;
    var tilt = 90 * 3600;
    camera.absolutePanTilt(pan, tilt).then(function(){
        console.log('absolute pan/tilt command sent!');
    });
});

Relative Pan/Tilt

// Get the camera's pan and tilt info so you know the min, max, and resolution values for both speeds.
camera.getRelativePanTilt().then(function(panTilt){
    console.log(panTilt);

    var pan_speed = 10; // must be between min and max and divisible by resolution, without remainder.
    var tilt_speed = 10; // must be between min and max and divisible by resolution, without remainder.
    var pan_direction = 1; // 1 right, -1 left, 0 no change
    var tilt_direction = 1; // 1 up, -1 down, 0 no change
    camera.relativePanTilt(pan_direction, pan_speed, tilt_direction, tilt_speed).then(function(){
        console.log('relative pan/tilt command sent!');
        camera.relativeZoomStop().then(function(){ // usually we would wait for a bit before stopping
            console.log('relative pan/tilt stop command sent!');
        });
    });
});

Install dependencies

Need to install libuvc on the machine first.

Mac

brew install libusb
mkdir -p ~/git
cd ~/git
git clone https://github.com/ktossell/libuvc
cd libuvc
mkdir build
cd build
cmake -D LIBUSB_INCLUDE_DIRS=/usr/local/Cellar/libusb/1.0.21/include/libusb-1.0 ..
make && sudo make install

Linux

sudo apt-get -qq update
sudo apt-get install -y libusb-1.0-0-dev
sudo apt-get install -y build-essential libudev-dev libtool cmake git
mkdir -p ~/git
cd ~/git
git clone https://github.com/ktossell/libuvc
cd libuvc
mkdir build
cd build
cmake -D LIBUSB_INCLUDE_DIRS=/usr/include/libusb-1.0 ..
make && sudo make install

Windows

Not supported

As A Side Note

Just as a side node, on every operation sent to the camera, a USB connection is opened and immediately closed. This is to minimize conflicts with the USB device and keep things easy to manage. We don't need to figure out how to keep USB connections open and maintain them.

Don't always trust the min max values from the cameras. For pan/tilt the min should always be (-180 * 3600) and max should be (180 * 3600). If these values are different, test the values before trusting them.