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

DeepSight SDK body aggregator class. More...

Public Member Functions

 BodyAggregator ()
 ds::BodyAggregator constructor.
 
 ~BodyAggregator () noexcept
 ds::BodyAggregator destructor.
 
 BodyAggregator (BodyAggregator &&bodyAggregator) noexcept
 ds::BodyAggregator move constructor.
 
BodyAggregator & operator= (BodyAggregator &&bodyAggregator) noexcept
 ds::BodyAggregator move assignment operator.
 
void newDetections (const std::vector< ds::Body > &bodies)
 Adds new detections in the current state of aggregations. More...
 
std::vector< ds::AggregatedBody > getFinalizedAggregations (bool clean=true)
 Get bodies whose aggregation is finalized. More...
 
std::vector< ds::AggregatedBody > getOngoingAggregations () const
 Get bodies whose aggregation is still ongoing. More...
 
std::vector< ds::AggregatedBody > 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::AggregatedBody > aggregateOffline (const std::vector< ds::Body > &bodies)
 Aggregates all the bodies in the input vector. More...
 

Detailed Description

DeepSight SDK body aggregator class.

The ds::BodyAggregator class aggregates all information retrieved at each frame for each unique body. This means that for all ds::Body detections with the same id, the ds::BodyAggregator class produces one single ds::AggregatedBody 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::AggregatedBody > ds::BodyAggregator::aggregateOffline ( const std::vector< ds::Body > &  bodies)
static

Aggregates all the bodies in the input vector.

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

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

ds::BodyAggregator aggregator;
aggregator.newDetections( bodies );
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::Body> analyzedBodies;
while( true )
{
cap >> frame;
if( frame.empty() )
break;
// Analyze frame
std::vector<ds::Body> bodies = ds.analyzeBodies( frame );
// Accumulate detections
analyzedBodies.insert( analyzedBodies.end(), bodies.begin(), bodies.end() );
}
// Aggregated all bodies detected in the video
std::vector<ds::AggregatedBody> videoSummary = ds::BodyAggregator::aggregateOffline( analyzedBodies );

◆ cleanAll()

void ds::BodyAggregator::cleanAll ( )
noexcept

Deletes ongoing and finalized aggregations from the internal state.

◆ getAllAggregations()

std::vector< ds::AggregatedBody > ds::BodyAggregator::getAllAggregations ( ) const

Get all aggregations, ongoing and finalized.

Returns
A vector of aggregated bodies.

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

Example usage:

ds::BodyAggregator aggregator;
while( true )
{
cap >> frame;
if( frame.empty() )
break;
// Analyze frame
std::vector<ds::Body> bodies = ds.analyzeBodies( frame );
// Update the aggregations with the new detections
aggregator.newDetections( bodies );
}
// Print all aggregated bodies in CSV format
std::vector<ds::AggregatedBody> aggregatedBodies = aggregator.getAllAggregations();
for( const ds::AggregatedBody & aggregatedBody : aggregatedBodies )
std::cout << ds::help::aggregatedBodyToCsv( aggregatedBody ) << std::endl;

◆ getFinalizedAggregations()

std::vector< ds::AggregatedBody > ds::BodyAggregator::getFinalizedAggregations ( bool  clean = true)

Get bodies whose aggregation is finalized.

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

When a body 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 body and it's therefore considered finalized. This function returns all the bodies whose aggregation is considered finalized. Aggregated bodies 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::BodyAggregator::cleanFinalizedAggregations. Otherwise they will be returned again at the next call of the ds::BodyAggregator::getFinalizedAggregations or ds::BodyAggregator::cleanFinalizedAggregations functions.

Example usage:

ds::BodyAggregator aggregator;
while( true )
{
cap >> frame;
if( frame.empty() )
break;
// Analyze frame
std::vector<ds::Body> bodies = ds.analyzeBodies( frame );
// Update the aggregations with the new detections
aggregator.newDetections( bodies );
// Print the finalized aggregations in CSV format
std::vector<ds::AggregatedBody> finalizedAggregations = aggregator.getFinalizedAggregations();
for( const ds::AggregatedBody & aggregatedBody : finalizedAggregations )
std::cout << ds::help::aggregatedBodyToCsv( aggregatedBody ) << std::endl;
}

◆ getOngoingAggregations()

std::vector< ds::AggregatedBody > ds::BodyAggregator::getOngoingAggregations ( ) const

Get bodies whose aggregation is still ongoing.

Returns
A vector of ongoing aggregations.

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

Example usage:

ds::BodyAggregator aggregator;
while( true )
{
cap >> frame;
if( frame.empty() )
break;
// Analyze frame
std::vector<ds::Body> bodies = ds.analyzeBodies( frame );
// Update the aggregations with the new detections
aggregator.newDetections( bodies );
// Print the finalized aggregations in CSV format
std::vector<ds::AggregatedBody> finalizedAggregations = aggregator.getFinalizedAggregations();
for( const ds::AggregatedBody & aggregatedBody : finalizedAggregations )
std::cout << ds::help::aggregatedBodyToCsv( aggregatedBody ) << std::endl;
}
// Print in CSV format the remaining aggregations which were not finalized at the end of the video
std::vector<ds::AggregatedBody> ongoingAggregations = aggregator.getOngoingAggregations();
for( const ds::AggregatedBody & aggregatedBody : ongoingAggregations )
std::cout << ds::help::aggregatedBodyToCsv( aggregatedBody ) << std::endl;

◆ newDetections()

void ds::BodyAggregator::newDetections ( const std::vector< ds::Body > &  bodies)

Adds new detections in the current state of aggregations.

Parameters
bodiesNew detections to aggregate.

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

Example usage:

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