DFX Extraction library v4.12.0
enabling applications to perform DFX blood flow analysis
Public Member Functions | List of all members
dfx::DFXFactory Class Referenceabstract

DFXFactory is the primary entry point for the collector and is used create a collector. More...

#include "dfx/DFXFactory.h"

Public Member Functions

virtual ~DFXFactory ()
 DFXFactory destructor.
 
virtual std::string getVersion () const =0
 The version ID of this DFX Extraction library. More...
 
virtual std::string getSdkID () const =0
 The ID of this DFX Extraction library. More...
 
virtual bool setMode (const std::string &mode)=0
 Set the operating mode which will be used when creating a new collector. More...
 
virtual std::string getMode () const =0
 Returns the current operating mode when creating collectors. More...
 
virtual std::string getLastErrorMessage ()=0
 If there was an error getLastErrorMessage may contain more information about why the erorr occurred. More...
 
virtual void setProperty (const std::string &key, const std::string &value)=0
 Specifies a configurable property key/value pair to configure the DFX Extraction library. More...
 
virtual std::string getProperty (const std::string &key)=0
 Returns a property value for a key. More...
 
virtual void removeProperty (const std::string &key)=0
 Removes a property from the factory if it exists. More...
 
virtual std::vector< std::string > getValidProperties () const =0
 Obtain a list of valid property keys which can be configured. More...
 
virtual bool initializeStudy (const std::vector< unsigned char > &data)=0
 Initializes the factory to create collectors for a study with a memory based data definition. More...
 
virtual bool addToStudy (const std::vector< unsigned char > &data)=0
 Adds to the study definition when a definition is comprised of multiple parts with an additional memory based definition. More...
 
virtual bool initializeStudyFromFile (const std::string &pathToFile)=0
 Initializes the factory to create collectors for a study with a file based data definition. More...
 
virtual bool addToStudyFromFile (const std::string &pathToFile)=0
 Adds to the study definition when a definition is comprised of multiple parts with an additional file based definition. More...
 
virtual std::shared_ptr< dfx::CollectorcreateCollector ()=0
 Creates a Collector to process video frames and build a request payload. More...
 

Detailed Description

DFXFactory is the primary entry point for the collector and is used create a collector.

Applications are able to analyze video stream and summarize relevent portions of the stream which can be sent using the DFX API to the DFX Server for additional signal processing and model prediction.

Typical usage of the DFX API and DFX Extraction library involves only a few application level calls.

While the DFX Extraction library does not perform server calls, it does construct the payloads which a client platform will send to the server. The DFX Extraction library also expects to be initialized with the server response to properly initialize the engine.

// Obtain a study reference from the DFX API
auto studyResponse = Application::getAPIStudy();
std::vector<unsigned int> study =
dfx::DFXFactory factory; // Create the DFX factory instance
factory.initializeStudy(study);
auto collector = factory.createCollector();
collector->setTargetFPS(30.0f);
collector->prepareMeasurement(measurementResponsePayload);
// Enable all possible client contraints to minimize server side rejections
collector->setEnableConstraints(collector->getAvailableConstraintIDs());
collector->startCollection();
int frameNumber = 0;
cv::Mat image;
cv::VideoCapture video("theVideoFile.mp4");
while( video.read(image) ) {
dfx::VideoFrame videoFrame;
videoFrame.image = image;
videoFrame.channelOrder = dfx::VideoFormat::BGRA;
videoFrame.timestamp = std::chrono::high_resolution_clock::now();
videoFrame.number = frameNumber++;
auto frame = collector->createFrame(videoFrame);
// Application provides face tracking and builds face
// and adds it to frame.
auto face = Application::getDFXFace(videoFrame);
frame->addFace(face);
// Add markers, acceleration, rotation etc. if needed
frame->addMarker("smile");
// Define the collector regions of interest for this frame.
collector->defineRegions(frame);
std::vector<std::string> violations;
auto result = collector->checkConstraints(frame, violations);
if( result != ConstraintResult::Error ) {
// Extract the channels for this frame
collector->extractChannels(frame);
// Different studies have different requirements on number of
// frames to produce a chunk.
if ( collector->isChunkReady() ) {
auto chunkData = collector->getChunkData();
auto chunkPayload = chunkData->getChunkPayload();
std::vector<uint8_t> metadata = chunkPayload.metadata;
std::vector<uint8_t> payload = chunkPayload.payload;
// This is where the Application uses the DFX API to make
// the network call to the DFX Server.
auto payload = Application::getAPIcollectorPayload(metadata, bytes);
auto prediction = Application::getAPIPrediction(payload);
}
} else {
collector->resetCollection();
}
}

Member Function Documentation

◆ addToStudy()

virtual bool dfx::DFXFactory::addToStudy ( const std::vector< unsigned char > &  data)
pure virtual

Adds to the study definition when a definition is comprised of multiple parts with an additional memory based definition.

Deprecated:
: Support for this method will be removed in a future release. Please use the initializeStudy(const vector<unsigned char>&) to initialize a study.

If this is the first call, it will initialize the study with the definition otherwise it will be added to the existing data definitions.

Parameters
datato add to the study definition
Returns
true if the the data passes some basic sanity, false otherwise.
See also
DFXNetworkAPI

