Fever Cam Processing
/*
* 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 <PFeverCamCalibration.h>
#include <PFeverCamProcessor.h>
#include <PapillonCore.h>
USING_NAMESPACE_PAPILLON
int main(int argc, char** argv) {
// Handle standard options
POption opt(argc, argv);
opt.AddStandardOptions(); // set-up logging
PFeverCamCalibration fccalib;
PFeverCamProcessor fcproc;
// Configure a default FaceLog6 analytics that will be used for detection
PAnalytics faceLog;
PProperties faceLogParameters;
faceLogParameters.Set("faceDetector.MinDetectionSize", 80);
faceLogParameters.Set("faceDetector.MaxDetectionSize", 1000);
faceLogParameters.Set("faceDetector.Threshold", 0.0);
faceLogParameters.Set("faceDetector.regionOfInterest", papillon::PRectanglei(0, 0, 0, 0));
faceLogParameters.Set("faceDetector.MinCertainty", 0.0);
faceLogParameters.Set("faceDetector.MaxLength", 100);
faceLogParameters.Set("faceDetector.MinLength", 1);
faceLogParameters.Set("faceDetector.MaxGap", 10);
faceLogParameters.Set("faceDetector.SightingSimilarity", 0.6);
faceLogParameters.Set("faceDetector.FrameLag", 50);
faceLogParameters.Set("faceDetector.OSDFlags", 1);
PWatchlistOptions watchlistOptions;
watchlistOptions.SetTopN(1);
watchlistOptions.SetThreshold(0.75);
watchlistOptions.SetNormalise(false);
faceLogParameters.Set("faceDetector.WatchlistOptions", watchlistOptions);
faceLogParameters.Set("faceDetector.MaxFaceDetectorFR", -1);
// Load calibration for the processor
fccalib.LoadFromFile(PPath::Join(SAMPLE_DIR, "calibrationMatrix.bin")).OrDie("Loading calibration matrix");
fcproc.SetCalibration(fccalib);
// Connect to feverCam
// Connect to color camera
PInputVideoStream colorIvs;
.OrDie("Opening color stream");
PImage img;
PFrame colorFame, thermFrame;
// Detection will run as long as video streams are available
while(colorIvs.GetFrame(colorFame, 30000).LogErrorIfAny("retrieving color frame").Ok() && fcproc.IsActive()) {
PList faceEvents;
// Here we can detect black body should it be needed
PList bbodyCandidates;
!bbodyCandidates.IsEmpty()) {
// At this point user could update automatically black body position in the camera
// To do this (very simple example assuming only one candidate is found):
//
// Retrieve the thermal video stream
// PInputVideoStream tivs;
// fcproc.GetTemperatureVideoSource(tivs).OrDie("Retrieving thermal video source");
// PRectanglef bbodyRect;
// bbodyCandidates.Get(0, bbodyRect).OrDie("Retrieving first black body candidate");
// tivs.Set("BLACKBODY_RECTANGLE", bbodyRect).OrDie("Setting black body position");
}
// Display synchronized temperature image
thermFrame.Display("thermal", 0);
// Retrieve image that will be used for display of faces and temperature
// Now process faces that we may have detected
for(int32 e = 0; e < faceEvents.Size(); ++e) {
PEvent evt;
// We only process faces
// Extract the detection
PDetection detection;
if(eventProperties.Get("Detection", detection).LogIfError().Failed())
continue;
// We'll draw the image with the detection on it
PUtils::DrawLabel(img, detection, "", PUtils::E_TOP_CENTRE, PUtils::E_BLACK, 1., 1, PColour3i::Red());
// Estimate face temperature for this face
double temperature, confidence;
if(fcproc.EstimateFaceTemperature(detection, temperature, confidence)
.LogErrorIfAny("Estimating face temperature")) {
// We managed to get face temperature (so calibration was correct enough that we could match face to
// thermal equivalent)
<< " has temperature " << temperature << "C with confidence " << confidence;
// we'll add the color information on top
PColour3i::Darkgray(), PColour3i::Red(), papillon::PUtils::E_TOP_CENTRE, 1., 0,
papillon::PColour3i::White(), papillon::PImage::E_FONT_HERSHEY_TRIPLEX);
}
}
}
// Display image with detection and temperature if available
img.Display("Detection", 0);
}
return 0;
}