NVIDIA DeepStream SDK API Reference

9.2 Release
ReIDService Class Reference

Detailed Description

Associates local targets with identities returned by a remote service.

Definition at line 94 of file sources/libs/nvmultiobjecttracker/include/modules/ReIDService/ReIDService.hpp.

Inheritance diagram for ReIDService:
Collaboration diagram for ReIDService:

Public Member Functions

 ReIDService (const std::string &configFilePath)
 Construct a ReIDService instance from configuration. More...
 
virtual ~ReIDService ()
 Release resources owned by the ReIDService instance. More...
 
void initialize (const SourceFrameInfo &frameInfo, const uint maxTargetsPerStream, const std::shared_ptr< NvTrackedObjectManager > &targetManager) override
 Initialize variables and allocate memories. More...
 
void queryParams (NvMOTQuery &paramsQuery)
 Populate the capabilities reported to the tracker. More...
 
void query (const std::map< NvMOTStreamId, NvMOTFrame * > &inputMeta) override
 Send query to reid service for all unmatched active objects. More...
 
void updateTargetIDs () override
 Update target ID using remoteTargetID from reid service. More...
 
const REID_SERVICE_TYPES getReIDServiceType () override
 Get the configured ReID-service implementation type. More...
 
 ReIDService (const std::string &configFilePath)
 Construct a ReIDService instance from configuration. More...
 
virtual ~ReIDService ()
 Release resources owned by the ReIDService instance. More...
 
void initialize (const SourceFrameInfo &frameInfo, const uint maxTargetsPerStream, const std::shared_ptr< NvTrackedObjectManager > &targetManager) override
 Initialize variables and allocate memories. More...
 
void queryParams (NvMOTQuery &paramsQuery)
 Populate the capabilities reported to the tracker. More...
 
void query (const std::map< NvMOTStreamId, NvMOTFrame * > &inputMeta) override
 Send query to reid service for all unmatched active objects. More...
 
void updateTargetIDs () override
 Update target ID using remoteTargetID from reid service. More...
 
const REID_SERVICE_TYPES getReIDServiceType () override
 Get the configured ReID-service implementation type. More...
 

Protected Member Functions

void workerThread ()
 Process queued remote ReID requests. More...
 
void waitToFinish ()
 Wait until all submitted service requests have completed. More...
 
bool tryIDCorrection (const std::shared_ptr< NvTrackedObject > targetToBeCorrected, const std::shared_ptr< NvTrackedObject > existingTarget, TargetId associatedTargetID)
 Apply a remote identity to a compatible local target. More...
 
std::string convertReidFeaturesToJson (const float *reidFeatures, int reidFeatureSize)
 Serialize a ReID feature vector as JSON. More...
 
std::string send_post_request (const std::string &jsonPayload)
 Send one synchronous HTTP POST request. More...
 
remoteTargetInfo parseResponseForTargetID (const std::string &response)
 Parse a remote identity result from a service response. More...
 
bool appendCurlRequest (const CurlRequestTargetInfo &curlRequestInfoInput)
 Add a request to the asynchronous CURL multi-handle. More...
 
void processCompletedCurlRequest (CURLMsg *msg)
 Collect the result of a completed CURL request. More...
 
void workerThread ()
 Process queued remote ReID requests. More...
 
void waitToFinish ()
 Wait until all submitted service requests have completed. More...
 
bool tryIDCorrection (const std::shared_ptr< NvTrackedObject > targetToBeCorrected, const std::shared_ptr< NvTrackedObject > existingTarget, TargetId associatedTargetID)
 Apply a remote identity to a compatible local target. More...
 
std::string convertReidFeaturesToJson (const float *reidFeatures, int reidFeatureSize)
 Serialize a ReID feature vector as JSON. More...
 
std::string send_post_request (const std::string &jsonPayload)
 Send one synchronous HTTP POST request. More...
 
remoteTargetInfo parseResponseForTargetID (const std::string &response)
 Parse a remote identity result from a service response. More...
 
bool appendCurlRequest (const CurlRequestTargetInfo &curlRequestInfoInput)
 Add a request to the asynchronous CURL multi-handle. More...
 
void processCompletedCurlRequest (CURLMsg *msg)
 Collect the result of a completed CURL request. More...
 

Protected Attributes

bool m_isInit
 Reid status if runtime variables initialized. More...
 
ReIDServiceConfigParams m_params
 Config params for reid module. More...
 
std::shared_ptr< NvTrackedObjectManager > m_targetManager
 Target manager of the tracked objects. More...
 
std::map< CURL *, CurlRequestTargetInfo > m_curlRequestInfoMap
 Active CURL handles. More...
 