◆ addToStudyFromFile()

virtual bool dfx::DFXFactory::addToStudyFromFile ( const std::string &  pathToFile)
pure virtual

Adds to the study definition when a definition is comprised of multiple parts with an additional file based definition.

Deprecated:
: Support for this method will be removed in a future release. Please use the initializeStudy(const vector<unsigned char>&) to initialize a study.

If this is the first call, it will initialize the study with the definition otherwise it will be added to the existing data definitions.

Parameters
pathToFileto add to the study definition
Returns
true if the the data passes some basic sanity, false otherwise.
See also
DFXNetworkAPI

◆ createCollector()

virtual std::shared_ptr<dfx::Collector> dfx::DFXFactory::createCollector ( )
pure virtual

Creates a Collector to process video frames and build a request payload.

Returns
a reference to a Collector or nullptr on failure.

◆ getLastErrorMessage()

virtual std::string dfx::DFXFactory::getLastErrorMessage ( )
pure virtual

If there was an error getLastErrorMessage may contain more information about why the erorr occurred.

Returns
the last known error

◆ getMode()

virtual std::string dfx::DFXFactory::getMode ( ) const
pure virtual

Returns the current operating mode when creating collectors.

Returns
the currently configured operating mode

◆ getProperty()

virtual std::string dfx::DFXFactory::getProperty ( const std::string &  key)
pure virtual

Returns a property value for a key.

Parameters
keyto obtain the property value for.
Returns
the property if it exists or an empty string.

◆ getSdkID()

virtual std::string dfx::DFXFactory::getSdkID ( ) const
pure virtual

The ID of this DFX Extraction library.

When requesting a study file from the DFX server it requires the ID which is returned by this method.

Since
4.3.13
Returns
the ID of this DFX Extraction library.

◆ getValidProperties()

virtual std::vector<std::string> dfx::DFXFactory::getValidProperties ( ) const
pure virtual

Obtain a list of valid property keys which can be configured.

Returns
list of configurable property keys.
See also
setProperty

◆ getVersion()

virtual std::string dfx::DFXFactory::getVersion ( ) const
pure virtual

The version ID of this DFX Extraction library.

Returns
the version ID of this DFX Extraction library.

◆ initializeStudy()

virtual bool dfx::DFXFactory::initializeStudy ( const std::vector< unsigned char > &  data)
pure virtual

Initializes the factory to create collectors for a study with a memory based data definition.

An instance of a DFXFactory will only create collectors for the most recently configured study. Previously initialized study definitions are replaced with the new data if true is returned.

Parameters
datafrom the server which identifies the study characteristics this DFXFactory will use.
Returns
true if the the data passes some basic sanity, false otherwise.
See also
DFXNetworkAPI

◆ initializeStudyFromFile()

virtual bool dfx::DFXFactory::initializeStudyFromFile ( const std::string &  pathToFile)
pure virtual

Initializes the factory to create collectors for a study with a file based data definition.

Deprecated:
: Support for this method will be removed in a future release. Please use the initializeStudy(const vector<unsigned char>&) to initialize a study.

An instance of a DFXFactory will only create collectors for the most recently configured study. Previously initialized study definitions are replaced with the new data if true is returned.

Parameters
pathToFilefrom the server which identifies the study characteristics this DFXFactory will use.
Returns
true if the the data passes some basic sanity, false otherwise.
See also
DFXNetworkAPI

◆ removeProperty()

virtual void dfx::DFXFactory::removeProperty ( const std::string &  key)
pure virtual

Removes a property from the factory if it exists.

Parameters
keyof property to remove if it exists, ignored if it does not exist.
See also
getValidProperties, setProperties

◆ setMode()

virtual bool dfx::DFXFactory::setMode ( const std::string &  mode)
pure virtual

Set the operating mode which will be used when creating a new collector.

Identifies the collector as being a "streaming" or a "discrete" collector. By default the collector is considered "discrete".

Parameters
modethe string representing the operating mode.
Returns
true if mode was successfully changed, false otherwise.

◆ setProperty()

virtual void dfx::DFXFactory::setProperty ( const std::string &  key,
const std::string &  value 
)
pure virtual

Specifies a configurable property key/value pair to configure the DFX Extraction library.

Parameters
keyof property to configure.
valueof property to configure.
See also
getValidProperties

The documentation for this class was generated from the following file:
dfx::VideoFrame
Represents the internal structure for how image frames are passed to the DFX Engine since there is li...
Definition: VideoFrame.h:35
dfx::DFXFactory
DFXFactory is the primary entry point for the collector and is used create a collector.
Definition: DFXFactory.h:114
dfx::DFXFactory::createCollector
virtual std::shared_ptr< dfx::Collector > createCollector()=0
Creates a Collector to process video frames and build a request payload.
dfx::ConstraintResult::Error
@ Error
dfx::VideoFrame::image
cv::Mat image
the image color channels for the frame.
Definition: VideoFrame.h:82
dfx::DFXFactory::initializeStudy
virtual bool initializeStudy(const std::vector< unsigned char > &data)=0
Initializes the factory to create collectors for a study with a memory based data definition.
dfx::VideoFrame::number
uint32_t number
the video frame number within the video sequence.
Definition: VideoFrame.h:116