Code Monkey home page Code Monkey logo

node-ueye's Introduction

node-ueye

Unoffical Node.js Binding (ffi-based) for uEye Camera-Library from Imaging Development Systems GmbH

Notice: This module requires nodejs 4+. The examples use the ES6/generator pattern to simplify the excessive async code. You can read more about this pattern here. As wrapper we use the excellent co library, but any generator/promise wrapper could be used. All async methods return a ES6 Promise-object and you could also use the standard then/catch methodology.

synopsis

const Camera = require('ueye');
const co = require('co');
const path = require('path');

const cam = new Camera();

co(function* () {
    console.log('Initialize cam');
    yield cam.init();
    console.log('Initialized');

    const sensorInfo = yield cam.getSensorInfo();
    const maxImageSize = yield cam.getMaxImageSize(sensorInfo);
    console.log('MaxImageSize', maxImageSize);

    yield cam.setColorMode(cam.def.IS_CM_BGR8_PACKED);

    yield cam.aoiImageSetSize(maxImageSize);
    yield cam.setDisplayMode(cam.def.IS_SET_DM_DIB);

    const seq = yield cam.allocImageMem(maxImageSize, 24);
    yield cam.setImageMem(seq);

    console.log('New framerate:', yield cam.setFrameRate(3));
    
    console.log('Start capturing');
    yield cam.freezeVideo(cam.def.IS_WAIT);

    console.log('Captured!');

    const res = yield cam.getImageMem();

    yield cam.imageFile({
        pwchFileName: path.join(__dirname, '../out/test.png'),
        nFileType: cam.def.IS_IMG_PNG,
        ppcImageMem: res.mem,
        pnImageID: res.id,
        nQuality: 0,
    })

    yield cam.exit();
}).catch((ex) => {
    console.error('Exception:', ex);

    cam.exit().then(() => {
        process.exit();
    });
});

installation

  $ npm install ueye

ueye/sdl2

You can test the live performance of your ueye camera with the liveSDL example located in the examples folder.

installation

You need to install the sdl2 system-libraries (including sdl2-image and sdl2-ttf) and the node-sdl2 npm package.

apt-get install libsdl2 libsdl2-image libsdl2-ttf # This may differ on your distro
npm install node-sdl2
node examples/liveSDL

bindings and defines

The ffi-bindings are directly accessible via the binding attribute of the Camera class. For many library functions exist a convenient wrapper-function. If not, you can access the functions directly via the binding attribute.

Let's implement a call to the native is_Saturation function:

const Camera = require('ueye');
const ref = require('ref');

const cam = new Camera();

cam.init().then(() => {
    const saturation = ref.alloc('int', 0);
    const minSaturation = ref.alloc('int', 0);
    const maxSaturation = ref.alloc('int', 0);

    let nRet = cam.binding.is_Saturation (cam.hCam, cam.def.SATURATION_CMD_GET_VALUE, saturation, ref.sizeof.int);
    nRet = nRet || cam.binding.is_Saturation (cam.hCam, cam.def.SATURATION_CMD_GET_MIN_VALUE, minSaturation, ref.sizeof.int);
    nRet = nRet || cam.binding.is_Saturation (cam.hCam, cam.def.SATURATION_CMD_GET_MAX_VALUE, maxSaturation, ref.sizeof.int);

    console.log(`Saturation min/max/current (errcode): ${minSaturation.deref()}/${maxSaturation.deref()}/${saturation.deref()} (${nRet})`);

    cam.exit().then(() => {
    });
});

Notice: The is_Saturation calls here are called in a synchronous manner. To call async use the ffi-async way: cam.binding.is_Saturation.async(...).

node-ueye's People

Contributors

d0m1n1kr avatar

Watchers

James Cloos avatar  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.