CURLM * m_curlMultiHandle
 CURL multi handle. More...
 
std::string m_curlRequestUrl
 CURL request URL. More...
 
std::thread m_workerThread
 Worker thread. More...
 
std::atomic< bool > m_persistThreadRunning
 Indicates whether the worker thread should keep running. More...
 
std::mutex m_inputLock
 Lock associated with input queue. More...
 
std::condition_variable m_cond4In
 Wakes the worker when the input queue receives a request. More...
 
std::queue< CurlRequestTargetInfo > m_inputQueue
 Queue for input. More...
 
std::mutex m_outputLock
 Lock associated with output. More...
 
std::condition_variable m_cond4Out
 Wakes the caller when the worker finishes a request. More...
 
std::queue< remoteTargetInfo > m_outputQueue
 Queue for output. More...
 
std::atomic< uint32_t > m_submittedReqCnt
 Number of submitted tasks. More...
 
std::atomic< uint32_t > m_finishedReqCnt
 Keep track of how many tasks are finished. More...
 
std::map< NvMOTStreamId, std::map< TargetId, std::pair< TargetId, int > > > m_idCorrectionMap
 Target-ID corrections keyed by stream ID. More...
 

Constructor & Destructor Documentation

◆ ReIDService() [1/2]

ReIDService::ReIDService ( const std::string &  configFilePath)

Construct a ReIDService instance from configuration.

Parameters
[in]configFilePathPath to the tracker configuration file.

◆ ~ReIDService() [1/2]

virtual ReIDService::~ReIDService ( )
virtual

Release resources owned by the ReIDService instance.

◆ ReIDService() [2/2]

ReIDService::ReIDService ( const std::string &  configFilePath)

Construct a ReIDService instance from configuration.

Parameters
[in]configFilePathPath to the tracker configuration file.

◆ ~ReIDService() [2/2]

virtual ReIDService::~ReIDService ( )
virtual

Release resources owned by the ReIDService instance.

Member Function Documentation

◆ appendCurlRequest() [1/2]

bool ReIDService::appendCurlRequest ( const CurlRequestTargetInfo &  curlRequestInfoInput)
protected

Add a request to the asynchronous CURL multi-handle.

Parameters
[in]curlRequestInfoInputRequest state to append to the active CURL set.
Returns
False when the CURL handle cannot be created; true otherwise, including when the request is dropped.

◆ appendCurlRequest() [2/2]

bool ReIDService::appendCurlRequest ( const CurlRequestTargetInfo &  curlRequestInfoInput)
protected

Add a request to the asynchronous CURL multi-handle.

Parameters
[in]curlRequestInfoInputRequest state to append to the active CURL set.
Returns
False when the CURL handle cannot be created; true otherwise, including when the request is dropped.

◆ convertReidFeaturesToJson() [1/2]

std::string ReIDService::convertReidFeaturesToJson ( const float *  reidFeatures,
int  reidFeatureSize 
)
protected

Serialize a ReID feature vector as JSON.

Parameters
[in]reidFeaturesReID feature vector.
[in]reidFeatureSizeNumber of values in each ReID feature.

◆ convertReidFeaturesToJson() [2/2]

std::string ReIDService::convertReidFeaturesToJson ( const float *  reidFeatures,
int  reidFeatureSize 
)
protected

Serialize a ReID feature vector as JSON.

Parameters
[in]reidFeaturesReID feature vector.
[in]reidFeatureSizeNumber of values in each ReID feature.

◆ getReIDServiceType() [1/2]

const REID_SERVICE_TYPES ReIDService::getReIDServiceType ( )
inlineoverridevirtual

Get the configured ReID-service implementation type.

Implements IReIDService.

Definition at line 133 of file 9.2/sources/libs/nvmultiobjecttracker/include/modules/ReIDService/ReIDService.hpp.

References m_params, and ReIDServiceConfigParams::m_reidServiceType.

◆ getReIDServiceType() [2/2]

const REID_SERVICE_TYPES ReIDService::getReIDServiceType ( )
inlineoverridevirtual

Get the configured ReID-service implementation type.

Implements IReIDService.

Definition at line 133 of file sources/libs/nvmultiobjecttracker/include/modules/ReIDService/ReIDService.hpp.

References m_params, and ReIDServiceConfigParams::m_reidServiceType.

◆ initialize() [1/2]

void ReIDService::initialize ( const SourceFrameInfo &  frameInfo,
const uint  maxTargetsPerStream,
const std::shared_ptr< NvTrackedObjectManager > &  targetManager 
)
overridevirtual

Initialize variables and allocate memories.

