I'm trying to find a way to save the .png images produced when streaming video from the AR-Drone. The following code that uses the ar-drone module by felixge successfully streams the video to a browser, but I would like to take a screen-shot of this feed and save it to my drive for real-time image analysis.
I am attempting to use the screenshot module to save what appears in my browser when I connect to the host, but all this does is save a blank white image of the size that I specify (see below code). Is there a better way to save a still frame from the AR-Drone video (NOT save the .h264 video feed)?
Thank you.
// Run this to receive a png image stream from your drone.
var arDrone = require('ar-drone'); //Call AR-drone module
var http = require('http'); //Allows video to be displayed to browser
var client = arDrone.createClient(); //Create AR-drone client--->IP address, video frame rate, image sizing
var pngStream = client.getPngStream(); //Fetch real-time video feed from quad
var fs = require('fs');
var screenshot = require('node-webkit-screenshot');
client.config('general:navdata_options', 777060865); //turn on GPS
client.config('video:video_channel',3); //Switch feed to downward-facing camera
var lastPng;
pngStream
.on('error', console.log)
.on('data', function(pngBuffer) {
lastPng = pngBuffer; //Store latest png still frame
});
var server = http.createServer(function(req, res) {
if (!lastPng) {
res.writeHead(503);
res.end('Did not receive any png data yet.');
return;
}
res.writeHead(200, {'Content-Type': 'image/png'});
res.end(lastPng);
});
server.listen(8080, function() {
console.log('Serving latest png on port 8080 ...');
})
screenshot({
url : 'http://localhost:8080',
width : 640,
height : 360
})
.then(function(buffer){
fs.writeFile('Drone.png', buffer, function(){
console.log('Screenshot saved') ;
screenshot.close();
});
});