NVIDIA DeepStream SDK API Reference

9.1 Release
9.1/sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_bodypose.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_BODYPOSE_HPP__
19 #define __POST_PROCESSOR_BODYPOSE_HPP__
20 
21 #include "post_processor.h"
22 #include "nvdsmeta_schema.h"
23 
24 #include <cmath>
25 
26 class OneEuroFilter {
27 public:
30  reset(30.0f /* Hz */, 0.1f /* Hz */, 0.09f /* ??? */, 0.5f /* Hz */);
31  }
37  OneEuroFilter(float dataUpdateRate, float minCutoffFreq, float cutoffSlope, float derivCutoffFreq) {
38  reset(dataUpdateRate, minCutoffFreq, cutoffSlope, derivCutoffFreq);
39  }
45  void reset(float dataUpdateRate, float minCutoffFreq, float cutoffSlope, float derivCutoffFreq) {
46  reset(); _rate = dataUpdateRate; _minCutoff = minCutoffFreq; _beta = cutoffSlope; _dCutoff = derivCutoffFreq;
47  }
49  void reset() { _firstTime = true; _xFilt.reset(); _dxFilt.reset(); }
53  float filter(float x)
54  {
55  float dx, edx, cutoff;
56  if (_firstTime) {
57  _firstTime = false;
58  dx = 0;
59  } else {
60  dx = (x - _xFilt.hatXPrev()) * _rate;
61  }
62  edx = _dxFilt.filter(dx, alpha(_rate, _dCutoff));
63  cutoff = _minCutoff + _beta * fabsf(edx);
64  return _xFilt.filter(x, alpha(_rate, cutoff));
65  }
66 
67 
68 private:
69  class LowPassFilter {
70  public:
71  LowPassFilter() { reset(); }
72  void reset() { _firstTime = true; }
73  float hatXPrev() const { return _hatXPrev; }
74  float filter(float x, float alpha){
75  if (_firstTime) {
76  _firstTime = false;
77  _hatXPrev = x;
78  }
79  float hatX = alpha * x + (1.f - alpha) * _hatXPrev;
80  _hatXPrev = hatX;
81  return hatX;
82 
83  }
84  private:
85  float _hatXPrev;
86  bool _firstTime;
87  };
88  inline float alpha(float rate, float cutoff) {
89  const float kOneOverTwoPi = 0.15915494309189533577f; // 1 / (2 * pi)
90  // The paper has 4 divisions, but we only use one
91  // float tau = kOneOverTwoPi / cutoff, te = 1.f / rate;
92  // return 1.f / (1.f + tau / te);
93  return cutoff / (rate * kOneOverTwoPi + cutoff);
94 }
95  bool _firstTime;
96  float _rate, _minCutoff, _dCutoff, _beta;
97  LowPassFilter _xFilt, _dxFilt;
98 };
99 
100 constexpr int NVDS_OBJECT_TYPE_PERSON_EXT_POSE = 0x103;
101 
102 typedef struct NvDsPersonPoseExt {
103  gint num_poses;
104  NvDsJoints *poses;
106 
107 
109 
110 public:
111  BodyPoseModelPostProcessor(int id, int gpuId = 0)
113 
114  ~BodyPoseModelPostProcessor() override = default;
115 
117  initResource(NvDsPostProcessContextInitParams& initParams) override;
118 
119  NvDsPostProcessStatus parseEachFrame(const std::vector <NvDsInferLayerInfo>&
120  outputLayers,
121  NvDsPostProcessFrameOutput &result) override;
122 
123  void
124  attachMetadata (NvBufSurface *surf, gint batch_idx,
125  NvDsBatchMeta *batch_meta,
126  NvDsFrameMeta *frame_meta,
127  NvDsObjectMeta *object_meta,
128  NvDsObjectMeta *parent_obj_meta,
129  NvDsPostProcessFrameOutput & detection_output,
130  NvDsPostProcessDetectionParams *all_params,
131  std::set <gint> & filterOutClassIds,
132  int32_t unique_id,
133  gboolean output_instance_mask,
134  gboolean process_full_frame,
135  float segmentationThreshold,
136  gboolean maintain_aspect_ratio,
137  NvDsRoiMeta *roi_meta,
138  gboolean symmetric_padding)
139  override;
140 
141  void releaseFrameOutput(NvDsPostProcessFrameOutput& frameOutput) override;
142 private:
143  NvDsPostProcessStatus fillBodyPoseOutput(
144  const std::vector<NvDsInferLayerInfo>& outputLayers,
146  void osdBody(NvDsFrameMeta* frame_meta,
147  NvDsBatchMeta *bmeta,
148  NvDsDisplayMeta *dmeta,
149  const int numKeyPoints,
150  const float keypoints[],
151  const float keypoints_confidence[]);
152 
153  void movenetposeFromTensorMeta(
154  const std::vector<NvDsInferLayerInfo>& outputLayers,
156 
157  float median(std::vector<float>& v);
158 
159  float m_ClassificationThreshold = 0.50;
160  std::unordered_map<gint , std::vector<OneEuroFilter>> m_filter_pose;
161  OneEuroFilter m_filterRootDepth; // Root node in pose25d.
162  fpos_t m_fp_25_pos;
163 };
164 
165 #endif
NvDsDisplayMeta
Holds display metadata that the user can specify in the frame.
Definition: sources/includes/nvdsmeta.h:457
OneEuroFilter::reset
void reset(float dataUpdateRate, float minCutoffFreq, float cutoffSlope, float derivCutoffFreq)
Reset all parameters of the filter.
Definition: 9.1/sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_bodypose.h:45
BodyPoseModelPostProcessor::initResource
NvDsPostProcessStatus initResource(NvDsPostProcessContextInitParams &initParams) override
NvDsPostProcessDetectionParams
Holds detection and bounding box grouping parameters.
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_struct.h:212
NvDsPersonPoseExt
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_bodypose.h:102
ModelPostProcessor
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor.h:51
BodyPoseModelPostProcessor::releaseFrameOutput
void releaseFrameOutput(NvDsPostProcessFrameOutput &frameOutput) override
NvBufSurface
Holds information about batched buffers.
Definition: sources/includes/nvbufsurface.h:597
NVDS_OBJECT_TYPE_PERSON_EXT_POSE
constexpr int NVDS_OBJECT_TYPE_PERSON_EXT_POSE
Definition: 9.1/sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_bodypose.h:100
BodyPoseModelPostProcessor::parseEachFrame
NvDsPostProcessStatus parseEachFrame(const std::vector< NvDsInferLayerInfo > &outputLayers, NvDsPostProcessFrameOutput &result) override
BodyPoseModelPostProcessor::~BodyPoseModelPostProcessor
~BodyPoseModelPostProcessor() override=default
NvDsPostProcessStatus
NvDsPostProcessStatus
Enum for the status codes returned by NvDsPostProcessAlgorithm.
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_struct.h:78
NvDsPostProcessNetworkType_BodyPose
@ NvDsPostProcessNetworkType_BodyPose
Bodypose 3D.
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_struct.h:201
NvDsPersonPoseExt
struct NvDsPersonPoseExt NvDsPersonPoseExt
OneEuroFilter::reset
void reset()
Reset only the initial condition of the filter, leaving parameters the same.
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_bodypose.h:49
BodyPoseModelPostProcessor
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_bodypose.h:108
BodyPoseModelPostProcessor::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
NvDsPersonPoseExt::poses
NvDsJoints * poses
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_bodypose.h:104
OneEuroFilter
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_bodypose.h:26
_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
OneEuroFilter::OneEuroFilter
OneEuroFilter()
Default constructor.
Definition: 9.1/sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_bodypose.h:29
post_processor.h
OneEuroFilter::OneEuroFilter
OneEuroFilter(float dataUpdateRate, float minCutoffFreq, float cutoffSlope, float derivCutoffFreq)
Constructor.
Definition: 9.1/sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_bodypose.h:37
NvDsPostProcessFrameOutput
Holds the information inferred by the network on one frame.
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_struct.h:502
OneEuroFilter::filter
float filter(float x)
Apply the one euro filter to the given input.
Definition: 9.1/sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_bodypose.h:53
NvDsPostProcessBodyPoseOutput
Holds information parsed from bodypose network output for one frame.
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_struct.h:487
NvDsRoiMeta
Holds Information about ROI Metadata.
Definition: sources/includes/nvds_roi_meta.h:95
NvDsJoints
Holds a body pose's joint points.
Definition: sources/includes/nvdsmeta_schema.h:257
_NvDsFrameMeta
Holds metadata for a frame in a batch.
Definition: sources/includes/nvdsmeta.h:306
NvDsPersonPoseExt::num_poses
gint num_poses
Definition: sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_bodypose.h:103
BodyPoseModelPostProcessor::BodyPoseModelPostProcessor
BodyPoseModelPostProcessor(int id, int gpuId=0)
Definition: 9.1/sources/gst-plugins/gst-nvdspostprocess/postprocesslib_impl/post_processor_bodypose.h:111
_NvDsObjectMeta
Holds metadata for an object in the frame.
Definition: sources/includes/nvdsmeta.h:365