Parameters
[in]frameInfoMetadata about the source image, such as size and color.
[in]maxTargetsPerStreamMaximum number of targets to track in each stream.
[in]targetManagerTarget manager of the tracked objects.

Implements IReIDService.

◆ initialize() [2/2]

void ReIDService::initialize ( const SourceFrameInfo &  frameInfo,
const uint  maxTargetsPerStream,
const std::shared_ptr< NvTrackedObjectManager > &  targetManager 
)
overridevirtual

Initialize variables and allocate memories.

Parameters
[in]frameInfoMetadata about the source image, such as size and color.
[in]maxTargetsPerStreamMaximum number of targets to track in each stream.
[in]targetManagerTarget manager of the tracked objects.

Implements IReIDService.

◆ parseResponseForTargetID() [1/2]

remoteTargetInfo ReIDService::parseResponseForTargetID ( const std::string &  response)
protected

Parse a remote identity result from a service response.

Parameters
[in]responseService response text.

◆ parseResponseForTargetID() [2/2]

remoteTargetInfo ReIDService::parseResponseForTargetID ( const std::string &  response)
protected

Parse a remote identity result from a service response.

Parameters
[in]responseService response text.

◆ processCompletedCurlRequest() [1/2]

void ReIDService::processCompletedCurlRequest ( CURLMsg *  msg)
protected

Collect the result of a completed CURL request.

Parameters
[in]msgCompleted CURL message.

◆ processCompletedCurlRequest() [2/2]

void ReIDService::processCompletedCurlRequest ( CURLMsg *  msg)
protected

Collect the result of a completed CURL request.

Parameters
[in]msgCompleted CURL message.

◆ query() [1/2]

void ReIDService::query ( const std::map< NvMOTStreamId, NvMOTFrame * > &  inputMeta)
overridevirtual

Send query to reid service for all unmatched active objects.

Parameters
[in]inputMetaInput frames keyed by stream ID.

Implements IReIDService.

◆ query() [2/2]

void ReIDService::query ( const std::map< NvMOTStreamId, NvMOTFrame * > &  inputMeta)
overridevirtual

Send query to reid service for all unmatched active objects.

Parameters
[in]inputMetaInput frames keyed by stream ID.

Implements IReIDService.

◆ queryParams() [1/2]

void ReIDService::queryParams ( NvMOTQuery &  paramsQuery)
virtual

Populate the capabilities reported to the tracker.

Parameters
[out]paramsQueryThe output query parameters.

Implements IReIDService.

◆ queryParams() [2/2]

void ReIDService::queryParams ( NvMOTQuery &  paramsQuery)
virtual

Populate the capabilities reported to the tracker.

Parameters
[out]paramsQueryThe output query parameters.

Implements IReIDService.

◆ send_post_request() [1/2]

std::string ReIDService::send_post_request ( const std::string &  jsonPayload)
protected

Send one synchronous HTTP POST request.

Parameters
[in]jsonPayloadJSON request payload.

◆ send_post_request() [2/2]

std::string ReIDService::send_post_request ( const std::string &  jsonPayload)
protected

Send one synchronous HTTP POST request.

Parameters
[in]jsonPayloadJSON request payload.

◆ tryIDCorrection() [1/2]

bool ReIDService::tryIDCorrection ( const std::shared_ptr< NvTrackedObject >  targetToBeCorrected,
const std::shared_ptr< NvTrackedObject >  existingTarget,
TargetId  associatedTargetID 
)
protected

Apply a remote identity to a compatible local target.

Parameters
[in]targetToBeCorrectedTarget whose identity may be corrected.
[in]existingTargetExisting target associated with the remote identity.
[in]associatedTargetIDTarget identifier returned by the service.
Returns
True when the correction is accepted and the existing target's ID is dropped; false otherwise.

◆ tryIDCorrection() [2/2]

bool ReIDService::tryIDCorrection ( const std::shared_ptr< NvTrackedObject >  targetToBeCorrected,
const std::shared_ptr< NvTrackedObject >  existingTarget,
TargetId  associatedTargetID 
)
protected

Apply a remote identity to a compatible local target.

Parameters
[in]targetToBeCorrectedTarget whose identity may be corrected.
[in]existingTargetExisting target associated with the remote identity.
[in]associatedTargetIDTarget identifier returned by the service.
Returns
True when the correction is accepted and the existing target's ID is dropped; false otherwise.

◆ updateTargetIDs() [1/2]

void ReIDService::updateTargetIDs ( )
overridevirtual

Update target ID using remoteTargetID from reid service.

Implements IReIDService.

◆ updateTargetIDs() [2/2]

void ReIDService::updateTargetIDs ( )
overridevirtual

