NVIDIA DeepStream SDK API Reference

9.1 Release
sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2022-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef __POST_PROCESSOR_HPP__
19 #define __POST_PROCESSOR_HPP__
20 
21 #include <iostream>
22 #include <fstream>
23 #include <thread>
24 #include <cstring>
25 #include <queue>
26 #include <mutex>
27 #include <memory>
28 #include <stdexcept>
29 #include <unordered_map>
30 #include <condition_variable>
31 #include <yaml-cpp/yaml.h>
32 #include <limits.h>
33 #include <cassert>
34 #include <algorithm>
35 #include "nvbufsurface.h"
36 #include "nvbufsurftransform.h"
37 #include "gst-nvquery.h"
38 #include "gstnvdsmeta.h"
39 #include "gst-nvevent.h"
40 #include "nvdsinfer_dbscan.h"
41 #include "post_processor_struct.h"
42 
43 
44 #ifndef PP_DISABLE_CLASS_COPY
45 #define PP_DISABLE_CLASS_COPY(NoCopyClass) \
46  NoCopyClass(const NoCopyClass&) = delete; \
47  void operator=(const NoCopyClass&) = delete
48 #endif
49 
50 
52 {
53 
54 protected:
56  : m_NetworkType(type), m_UniqueID(id), m_GpuID(gpuId){}
57 
58 public:
59  virtual ~ModelPostProcessor() = default;
60 
61  virtual NvDsPostProcessStatus
63  const std::vector<std::vector<std::string>>& getLabels() const
64  {
65  return m_Labels;
66  }
69  m_NetworkInfo = networkInfo;
70  }
71 
73  const std::vector <NvDsInferLayerInfo> &outputLayers,
74  NvDsPostProcessFrameOutput& result) = 0;
75 
76 
77  virtual void
78  attachMetadata (NvBufSurface *surf, gint batch_idx,
79  NvDsBatchMeta *batch_meta,
80  NvDsFrameMeta *frame_meta,
81  NvDsObjectMeta *object_meta,
82  NvDsObjectMeta *parent_obj_meta,
83  NvDsPostProcessFrameOutput & detection_output,
85  std::set <gint> & filterOutClassIds,
86  int32_t unique_id,
87  gboolean output_instance_mask,
88  gboolean process_full_frame,
89  float segmentationThreshold,
90  gboolean maintain_aspect_ratio,
91  NvDsRoiMeta *roi_meta,
92  gboolean symmetric_padding) = 0;
93 
94 
95  virtual void releaseFrameOutput(NvDsPostProcessFrameOutput& frameOutput) = 0;
96 
97 protected:
98  NvDsPostProcessStatus parseLabelsFile(const std::string &path);
99 
100 private:
101  PP_DISABLE_CLASS_COPY(ModelPostProcessor);
102 
103 protected:
104  /* Processor type */
106 
107  int m_UniqueID = 0;
108  uint32_t m_GpuID = 0;
109 
110  /* Network input information. */
112  std::vector<NvDsInferLayerInfo> m_AllLayerInfo;
113  std::vector<NvDsInferLayerInfo> m_OutputLayerInfo;
114 
115  /* Holds the string labels for classes. */
116  std::vector<std::vector<std::string>> m_Labels;
117 
118 };
119 
120 #endif
ModelPostProcessor::parseEachFrame
virtual NvDsPostProcessStatus parseEachFrame(const std::vector< NvDsInferLayerInfo > &outputLayers, NvDsPostProcessFrameOutput &result)=0
ModelPostProcessor::getLabels
const std::vector< std::vector< std::string > > & getLabels() const
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor.h:63
ModelPostProcessor::m_AllLayerInfo
std::vector< NvDsInferLayerInfo > m_AllLayerInfo
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor.h:112
ModelPostProcessor::setNetworkInfo
void setNetworkInfo(NvDsInferNetworkInfo networkInfo)
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor.h:68
NvDsPostProcessDetectionParams
Holds detection and bounding box grouping parameters.
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_struct.h:212
ModelPostProcessor
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor.h:51
ModelPostProcessor::initResource
virtual NvDsPostProcessStatus initResource(NvDsPostProcessContextInitParams &initParams)
NvBufSurface
Holds information about batched buffers.
Definition: sources/includes/nvbufsurface.h:597
NvDsPostProcessNetworkType
NvDsPostProcessNetworkType
Defines network types.
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_struct.h:185
ModelPostProcessor::ModelPostProcessor
ModelPostProcessor(NvDsPostProcessNetworkType type, int id, int gpuId)
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor.h:55
ModelPostProcessor::m_Labels
std::vector< std::vector< std::string > > m_Labels
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor.h:116
NvDsPostProcessStatus
NvDsPostProcessStatus
Enum for the status codes returned by NvDsPostProcessAlgorithm.
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_struct.h:78
ModelPostProcessor::m_GpuID
uint32_t m_GpuID
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor.h:108
ModelPostProcessor::m_NetworkInfo
NvDsInferNetworkInfo m_NetworkInfo
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor.h:111
NvDsInferNetworkInfo
Holds information about the model network.
Definition: sources/includes/nvdsinfer.h:119
ModelPostProcessor::m_UniqueID
int m_UniqueID
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor.h:107
_NvDsBatchMeta
Holds information about a formed batch containing frames from different sources.
Definition: sources/includes/nvdsmeta.h:262
_NvDsPostProcessContextInitParams
Holds the initialization parameters required for the NvDsPostProcessContext interface.
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_struct.h:256
ModelPostProcessor::m_OutputLayerInfo
std::vector< NvDsInferLayerInfo > m_OutputLayerInfo
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor.h:113
NvDsPostProcessFrameOutput
Holds the information inferred by the network on one frame.
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_struct.h:502
ModelPostProcessor::attachMetadata
virtual 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)=0
ModelPostProcessor::parseLabelsFile
NvDsPostProcessStatus parseLabelsFile(const std::string &path)
NvDsPostProcessBatchOutput
Holds the output for all of the frames in a batch (an array of frame), and related buffer information...
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_struct.h:531
ModelPostProcessor::m_NetworkType
NvDsPostProcessNetworkType m_NetworkType
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor.h:105
ModelPostProcessor::releaseFrameOutput
virtual void releaseFrameOutput(NvDsPostProcessFrameOutput &frameOutput)=0
NvDsRoiMeta
Holds Information about ROI Metadata.
Definition: sources/includes/nvds_roi_meta.h:95
NvDsPostProcessNetworkType_Other
@ NvDsPostProcessNetworkType_Other
Specifies other.
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_struct.h:206
ModelPostProcessor::~ModelPostProcessor
virtual ~ModelPostProcessor()=default
_NvDsFrameMeta
Holds metadata for a frame in a batch.
Definition: sources/includes/nvdsmeta.h:306
ModelPostProcessor::freeBatchOutput
void freeBatchOutput(NvDsPostProcessBatchOutput &batchOutput)
post_processor_struct.h
_NvDsObjectMeta
Holds metadata for an object in the frame.
Definition: sources/includes/nvdsmeta.h:365