Track faces (deprecated, see FaceLog6 instead)
/*
* Copyright (C) 2015-2018 Digital Barriers plc. All rights reserved.
* Contact: http://www.digitalbarriers.com/
*
* This file is part of the Papillon SDK.
*
* You can't use, modify or distribute any part of this file without
* the explicit written agreements of Digital Barriers.
*/
#include <PapillonCore.h>
USING_NAMESPACE_PAPILLON
const PString SAMPLE_DIR = PPath::Join(PUtils::GetEnv("PAPILLON_INSTALL_DIR"), "Data", "Samples"); // path to find sample data: $PAPILLON_INSTALL_DIR/Data/Samples
const bool ENABLE_FACE_LOCALISER = false;
const float SCALE_FACTOR = 0.75f;
PResult ProcessEvents(const PList & events) {
for (int32 i = 0, ni = events.Size(); i < ni; i++) {
PEvent event;
events.Get(i, event);
if (event.GetType() == "Track") { // Get thumbnail
PImage thumbnail;
event.GetPayload().Get(papillon::C_PROPERTY_THUMBNAIL, thumbnail);
thumbnail.Display("Track Thumbnail");
}
}
return PResult::C_OK;
}
PResult RunDemoFaceLog(int argc, char** argv) {
POption opt(argc, argv);
opt.AddStandardOptions(); // set-up logging
PString inputVideoFile = opt.String("inputVideo,i", PPath::Join(SAMPLE_DIR, "face_log.avi"), "Input video file");
PString outputVideoFile = opt.String("outputVideo,o", "out.avi", "Output video file");
int32 maxFrames = opt.Int ("frames,f", 0, "Maximum number of frames to process");
int32 skip = opt.Int ("skip,ss", 0, "Skip this number of frames at the beginning");
double scale = opt.Double("scale,s", 1.0, "Scale the output image");
bool blur = opt.Bool ("blur,b", false, "Blur the faces");
opt.Check().OrDie();
if (opt.Has("h") || opt.Has("help")) {
P_LOG_INFO << opt.ToStringHelp();
return PResult::C_OK;
}
ReturnIfFailed(PInputVideoStream::Open(inputVideoFile, ivs));
// Create an output stream for H.264 encoding
POutputVideoStream outputStream;
ReturnIfFailed(POutputVideoStream::Open(PString("file:%0?encode_with=opencv&fps=5").Arg(outputVideoFile), outputStream));
PProperties faceLogOptions;
faceLogOptions.Set("MinDetectionSize", 80);
faceLogOptions.Set("MaxDetectionSize", 1000);
faceLogOptions.Set("Blur", blur);
PAnalytics faceLog;
ReturnIfFailed(PAnalytics::Create("FaceLog", faceLogOptions, faceLog));
PList events;
PFrame frame;
int frameNumber = 0;
P_LOG_INFO << "max frames: " << maxFrames;
while (ivs.GetFrame(frame).Ok()) {
frameNumber++;
if (frameNumber < skip)
continue;
if (faceLog.Apply(frame, events).Failed())
continue;
ProcessEvents(events);
P_LOG_DEBUG << "(" << frameNumber << "/" << maxFrames << ") found " << events << " events.";
PImage displayImage = frame.GetImage().Clone();
faceLog.DrawOSD(displayImage);
if (scale < 1.0)
displayImage.Resize(displayImage, 0.5f, PImage::E_INTERPOLATION_NEAREST);
displayImage.Display("Papillon SDK - Face Log");
if(frameNumber == maxFrames) {
P_LOG_INFO << "Maximum number of frames reached.";
break;
}
outputStream.PutFrame(displayImage);
}
// OK we have finished video, lets check we have no events hanging around
ReturnIfFailed(faceLog.Finish(events));
ReturnIfFailed(ProcessEvents(events));
outputStream.Close();
return PResult::C_OK;
}
int main(int argc, char** argv) {
RunDemoFaceLog(argc, argv).LogIfError();
return 0;
}