NVIDIA DeepStream SDK API Reference

7.1 Release
post_processor_detect.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2022-2024 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,
61  NvDsRoiMeta *roi_meta,
62  gboolean symmetric_padding) override;
63 
64  void releaseFrameOutput(NvDsPostProcessFrameOutput& frameOutput) override;
65  private:
66  bool parseBoundingBox(std::vector <NvDsInferLayerInfo> const&
67  outputLayersInfo,
68  NvDsInferNetworkInfo const& networkInfo,
69  NvDsPostProcessParseDetectionParams const& detectionParams,
70  std::vector<NvDsPostProcessObjectDetectionInfo>& objectList);
71  std::vector<int> nonMaximumSuppression(
72  std::vector <std::pair<float,int>>& scoreIndex,
73  std::vector<NvDsPostProcessParseObjectInfo> &bbox,
74  float const nmsThreshold);
75 
76  void clusterAndFillDetectionOutputHybrid(NvDsPostProcessDetectionOutput& output);
77  void clusterAndFillDetectionOutputNMS(NvDsPostProcessDetectionOutput& output);
78  void clusterAndFillDetectionOutputDBSCAN(NvDsPostProcessDetectionOutput& output);
79  void fillUnclusteredOutput(NvDsPostProcessDetectionOutput& output);
80  NvDsPostProcessStatus fillDetectionOutput(const std::vector <NvDsInferLayerInfo>& outputLayers,
82  void preClusteringThreshold(NvDsPostProcessParseDetectionParams const &detectionParams,
83  std::vector<NvDsPostProcessObjectDetectionInfo> &objectList);
84  void filterTopKOutputs(int const topK,
85  std::vector<NvDsPostProcessObjectDetectionInfo> &objectList);
86 
87 private:
88  NvDsPostProcessClusterMode m_ClusterMode;
89 
90  uint32_t m_NumDetectedClasses = 0;
91  std::shared_ptr<NvDsInferDBScan> m_DBScanHandle;
92 
93  std::vector <NvDsPostProcessDetectionParams> m_PerClassDetectionParams;
94  NvDsPostProcessParseDetectionParams m_DetectionParams = {0, {}, {}};
95 
96  std::vector <NvDsPostProcessObjectDetectionInfo> m_ObjectList;
97 #ifdef WITH_OPENCV
98  /* Vector of cv::Rect vectors for each class. */
99  std::vector<std::vector<cv::Rect>> m_PerClassCvRectList;
100 #endif
101  /* Vector of NvDsPostProcessObjectDetectionInfo vectors for each class. */
102  std::vector<std::vector<NvDsPostProcessObjectDetectionInfo>> m_PerClassObjectList;
103 
104  NvDsPostProcessParseCustomFunc m_CustomBBoxParseFunc = nullptr;
105  bool m_PreprocessorSupport = FALSE;
106 
107 };
108 
109 
110 #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:218
DetectModelPostProcessor::releaseFrameOutput
void releaseFrameOutput(NvDsPostProcessFrameOutput &frameOutput) override
ModelPostProcessor
Definition: post_processor.h:57
NvBufSurface
Holds information about batched buffers.
Definition: nvbufsurface.h:520
post_processor.h
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, NvDsRoiMeta *roi_meta, gboolean symmetric_padding) override
NvDsPostProcessDetectionOutput
Holds information on all objects detected by a detector network in one frame.
Definition: post_processor_struct.h:439
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:112
_NvDsBatchMeta
Holds information about a formed batch containing frames from different sources.
Definition: nvdsmeta.h:242
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:262
NvDsPostProcessFrameOutput
Holds the information inferred by the network on one frame.
Definition: post_processor_struct.h:508
DetectModelPostProcessor::initResource
NvDsPostProcessStatus initResource(NvDsPostProcessContextInitParams &initParams) override
NvDsRoiMeta
Holds Information about ROI Metadata.
Definition: nvds_roi_meta.h:86
_NvDsFrameMeta
Holds metadata for a frame in a batch.
Definition: nvdsmeta.h:286
NvDsPostProcessParseDetectionParams
Holds the detection parameters required for parsing objects.
Definition: post_processor_struct.h:567
_NvDsObjectMeta
Holds metadata for an object in the frame.
Definition: nvdsmeta.h:344