Take Raspistill Image NoFileSave in a loop (nodejs)

486 views Asked by At

I'm making a fun open sourced sample for doing Edge Compute Computer Vision using the Raspberry Pi as my hardware.

The current SDK I have to access hardware is nodejs based (I'll release a second with python when it is available). Warning: I am a node novice.

The issue I am facing is that I want to take pictures using the stock camera in a loop without saving a file. I just want to get access to the buffer, extract the pixels, pass to my second edge module.

Taking pictures with no file save in a while(true) loop appears to never execute.

Here is my sample:

'use strict';

var sleep = require('sleep');
const Raspistill = require('node-raspistill').Raspistill;
var pixel_getter = require('pixel-getter');


while(true) {

const camera = new Raspistill({ verticalFlip: true,
                            horizontalFlip: true,
                            width: 500,
                            height: 500,
                            encoding: 'jpg',
                            noFileSave: true,
                            time: 1 });

camera.takePhoto().then((photo) => {
    console.log('got photo');
    pixel_getter.get(photo,
               function(err, pixels) {
                    console.log('got pixels');
                    console.log(String(pixels));
                    });
    });
sleep.sleep(5);
}
console.log('picture taken');

In the above code, none of the console.log functions actually ever log; leading me to believe that photos are never taken and therefor pixels can not be extracted.

Any assistance would be greatly appreciated.


UPDATE: It looks like the looping mechanic might be funny. I guess I don't really care if it takes pictures in a loop as long as it takes a picture, I pass it off, I take a picture and I pass it off, indefinately.

1

There are 1 answers

1
David Crook On BEST ANSWER

I decided to approach the problem with a recursive loop instead which worked brilliantly.

'use strict';

const sleep = require('sleep');
const Raspistill = require('node-raspistill').Raspistill;
const pixel_getter = require('pixel-getter')

const camera = new Raspistill({ verticalFlip: true,
                            horizontalFlip: true,
                            width: 500,
                            height: 500,
                            encoding: 'jpg',
                            noFileSave: true,
                            time: 5 });

function TakePictureLoop() {
    console.log('taking picture');
    camera.takePhoto().then((photo) => {
        console.log('got photo');
        pixel_getter.get(photo, function(err, pixels) {
            console.log('got pixels');
            TakePictureLoop();
        });
    });
}

TakePictureLoop();