DeepSight SDK  3.0.0
DeepSight SDK - crowd face analysis
ds::Aggregator Class Reference

DeepSight SDK aggregator class. More...

Public Member Functions

 Aggregator ()
 ds::Aggregator constructor.
 
 ~Aggregator () noexcept
 ds::Aggregator destructor.
 
 Aggregator (Aggregator &&aggregator) noexcept
 ds::Aggregator move constructor.
 
Aggregator & operator= (Aggregator &&aggregator) noexcept
 ds::Aggregator move assignment operator.
 
void newDetections (const std::vector< ds::Person > &people)
 Adds new detections to the current state of aggregations. More...
 
std::vector< ds::AggregatedPerson > getFinalizedAggregations (bool clean=true)
 Get people whose aggregation is finalized. More...
 
std::vector< ds::AggregatedPerson > getOngoingAggregations () const
 Get people whose aggregation is still ongoing. More...
 
std::vector< ds::AggregatedPerson > getAllAggregations () const
 Get all aggregations, ongoing and finalized. More...
 
void cleanFinalizedAggregations () noexcept
 Deletes all the finalized aggregations from the internal state.
 
void cleanAll () noexcept
 Deletes ongoing and finalized aggregations from the internal state. More...
 

Static Public Member Functions

static std::vector< ds::AggregatedPerson > aggregateOffline (const std::vector< ds::Person > &people)
 Aggregates all the people in the input vector. More...
 

Detailed Description

DeepSight SDK aggregator class.

The ds::Aggregator class aggregates all information retrieved at each frame for each unique person. This means that for all ds::Person detections with the same id, the ds::Aggregator class produces one single ds::AggregatedPerson object with the aggregated values for age, gender, and so on. The aggregation algorithm takes into account the conditions for calculating the best possible value for each estimated feature, like age, gender and so on. It also performs filtering in case a detection has a too short duration and therefore considered as a false positive.

Member Function Documentation

◆ aggregateOffline()

std::vector< ds::AggregatedPerson > ds::Aggregator::aggregateOffline ( const std::vector< ds::Person > &  people)
static

Aggregates all the people in the input vector.

Parameters
peopleThe vector of new detections to aggregate.
Returns
The vector of all people with a unique ID aggregated during the offline aggregation.

Assuming that all the ds::Person detections for each person are collected in a vector, this functions performs the aggregation in a stateless fashion, that is, without requiring to construct a ds::Aggregator object. This is equivalent to:

ds::Aggregator aggregator;
aggregator.newDetections( people );
return aggregator.getAllAggregations();

Example usage:

// Initialize DeepSight
s.neuralNetworksPath = "/path/to/neuralnetworks";
s.licenseKey = "license key";
ds::DeepSight ds{ s };
ds.authenticate();
// Open a video file
cv::VideoCapture cap( "/path/to/video.avi" );
cv::Mat frame;
// Analyze the whole video
std::vector<ds::Person> analyzedPeople;
while( true )
{
cap >> frame;
if( frame.empty() )
break;
// Analyze frame
std::vector<ds::Person> people = ds.analyze( frame );
// Accumulate detections
analyzedPeople.insert( analyzedPeople.end(), people.begin(), people.end() );
}
// Aggregated all people detected in the video
std::vector<ds::AggregatedPerson> videoSummary = ds::Aggregator::aggregateOffline( analyzedPeople );

◆ cleanAll()

void ds::Aggregator::cleanAll ( )
noexcept

Deletes ongoing and finalized aggregations from the internal state.

◆ getAllAggregations()

std::vector< ds::AggregatedPerson > ds::Aggregator::getAllAggregations ( ) const

Get all aggregations, ongoing and finalized.

Returns
A vector of aggregated people.

This function returns all aggregations, ongoing and finalized. Aggregated people who have a too short detection duration are considered false positives and are filtered out.

Example usage:

ds::Aggregator aggregator;
while( true )
{
cap >> frame;
if( frame.empty() )
break;
// Analyze frame
std::vector<ds::Person> people = ds.analyze( frame );
// Update the aggregations with the new detections
aggregator.newDetections( people );
}
// Print all aggregated people in CSV format
std::vector<ds::AggregatedPerson> aggregatedPeople = aggregator.getAllAggregations();
for( const ds::AggregatedPerson & aggregatedPerson : aggregatedPeople )
std::cout << ds::help::aggregatedPersonToCsv( aggregatedPerson ) << std::endl;

◆ getFinalizedAggregations()

std::vector< ds::AggregatedPerson > ds::Aggregator::getFinalizedAggregations ( bool  clean = true)

Get people whose aggregation is finalized.

Parameters
cleanIf true, the returned aggregations are removed from the internal state.
Returns
A vector of finalized aggregations.

