Tuesday 16 May 2017

Convert raw image to buffer

There is apparently no easy way to stream images in Raspberry Pi. While there are many hacks available, in my Raspberry Pi Zero it has some trouble keeping a decent framerate.

I suspect one of the main problems is that the 1st Google solution and most of them writes/reads to the SD for each image. I've got so far to read from the terminal an image without touching the SD:

const out = await exec(`fswebcam -r 640x480 -`);
const img = out[0];
console.log(img);

This gives me this on the terminal:

 ����JFIF``��>CREATOR: gd-jpeg v1.0 (using IJG JPEG v80), default quality
��      

 $.' ",#(7),01444'9=82<.342��C          

And many more. Previously I was doing something similar with buffers:

const file = fs.readFileSync(temp);
console.log(file.toString('base64'));
ctx.socket.emit('frame', { image: true, buffer: file.toString('base64') });

Where file is a Buffer and file.toString('base64') is a string in the form of:

/9j/4AAQSkZJRgABAQEAYABgAAD//gA8Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2ODApLCBxdWFsaXR5ID0gMTAwCv ...

And this worked (but through the SD card). So my question is, what is the format of the first output in terminal? And how can I convert it to a Buffer or a String similar to the latter.



via Francisco Presencia

No comments:

Post a Comment