Some of this code can be obtained here: https://bitbucket.org/lizardworks/aztec-rekog1/overview
THE PROBLEM
After my house was broken into, I got a simple game camera and set it up to take pictures that would hopefully identify the recreants should they strike again. And so I wound up with lots of data footage that needs to be analyzed - over 600 AVI files. Rather than go through this like a diligent hard working detective, I decided to be lazy and automate it as much as I could using AWS's new service, Rekognition.
About Rekognition
Rekognition is an "AI" system that specializes in identifying possible objects in pictures. It identifies such as 'labels' and confidence value pairs. The console for this subsystem is actually tied to the demo, and is therefore not useful for general purposes.First Part - Creating snapshots from the .AVI footage
Pymedia seemed to be the solution, but was abandoned. It was tightly coupled to the python version, and thus no current version existed. Then I found a command line utility1 that does just about everything, if you know how to use it. I'm not going to claim that I am this competent - however scanning the docs, I found an example that pretty much does what I need:
Ultimately, I
use File::Basename;
# glob all .AVIs
# globals
$datadir = "/Volumes/NO\\ NAME/DCIM/100EK113";
# can't check $datadir: glob and -d disagree on the escaping
#die "data dir ($datadir) not found !"
# if !-d $datadir;
@list = glob "$datadir/*.AVI";
# clear data directory
unlink $_ foreach ;
my $counter = 0;
foreach my $file (@list)
{
my $basename = basename($file);
print "$counter : $basename\n";
$com = "ffmpeg -i $datadir/$basename -r 0.5 -f image2 snapshots/$basename-%03d.jpeg";
# TODO: TRY system() - get rid of the program's output somehow
my $r = `$com`;
++$counter;
# uncomment to restrict processing
##die if $counter >= 3;
}
Second part - Enter AWS Rekognition
// Ref: Amazon Rekognition SDK: http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/getting-started-nodejs.html
// Load the SDK
var AWS = require('aws-sdk');
var rekognition = new AWS.Rekognition();
var fs = require('fs');
//* Read in list of files to process
var array = fs.readFileSync('files2.txt').toString().split("\n");
//* Loop through list processing for each file
for(i in array)
{
var file = array[i];
console.log(i, ". processing " + file);
examine (file); // for example, "01020403.bird.AVI-001.jpeg")
}
console.log("Program End ?");
// Examine the file using AWS recognition,
// saving the results to a file in the results/ directory.
function examine (filename)
{
// parameters for call
var params = {
Image: {
S3Object: {
Bucket: "phantomtec2",
Name: filename
}
},
MaxLabels: 123
};
// make the call to AWS
rekognition.detectLabels(params, function(err, data) {
if (err)
{
const outfile = "results/" + filename + ".ERROR";
fs.writeFile(outfile,
JSON.stringify(err, undefined, 2),
(err) => { return console.log(err) });
return;
}
else
{
// write results to file
const outfile = "results/" + filename + ".result";
fs.writeFileSync(outfile,
JSON.stringify(data,undefined,2),
(err) => { return console.log(err) });
}
});
} // end - examine
A result file contains the JSON returned from the detectLabels call. Here's an excerpt:
{
"Labels": [
{
"Name": "Blossom",
"Confidence": 74.3183364868164
},
{
"Name": "Flora",
"Confidence": 74.3183364868164
},
{
"Name": "Flower",
"Confidence": 74.3183364868164
},
{
"Name": "Plant",
"Confidence": 74.3183364868164
},