NVIDIA DeepStream SDK API Reference

7.0 Release
FacialLandmarks.h
Go to the documentation of this file.
1 /*###############################################################################
2 #
3 # Copyright(c) 2020 NVIDIA CORPORATION. All Rights Reserved.
4 #
5 # NVIDIA CORPORATION and its licensors retain all intellectual property
6 # and proprietary rights in and to this software, related documentation
7 # and any modifications thereto. Any use, reproduction, disclosure or
8 # distribution of this software and related documentation without an express
9 # license agreement from NVIDIA CORPORATION is strictly prohibited.
10 #
11 ###############################################################################*/
12 
13 #ifndef CVCORE_FACIALLANDMARKS_H_
14 #define CVCORE_FACIALLANDMARKS_H_
15 
16 #include <memory>
17 
18 #include <cuda_runtime.h>
19 
20 #include <cv/core/Array.h>
21 #include <cv/core/BBox.h>
22 #include <cv/core/Core.h>
23 #include <cv/core/MathTypes.h>
24 #include <cv/core/Model.h>
25 #include <cv/core/Tensor.h>
26 
27 namespace cvcore { namespace faciallandmarks {
28 
33 
38 
43 
44 enum class OutputLayout
45 {
46  LC,
47  CL
48 };
49 
54 {
55 public:
59  FacialLandmarksPreProcessor() = delete;
60 
61  /*
62  * Constructor for FacialLandmarksPreProcessor.
63  * @param preProcessorParams Image preprocessing parameters.
64  * @param modelInputParams Model input parameters.
65  */
66  FacialLandmarksPreProcessor(const ImagePreProcessingParams &preProcessorParams,
67  const ModelInputParams &modelInputParams);
68 
73 
74  /*
75  * Running preprocessing for a batch of images.
76  * @param preProcessedImagesBatch output images after preprocessing.
77  * @param facesBBoxes faces bboxes to crop the faces region.
78  * @param facesBBoxesScales the scale factors by which to scale facesBBoxes.
79  * @param inputImagesBatch the input images to be preprocessed.
80  * @param stream Cuda stream.
81  */
82  void execute(Tensor<NHWC, C1, F32> &preProcessedImagesBatch, Array<BBox> &facesBBoxes,
83  const Array<float> &facesBBoxesScales, const Tensor<NHWC, C3, U8> &inputImagesBatch,
84  cudaStream_t stream = 0);
85 
86 private:
87  struct FacialLandmarksPreProcessorImpl;
88  std::unique_ptr<FacialLandmarksPreProcessorImpl> m_pImpl;
89 };
90 
95 {
96 public:
100  static constexpr uint32_t MAX_NUM_FACIAL_LANDMARKS = 200;
101 
105  FacialLandmarks() = delete;
106 
107  /*
108  * Constructor for FacialLandmarks.
109  * @param preProcessorParams Image preprocessing parameters.
110  * @param modelInputParams Model input parameters.
111  * @param inferenceParams Inference parameters for the model.
112  * @param numLandmarks Number of output landmarks
113  * @param outputLayout whether the output landmarks are in order of LC...
114  */
115  FacialLandmarks(const ImagePreProcessingParams &preProcessorParams, const ModelInputParams &modelInputParams,
116  const ModelInferenceParams &inferenceParams, size_t numLandmarks = 80,
117  OutputLayout outputLayout = OutputLayout::LC);
118 
122  ~FacialLandmarks();
123 
124  /*
125  * Running FacialLandmarks for a given image.
126  * @param facialKeypointsCoordinates output facial keypoints for a given face.
127  * @param facesBBoxes faces bboxes to crop the faces.
128  * @param facesBBoxesScales the scale factor by wich to scale facesBBoxes.
129  * @param inputImagesBatch the input images to be preprocessed
130  * @param stream Cuda stream
131  */
132  void execute(Array<ArrayN<Vector2f, FacialLandmarks::MAX_NUM_FACIAL_LANDMARKS>> &facialKeypointsCoordinates,
133  Array<BBox> &facesBBoxes, const Array<float> &facesBBoxesScales,
134  const Tensor<NHWC, C3, U8> &inputImagesBatch, cudaStream_t stream = 0);
135 
136 private:
137  struct FacialLandmarksImpl;
138  std::unique_ptr<FacialLandmarksImpl> m_pImpl;
139 };
140 
145 {
146 public:
150  FacialLandmarksPostProcessor() = delete;
151 
152  /*
153  * Constructor for FacialLandmarksPostProcessor.
154  * @param modelInputParams Model input parameters.
155  * @param numLandmarks Number of output landmarks.
156  * @param outputLayout whether the output landmarks are in order of LC...
157  */
158  FacialLandmarksPostProcessor(const ModelInputParams &modelInputParams, size_t numLandmarks = 80,
159  OutputLayout outputLayout = OutputLayout::LC);
160 
165 
169  void allocateStagingBuffers();
170 
171  /*
172  * Running postprocessing for a given image.
173  * @param facialKeypointsCoordinates output facial keypoints for each image in the batch.
174  * @param coordRaw the candidate facial keypoints for a given face.
175  * @param facesBBoxes squarified faces bboxes.
176  * @param stream Cuda stream
177  */
178  void execute(Array<ArrayN<Vector2f, FacialLandmarks::MAX_NUM_FACIAL_LANDMARKS>> &facialKeypointsCoordinates,
179  const Tensor<CL, CX, F32> &coordRaw, const Array<BBox> &facesBBoxes, cudaStream_t stream = 0);
180 
181  /*
182  * Map 126 landmarks Array to 68 landmarks model Array
183  * @param outputLandmarks output array of 68 landmarks.
184  * @param inputLandmarks input array of 126 landmarks.
185  */
186  static void map126LandmarksTo68(Array<Vector2f> &outputLandmarks, const Array<Vector2f> &inputLandmarks);
187 
188  /*
189  * Map 126 landmarks ArrayN to 68 landmarks model Array
190  * @param outputLandmarks output array of 68 landmarks.
191  * @param inputLandmarks input array of 126 landmarks.
192  */
193  static void map126LandmarksTo68(Array<Vector2f> &outputLandmarks,
195 
196  /*
197  * Map 126 landmarks Array to 68 landmarks model ArrayN
198  * @param outputLandmarks output array of 68 landmarks.
199  * @param inputLandmarks input array of 126 landmarks.
200  */
201  static void map126LandmarksTo68(ArrayN<Vector2f, 68> &outputLandmarks, const Array<Vector2f> &inputLandmarks);
202 
203  /*
204  * Map 126 landmarks ArrayN to 68 landmarks model ArrayN
205  * @param outputLandmarks output array of 68 landmarks.
206  * @param inputLandmarks input array of 126 landmarks.
207  */
208  static void map126LandmarksTo68(ArrayN<Vector2f, 68> &outputLandmarks,
210 
211  /*
212  * Map 126 batch landmarks Array to 68 batch landmarks model Array
213  * @param outputLandmarks output array of 68 landmarks.
214  * @param inputLandmarks input array of 126 landmarks.
215  */
216  static void map126LandmarksTo68(
217  Array<ArrayN<Vector2f, 68>> &outputLandmarks,
219 
220 private:
221  struct FacialLandmarksPostProcessorImpl;
222  std::unique_ptr<FacialLandmarksPostProcessorImpl> m_pImpl;
223 };
224 
225 }} // namespace cvcore::faciallandmarks
226 
227 #endif
Model.h
cvcore::faciallandmarks::defaultPreProcessorParams
const CVCORE_API ImagePreProcessingParams defaultPreProcessorParams
Default Image Processing Params for Facial Landmarks.
cvcore::ModelInferenceParams
Struct to describe the model.
Definition: Model.h:34
cvcore::faciallandmarks::FacialLandmarks
Interface for loading and running FacialLandmarks.
Definition: FacialLandmarks.h:94
cvcore
Definition: PnP.h:20
MathTypes.h
cvcore::faciallandmarks::OutputLayout
OutputLayout
Definition: FacialLandmarks.h:44
Array.h
cvcore::faciallandmarks::FacialLandmarksPreProcessor
Interface for running pre-processing for FacialLandmarks.
Definition: FacialLandmarks.h:53
cudaStream_t
struct CUstream_st * cudaStream_t
Forward declaration of cudaStream_t.
Definition: nvbufsurftransform.h:34
cvcore::Tensor
Definition: Tensor.h:704
cvcore::faciallandmarks::FacialLandmarksPostProcessor
Interface for running post-processing for FacialLandmarks.
Definition: FacialLandmarks.h:144
cvcore::faciallandmarks::OutputLayout::CL
@ CL
cvcore::Array
Implementation of Array class.
Definition: Array.h:133
cvcore::ImagePreProcessingParams
Struct type for image preprocessing params.
Definition: Image.h:67
cvcore::faciallandmarks::defaultModelInputParams
const CVCORE_API ModelInputParams defaultModelInputParams
Default Model Input Params for FacialLandmarks.
CVCORE_API
#define CVCORE_API
Definition: Core.h:24
Tensor.h
cvcore::ModelInputParams
Struct to describe input type required by the model.
Definition: Model.h:23
BBox.h
cvcore::faciallandmarks::defaultInferenceParams
const CVCORE_API ModelInferenceParams defaultInferenceParams
Default inference Params for FacialLandmarks.
cvcore::ArrayN
Implementation of ArrayN class.
Definition: Array.h:258
Core.h
cvcore::faciallandmarks::OutputLayout::LC
@ LC