Update target ID using remoteTargetID from reid service.

Implements IReIDService.

◆ waitToFinish() [1/2]

void ReIDService::waitToFinish ( )
protected

Wait until all submitted service requests have completed.

◆ waitToFinish() [2/2]

void ReIDService::waitToFinish ( )
protected

Wait until all submitted service requests have completed.

◆ workerThread() [1/2]

void ReIDService::workerThread ( )
protected

Process queued remote ReID requests.

◆ workerThread() [2/2]

void ReIDService::workerThread ( )
protected

Process queued remote ReID requests.

Field Documentation

◆ m_cond4In

std::condition_variable ReIDService::m_cond4In
protected

Wakes the worker when the input queue receives a request.

Definition at line 148 of file sources/libs/nvmultiobjecttracker/include/modules/ReIDService/ReIDService.hpp.

◆ m_cond4Out

std::condition_variable ReIDService::m_cond4Out
protected

Wakes the caller when the worker finishes a request.

Definition at line 155 of file sources/libs/nvmultiobjecttracker/include/modules/ReIDService/ReIDService.hpp.

◆ m_curlMultiHandle

CURLM * ReIDService::m_curlMultiHandle
protected

◆ m_curlRequestInfoMap

std::map< CURL *, CurlRequestTargetInfo > ReIDService::m_curlRequestInfoMap
protected

Active CURL handles.

All CURL-related variables are used only by the worker thread.

Definition at line 139 of file sources/libs/nvmultiobjecttracker/include/modules/ReIDService/ReIDService.hpp.

◆ m_curlRequestUrl

std::string ReIDService::m_curlRequestUrl
protected

◆ m_finishedReqCnt

std::atomic< uint32_t > ReIDService::m_finishedReqCnt
protected

Keep track of how many tasks are finished.

Definition at line 160 of file sources/libs/nvmultiobjecttracker/include/modules/ReIDService/ReIDService.hpp.

◆ m_idCorrectionMap

std::map< NvMOTStreamId, std::map< TargetId, std::pair< TargetId, int > > > ReIDService::m_idCorrectionMap
protected

Target-ID corrections keyed by stream ID.

Each nested key is the target ID to correct. Value is a pair of successfully associated target ID and the number of times the target ID has been associated successfully.

Definition at line 166 of file sources/libs/nvmultiobjecttracker/include/modules/ReIDService/ReIDService.hpp.

◆ m_inputLock

std::mutex ReIDService::m_inputLock
protected

Lock associated with input queue.

Definition at line 147 of file sources/libs/nvmultiobjecttracker/include/modules/ReIDService/ReIDService.hpp.

◆ m_inputQueue

std::queue< CurlRequestTargetInfo > ReIDService::m_inputQueue
protected

◆ m_isInit

bool ReIDService::m_isInit
protected

Reid status if runtime variables initialized.

Definition at line 136 of file sources/libs/nvmultiobjecttracker/include/modules/ReIDService/ReIDService.hpp.

◆ m_outputLock

std::mutex ReIDService::m_outputLock
protected

Lock associated with output.

Definition at line 154 of file sources/libs/nvmultiobjecttracker/include/modules/ReIDService/ReIDService.hpp.

◆ m_outputQueue

std::queue< remoteTargetInfo > ReIDService::m_outputQueue
protected

◆ m_params

ReIDServiceConfigParams ReIDService::m_params
protected

Config params for reid module.

Definition at line 137 of file sources/libs/nvmultiobjecttracker/include/modules/ReIDService/ReIDService.hpp.

Referenced by getReIDServiceType().

◆ m_persistThreadRunning

std::atomic< bool > ReIDService::m_persistThreadRunning
protected

Indicates whether the worker thread should keep running.

Definition at line 146 of file sources/libs/nvmultiobjecttracker/include/modules/ReIDService/ReIDService.hpp.

◆ m_submittedReqCnt

std::atomic< uint32_t > ReIDService::m_submittedReqCnt
protected

Number of submitted tasks.

Blocking mode uses this count to wait for the worker thread to finish. These are accessed from both the query thread (producer) and the worker thread (consumer), so they must be atomic to avoid data races (UB).

Definition at line 157 of file sources/libs/nvmultiobjecttracker/include/modules/ReIDService/ReIDService.hpp.

◆ m_targetManager

std::shared_ptr< NvTrackedObjectManager > ReIDService::m_targetManager
protected

Target manager of the tracked objects.

Definition at line 138 of file sources/libs/nvmultiobjecttracker/include/modules/ReIDService/ReIDService.hpp.

◆ m_workerThread

std::thread ReIDService::m_workerThread
protected

The documentation for this class was generated from the following file: