NVIDIA DeepStream SDK API Reference

6.4 Release
post_processor_detect.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef __POST_PROCESSOR_DETECT_HPP__
25 #define __POST_PROCESSOR_DETECT_HPP__
26 
27 #include "post_processor.h"
28 
30  std::vector<NvDsInferLayerInfo> const &outputLayersInfo,
31  NvDsInferNetworkInfo const &networkInfo,
32  NvDsPostProcessParseDetectionParams const &detectionParams,
33  std::vector<NvDsPostProcessObjectDetectionInfo> &objectList);
34 
36 
37 public:
38  DetectModelPostProcessor(int id, int gpuId = 0)
40 
42  initResource(NvDsPostProcessContextInitParams& initParams) override;
43  ~DetectModelPostProcessor() override = default;
44  NvDsPostProcessStatus parseEachFrame(const std::vector <NvDsInferLayerInfo>&
45  outputLayers,
46  NvDsPostProcessFrameOutput &result) override;
47  void
48  attachMetadata (NvBufSurface *surf, gint batch_idx,
49  NvDsBatchMeta *batch_meta,
50  NvDsFrameMeta *frame_meta,
51  NvDsObjectMeta *object_meta,
52  NvDsObjectMeta *parent_obj_meta,
53  NvDsPostProcessFrameOutput & detection_output,
55  std::set <gint> & filterOutClassIds,
56  int32_t unique_id,
57  gboolean output_instance_mask,
58  gboolean process_full_frame,
59  float segmentationThreshold,
60  gboolean maintain_aspect_ratio) override;
61 
62  void releaseFrameOutput(NvDsPostProcessFrameOutput& frameOutput) override;
63  private:
64  bool parseBoundingBox(std::vector <NvDsInferLayerInfo> const&
65  outputLayersInfo,
66  NvDsInferNetworkInfo const& networkInfo,
67  NvDsPostProcessParseDetectionParams const& detectionParams,
68  std::vector<NvDsPostProcessObjectDetectionInfo>& objectList);
69  std::vector<int> nonMaximumSuppression(
70  std::vector <std::pair<float,int>>& scoreIndex,
71  std::vector<NvDsPostProcessParseObjectInfo> &bbox,
72  float const nmsThreshold);
73 
74  void clusterAndFillDetectionOutputHybrid(NvDsPostProcessDetectionOutput& output);
75  void clusterAndFillDetectionOutputNMS(NvDsPostProcessDetectionOutput& output);
76  void clusterAndFillDetectionOutputDBSCAN(NvDsPostProcessDetectionOutput& output);
77  void fillUnclusteredOutput(NvDsPostProcessDetectionOutput& output);
78  NvDsPostProcessStatus fillDetectionOutput(const std::vector <NvDsInferLayerInfo>& outputLayers,
80  void preClusteringThreshold(NvDsPostProcessParseDetectionParams const &detectionParams,
81  std::vector<NvDsPostProcessObjectDetectionInfo> &objectList);
82  void filterTopKOutputs(int const topK,
83  std::vector<NvDsPostProcessObjectDetectionInfo> &objectList);
84 
85 private:
86  NvDsPostProcessClusterMode m_ClusterMode;
87 
88  uint32_t m_NumDetectedClasses = 0;
89  std::shared_ptr<NvDsInferDBScan> m_DBScanHandle;
90 
91  std::vector <NvDsPostProcessDetectionParams> m_PerClassDetectionParams;
92  NvDsPostProcessParseDetectionParams m_DetectionParams = {0, {}, {}};
93 
94  std::vector <NvDsPostProcessObjectDetectionInfo> m_ObjectList;
95 #ifdef WITH_OPENCV
96  /* Vector of cv::Rect vectors for each class. */
97  std::vector<std::vector<cv::Rect>> m_PerClassCvRectList;
98 #endif
99  /* Vector of NvDsPostProcessObjectDetectionInfo vectors for each class. */
100  std::vector<std::vector<NvDsPostProcessObjectDetectionInfo>> m_PerClassObjectList;
101 
102  NvDsPostProcessParseCustomFunc m_CustomBBoxParseFunc = nullptr;
103 
104 };
105 
106 
107 #endif
DetectModelPostProcessor::DetectModelPostProcessor
DetectModelPostProcessor(int id, int gpuId=0)
Definition: post_processor_detect.h:38
NvDsPostProcessDetectionParams
Holds detection and bounding box grouping parameters.
Definition: post_processor_struct.h:216
DetectModelPostProcessor::releaseFrameOutput
void releaseFrameOutput(NvDsPostProcessFrameOutput &frameOutput) override
ModelPostProcessor
Definition: post_processor.h:57
NvBufSurface
Holds information about batched buffers.
Definition: nvbufsurface.h:503
post_processor.h
NvDsPostProcessDetectionOutput
Holds information on all objects detected by a detector network in one frame.
Definition: post_processor_struct.h:435
DetectModelPostProcessor
Definition: post_processor_detect.h:35
NvDsPostProcessStatus
NvDsPostProcessStatus
Enum for the status codes returned by NvDsPostProcessAlgorithm.
Definition: post_processor_struct.h:84
NvDsPostProcessParseCustomFunc
bool(* NvDsPostProcessParseCustomFunc)(std::vector< NvDsInferLayerInfo > const &outputLayersInfo, NvDsInferNetworkInfo const &networkInfo, NvDsPostProcessParseDetectionParams const &detectionParams, std::vector< NvDsPostProcessObjectDetectionInfo > &objectList)
Definition: post_processor_detect.h:29
DetectModelPostProcessor::~DetectModelPostProcessor
~DetectModelPostProcessor() override=default
DetectModelPostProcessor::parseEachFrame
NvDsPostProcessStatus parseEachFrame(const std::vector< NvDsInferLayerInfo > &outputLayers, NvDsPostProcessFrameOutput &result) override
NvDsInferNetworkInfo
Holds information about the model network.
Definition: nvdsinfer.h:110
_NvDsBatchMeta
Holds information about a formed batch containing frames from different sources.
Definition: nvdsmeta.h:240
NvDsPostProcessClusterMode
NvDsPostProcessClusterMode
Enum for clustering mode for detectors.
Definition: post_processor_struct.h:169
NvDsPostProcessNetworkType_Detector
@ NvDsPostProcessNetworkType_Detector
Specifies a detector.
Definition: post_processor_struct.h:195
_NvDsPostProcessContextInitParams
Holds the initialization parameters required for the NvDsPostProcessContext interface.
Definition: post_processor_struct.h:260
NvDsPostProcessFrameOutput
Holds the information inferred by the network on one frame.
Definition: post_processor_struct.h:483
DetectModelPostProcessor::initResource
NvDsPostProcessStatus initResource(NvDsPostProcessContextInitParams &initParams) override
_NvDsFrameMeta
Holds metadata for a frame in a batch.
Definition: nvdsmeta.h:284
DetectModelPostProcessor::attachMetadata
void attachMetadata(NvBufSurface *surf, gint batch_idx, NvDsBatchMeta *batch_meta, NvDsFrameMeta *frame_meta, NvDsObjectMeta *object_meta, NvDsObjectMeta *parent_obj_meta, NvDsPostProcessFrameOutput &detection_output, NvDsPostProcessDetectionParams *all_params, std::set< gint > &filterOutClassIds, int32_t unique_id, gboolean output_instance_mask, gboolean process_full_frame, float segmentationThreshold, gboolean maintain_aspect_ratio) override
NvDsPostProcessParseDetectionParams
Holds the detection parameters required for parsing objects.
Definition: post_processor_struct.h:539
_NvDsObjectMeta
Holds metadata for an object in the frame.
Definition: nvdsmeta.h:342