Code Monkey home page Code Monkey logo

node-raspistill's Introduction

node-raspistill

Build Status Coverage Status

Simple wrapper for taking photos using Raspberry Pi raspistill app.

Module is written in typescript and provides type definitions out-of-the-box.

Tested with Raspberry Pi 2 B (Raspbian OS), and Raspberry Camera Module v2.

Usage

npm install node-raspistill
const Raspistill = require('node-raspistill').Raspistill;
const camera = new Raspistill();

camera.takePhoto().then((photo) => {
    ...
});

Or (if you use imports):

import {Raspistill} from 'node-raspistill';
const camera = new Raspistill();

camera.takePhoto().then((photo) => {
    ...
});

You can also pass some options to constructor method:

const camera = new Raspistill({
    verticalFlip: true,
    width: 800,
    height: 600
});

See full options list in the docs below.

You can also find some usage examples here: https://github.com/dlukanin/node-raspistill/tree/master/examples

Changelog

v 0.0.12

Added raspistill stop method.

v 0.0.11

Timelapse mode. Something like beta version, can be unstable in some cases. Feel free to submit issue if you think that mode doesn't work well in your project.

v 0.0.10

Added noFileSave option. If you don't want to save photos on your raspberry pi - use this option.

Some bug fixes and new examples.

v 0.0.9

Fixed some issues with width/height options. Added setDefaultOptions method. Updated some dependencies.

v 0.0.8

Added noPreview option.

Docs

Raspistill

constructor(options?: ICameraOptions)

Creates new Raspistill instance.

Options - object, that can contain:

key type defaults desc
noFileSave boolean false Disables photos saving. If true - camera output will be directly sent as Buffer without saving on the drive
verticalFlip boolean false
horizontalFlip boolean false
noPreview boolean true Disables preview window on Pi while taking photo
outputDir string './photos' Output directory where photos will be stored
fileName string undefined Name for photo file. If undefined - photos file names will be calculated as new Date.now() + file encoding
encoding string 'jpg' 'jpg', 'bpm', 'gif' or 'png'
width number undefined Width of taken image in pixels. If width is not set - raspistill uses default max camera sensor resolution width
height number undefined Height of taken image in pixels. If height is not set - raspistill uses default max camera sensor resolution height
const camera = new Raspistill({
    verticalFlip: true,
    fileName: 'foo'
});

takePhoto(fileName?: string): Promise<Buffer>

Takes new photo. Returns Promise, resolving with Buffer object.

camera.takePhoto('testPhotoName').then((photo) => {
    ...
});

timelapse(fileName: string, intervalMs: number, execTimeMs: number, cb: (image: Buffer) => any): Promise<void>;

timelapse(intervalMs: number, execTimeMs: number, cb: (image: Buffer) => any): Promise<void>;

Runs camera in timelapse mode. Passes taken image picture as Buffer object to the callback. Raspistill options (passed into constructor or into setOptions method) are also applicable in this mode.

Remember that raspberry camera has it's own limits of taking photos speed even in timelapse mode.

Check out official raspistill docs (https://www.raspberrypi.org/documentation/raspbian/applications/camera.md) for file naming rules and interval/total exec time params usage.

camera.timelapse(500, 3000, (image) => {
    // got image from camera, do something
}).then(() => {
    // timelapse ended
}).catch((err) => {
    // something bad happened
});

or

camera.timelapse('image%04d', 500, 3000, (image) => {
    // got image from camera, do something
}).then(() => {
    // timelapse ended
}).catch((err) => {
    // something bad happened
});

stop(): void;

Tries to stop current raspistill running action. Note that pending raspistill promises will be rejected with RaspistillInterruptError if stop was completed.

const RaspistillInterruptError = require('node-raspistill').RaspistillInterruptError;

raspistill.timelapse(1000, 30000, (image) => {
    console.log('got photo, trying to stop raspistill');
    raspistill.stop();
})
    .then(() => {
        console.log('timelapse ended')
    })
    .catch((err) => {
        console.log(err instanceof RaspistillInterruptError) // true, raspistill was interrupted;
    });

setOptions(options: ICameraOptions): void

Sets new options for current Raspistill instance.

camera.setOptions({
    horizontalFlip: true,
    noPreview: false
});

setDefaultOptions(): void

Reverts all option values of current Raspistill instance to default. Default values are presented in the options table.

getOptions(): ICameraOptions

Gets current raspistill options.

getOption(key: string): any

Gets current raspistill option by key.

node-raspistill's People

Contributors

dlukanin avatar celaus avatar

Watchers

 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.