When a person is not detected for about 5 seconds, DeepSight stops tracking it. Therefore a detection with the same ID cannot be generated anymore. When that happens, there will be no new detection to aggregate for that person and it's therefore considered finalized. This function returns all the people whose aggregation is considered finalized. Aggregated people who have a too short detection duration are considered false positives and are filtered out.

If the clean parameter is set to true, the returned aggregations are removed from the internal state; this has the same effect as calling ds::Aggregator::cleanFinalizedAggregations. Otherwise they will be returned again at the next call of the ds::Aggregator::getFinalizedAggregations or ds::Aggregator::cleanFinalizedAggregations functions.

Example usage:

ds::Aggregator aggregator;
while( true )
{
cap >> frame;
if( frame.empty() )
break;
// Analyze frame
std::vector<ds::Person> people = ds.analyze( frame );
// Update the aggregations with the new detections
aggregator.newDetections( people );
// Print the finalized aggregations in CSV format
std::vector<ds::AggregatedPerson> finalizedAggregations = aggregator.getFinalizedAggregations();
for( const ds::AggregatedPerson & aggregatedPerson : finalizedAggregations )
std::cout << ds::help::aggregatedPersonToCsv( aggregatedPerson ) << std::endl;
}

◆ getOngoingAggregations()

std::vector< ds::AggregatedPerson > ds::Aggregator::getOngoingAggregations ( ) const

Get people whose aggregation is still ongoing.

Returns
A vector of ongoing aggregations.

This function returns the people whose aggregation is not finalized yet and can be updated with new detections in the following frames. Aggregated people who have a too short detection duration are considered false positives and are filtered out.

Example usage:

ds::Aggregator aggregator;
while( true )
{
cap >> frame;
if( frame.empty() )
break;
// Analyze frame
std::vector<ds::Person> people = ds.analyze( frame );
// Update the aggregations with the new detections
aggregator.newDetections( people );
// Print the finalized aggregations in CSV format
std::vector<ds::AggregatedPerson> finalizedAggregations = aggregator.getFinalizedAggregations();
for( const ds::AggregatedPerson & aggregatedPerson : finalizedAggregations )
std::cout << ds::help::aggregatedPersonToCsv( aggregatedPerson ) << std::endl;
}
// Print in CSV format the remaining aggregations which were not finalized at the end of the video
std::vector<ds::AggregatedPerson> ongoingAggregations = aggregator.getOngoingAggregations();
for( const ds::AggregatedPerson & aggregatedPerson : ongoingAggregations )
std::cout << ds::help::aggregatedPersonToCsv( aggregatedPerson ) << std::endl;

◆ newDetections()

void ds::Aggregator::newDetections ( const std::vector< ds::Person > &  people)

Adds new detections to the current state of aggregations.

Parameters
peopleNew detections to aggregate.

Use this function to update the current state of each person aggregation after every frame analysis.

Example usage:

ds::Aggregator aggregator;
while( true )
{
cap >> frame;
if( frame.empty() )
break;
// Analyze frame
std::vector<ds::Person> people = ds.analyze( frame );
// Update the aggregations with the new detections
aggregator.newDetections( people );
}
// Count how many unique people were detected during the analysis
std::cout << aggregator.getAllAggregations().size() << std::endl;
ds::Aggregator
DeepSight SDK aggregator class.
Definition: ds_aggregator.h:22
ds::AggregatedPerson
DeepSight SDK aggregated person class.
Definition: ds_person.h:65
ds::Settings::neuralNetworksPath
std::string neuralNetworksPath
Path of the directory containing the SDK neural network files.
Definition: ds_settings.h:39
ds::DeepSight
DeepSight SDK engine class.
Definition: ds_deepsight.h:28
ds::Settings
DeepSight SDK settings class.
Definition: ds_settings.h:19
ds::Aggregator::getAllAggregations
std::vector< ds::AggregatedPerson > getAllAggregations() const
Get all aggregations, ongoing and finalized.
ds::help::aggregatedPersonToCsv
DS_API std::string aggregatedPersonToCsv(const ds::AggregatedPerson &aggregatedPerson)
Returns a CSV record representing the input aggregatedPerson.
ds::Aggregator::getOngoingAggregations
std::vector< ds::AggregatedPerson > getOngoingAggregations() const
Get people whose aggregation is still ongoing.
ds::Aggregator::getFinalizedAggregations
std::vector< ds::AggregatedPerson > getFinalizedAggregations(bool clean=true)
Get people whose aggregation is finalized.
ds::Aggregator::aggregateOffline
static std::vector< ds::AggregatedPerson > aggregateOffline(const std::vector< ds::Person > &people)
Aggregates all the people in the input vector.
ds::Settings::licenseKey
std::string licenseKey
License key used for authenticating the SDK.
Definition: ds_settings.h:40
ds::Aggregator::newDetections
void newDetections(const std::vector< ds::Person > &people)
Adds new detections to the current state of aggregations.