Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- auto startPoint = std::chrono::high_resolution_clock::now();
- char path[] = "/opt/nvidia/deepstream/deepstream-4.0/samples/configs/deepstream-app/tracker_config.yml";
- NvMOTQuery query{};
- {
- const auto status = NvMOT_Query( sizeof( path ), path, &query );
- if( status != NvMOTStatus_OK ) {
- std::cout << "Error";
- }
- }
- /* INIT */
- void* yDevMem;
- const uint32_t width = static_cast< uint32_t >( m_currentFrame.cols );
- const uint32_t height = static_cast< uint32_t >( m_currentFrame.rows );
- const uint32_t pitch = static_cast< uint32_t >( m_currentFrame.step1() );
- //cudaMallocManaged( &yDevMem, width * height, cudaMemAttachGlobal );
- yDevMem = m_currentFrame.data;
- const uint32_t fullSize = pitch * height;
- static bool initCompleted{ false };
- static NvMOTContextHandle pContextHandle{};
- if( !initCompleted ) {
- // IN params
- NvMOTPerTransformBatchConfig batchConfig[ 1 ]{};
- batchConfig->bufferType = NVBUF_MEM_CUDA_UNIFIED;
- batchConfig->colorFormat = NVBUF_COLOR_FORMAT_GRAY8;
- batchConfig->maxHeight = height;
- batchConfig->maxPitch = pitch;
- batchConfig->maxSize = fullSize;
- batchConfig->maxWidth = width;
- NvMOTConfig pConfigIn{};
- pConfigIn.computeConfig = NVMOTCOMP_CPU; /**< Compute target. see NvMOTCompute */
- pConfigIn.maxStreams = 1; /**< Maximum number of streams in a batch. */
- pConfigIn.numTransforms = 1; /**< Number of NvMOTPerTransformBatchConfig entries in perTransformBatchConfig */
- pConfigIn.perTransformBatchConfig = batchConfig; /**< List of numTransform batch configs including type and resolution, one for each transform*/
- pConfigIn.miscConfig.gpuId = 0; /**< GPU to be used. */
- pConfigIn.miscConfig.maxObjPerBatch = 0; /**< Max number of objects to track per stream. 0 means no limit. */
- pConfigIn.miscConfig.maxObjPerStream = 0; /**< Max number of objects to track per batch. 0 means no limit. */
- pConfigIn.customConfigFilePathSize = sizeof( path ) ; /**< The char length in customConfigFilePath */
- pConfigIn.customConfigFilePath = path; /**< Path to the tracker's custom config file. Null terminated */
- // OUT Params
- NvMOTConfigResponse pConfigResponse{};
- {
- const auto status = NvMOT_Init( &pConfigIn, &pContextHandle, &pConfigResponse );
- if( status != NvMOTStatus_OK ) {
- std::cout << "Error";
- } else {
- initCompleted = true;
- }
- }
- }
- /* PROCESS */
- // IN Params
- NvBufSurfaceParams bufferParam[ 1 ]{};
- bufferParam->width = width; /** width of buffer */
- bufferParam->height = height; /** height of buffer */
- bufferParam->pitch = pitch; /** pitch of buffer */
- bufferParam->colorFormat = NVBUF_COLOR_FORMAT_GRAY8; /** color format */
- bufferParam->layout = NVBUF_LAYOUT_PITCH; /** BL or PL for Jetson, ONLY PL in case of dGPU */
- bufferParam->dataSize = fullSize; /** size of allocated memory */
- bufferParam->dataPtr = yDevMem; /** pointer to allocated memory, Not valid for NVBUF_MEM_SURFACE_ARRAY and NVBUF_MEM_HANDLE */
- bufferParam->planeParams.num_planes = 1; /** Number of planes */
- bufferParam->planeParams.width[ 0 ] = width; /** width of planes */
- bufferParam->planeParams.height[ 0 ] = height; /** height of planes */
- bufferParam->planeParams.pitch[ 0 ] = pitch; /** pitch of planes in bytes */
- bufferParam->planeParams.offset[ 0 ] = 0; /** offsets of planes in bytes */
- bufferParam->planeParams.psize[ 0 ] = pitch * height; /** size of planes in bytes */
- bufferParam->planeParams.bytesPerPix[ 0 ] = 1; /** bytes taken for each pixel */
- bufferParam->mappedAddr.addr[ 0 ] = yDevMem; /** pointers of mapped buffers. Null Initialized values.*/
- bufferParam->mappedAddr.eglImage = nullptr;
- //bufferParam->bufferDesc; /** dmabuf fd in case of NVBUF_MEM_SURFACE_ARRAY and NVBUF_MEM_HANDLE type memory. Invalid for other types. */
- NvBufSurfaceParams* bufferParamPtr{ bufferParam };
- static std::vector< NvMOTObjToTrack > inObjectVec{};
- static std::vector< NvMOTTrackedObj > outObjectVec{};
- size_t currObjectCount{ 0 };
- for( const TMetadataV2ObjectHeader::TObjectType currType: objectTypes ) {
- currObjectCount += m_objects.at( currType ).size();
- }
- if( inObjectVec.size() < currObjectCount ) {
- inObjectVec.resize( currObjectCount );
- }
- if( outObjectVec.size() < currObjectCount ) {
- outObjectVec.resize( currObjectCount );
- }
- size_t currInObjectIndex{ 0 };
- /* Iterate through the possible object types */
- /* The inner loop operates on the vector of tracked objects from that type */
- /* You can mock this section with generated objects */
- for( const TMetadataV2ObjectHeader::TObjectType currObjType: objectTypes ) {
- for( const auto& currObj: m_objects.at( currObjType ) ) {
- NvMOTObjToTrack& currInObject = inObjectVec[ currInObjectIndex++ ];
- currInObject.classId = static_cast< uint16_t >( currObjType ); /**< Class of the object to be tracked. */
- currInObject.bbox.x = currObj->getBBoxImage().x; /**< Bounding box. */
- currInObject.bbox.y = currObj->getBBoxImage().y;
- currInObject.bbox.width = currObj->getBBoxImage().width;
- currInObject.bbox.height = currObj->getBBoxImage().height;
- currInObject.confidence = 1.f; /**< Detection confidence of the object. */
- currInObject.doTracking = true; /**< True: track this object. False: do not initiate tracking on this object. */
- }
- }
- NvMOTFrame frame{};
- frame.streamID = 0; /**< The stream source for this frame. */
- frame.frameNum = m_frameNum; /**< Frame number sequentially identifying the frame within a stream. */
- frame.timeStamp = m_currFrameTimestamp; /**< Timestamp of the frame at the time of capture. */
- frame.timeStampValid = true; /**< The timestamp value is properly populated. */
- frame.doTracking = true; /**< True: track objects in this frame; False: do not track this frame. */
- frame.reset = false; /**< True: reset tracking for the stream. */
- frame.numBuffers = 1; /**< Number of entries in bufferList. */
- frame.bufferList = &bufferParamPtr; /**< Array of pointers to buffer params. */
- frame.objectsIn.detectionDone = ( m_frameNum % 2 == 0 ); // We detect on every second image
- frame.objectsIn.numAllocated = inObjectVec.size();
- frame.objectsIn.numFilled = currObjectCount;
- frame.objectsIn.list = inObjectVec.data();
- NvMOTProcessParams processParams{};
- processParams.numFrames = 1;
- processParams.frameList = &frame;
- // OUT Params
- NvMOTTrackedObjBatch outTrackedBatch{};
- NvMOTTrackedObjList outBatchObjects{};
- outBatchObjects.list = outObjectVec.data();
- outBatchObjects.streamID = 0; /**< Stream associated with objects in the list. */
- outBatchObjects.frameNum = m_frameNum; /**< Frame number for objects in the list. */
- outBatchObjects.valid = true; /**< This entry in the batch is valid */
- outBatchObjects.numAllocated = outObjectVec.size(); /**< Number of blocks allocated for the list. */
- outBatchObjects.numFilled = /*outObjVec.size()*/0; /**< Number of populated blocks in the list. */
- outTrackedBatch.numAllocated = 1;
- outTrackedBatch.numFilled = 1;
- outTrackedBatch.list = &outBatchObjects;
- {
- const auto status = NvMOT_Process( pContextHandle, &processParams, &outTrackedBatch );
- if( status != NvMOTStatus_OK ) {
- std::cout << "Error";
- }
- }
- for( size_t outIndex = 0; outIndex < outBatchObjects.numFilled; ++outIndex ) {
- const auto& currOutObj{ outObjectVec[ outIndex ] };
- const auto currOutAssociated{ currOutObj.associatedObjectIn };
- if( currOutAssociated != nullptr ) {
- std::cout << "Ref [x: " << currOutAssociated->bbox.x << " y: " << currOutAssociated->bbox.y
- << " w: " << currOutAssociated->bbox.width << " h: " << currOutAssociated->bbox.height << "] "
- << " Tracked [x: " << currOutObj.bbox.x << " y: " << currOutObj.bbox.y
- << " w: " << currOutObj.bbox.width << " h: " << currOutObj.bbox.height << "]" << std::endl;
- } else {
- std::cout << "No association" << std::endl;
- }
- }
- auto endPoint = std::chrono::high_resolution_clock::now();
- std::chrono::duration<float, std::milli> fdur = endPoint - startPoint;
- std::cout << "Count: " << inObjectVec.size() << " Runtime: " << fdur.count() << " Avg runtime: " << fdur.count() / inObjectVec.size() << std::endl;
Add Comment
Please, Sign In to add comment