preprocessor.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include "ultra_infer/vision/common/processors/transform.h"
  16. #include "ultra_infer/vision/common/result.h"
  17. namespace ultra_infer {
  18. namespace vision {
  19. namespace faceid {
  20. /*! @brief Preprocessor object for InsightFaceRecognition serials model.
  21. */
  22. class ULTRAINFER_DECL InsightFaceRecognitionPreprocessor {
  23. public:
  24. /** \brief Create a preprocessor instance for InsightFaceRecognition serials
  25. * model
  26. */
  27. InsightFaceRecognitionPreprocessor();
  28. /** \brief Process the input image and prepare input tensors for runtime
  29. *
  30. * \param[in] images The input image data list, all the elements are returned
  31. * by cv::imread() \param[in] outputs The output tensors which will feed in
  32. * runtime \return true if the preprocess succeeded, otherwise false
  33. */
  34. bool Run(std::vector<FDMat> *images, std::vector<FDTensor> *outputs);
  35. /// Get Size
  36. std::vector<int> GetSize() { return size_; }
  37. /// Set size.
  38. void SetSize(std::vector<int> &size) { size_ = size; }
  39. /// Get alpha
  40. std::vector<float> GetAlpha() { return alpha_; }
  41. /// Set alpha.
  42. void SetAlpha(std::vector<float> &alpha) { alpha_ = alpha; }
  43. /// Get beta
  44. std::vector<float> GetBeta() { return beta_; }
  45. /// Set beta.
  46. void SetBeta(std::vector<float> &beta) { beta_ = beta; }
  47. /// This function will disable normalize and hwc2chw in preprocessing step.
  48. void DisableNormalize() { disable_normalize_ = true; }
  49. /// This function will disable hwc2chw in preprocessing step.
  50. void DisablePermute() { disable_permute_ = true; }
  51. protected:
  52. bool Preprocess(FDMat *mat, FDTensor *output);
  53. // Argument for image preprocessing step, tuple of (width, height),
  54. // decide the target size after resize, default (112, 112)
  55. std::vector<int> size_;
  56. // Argument for image preprocessing step, alpha values for normalization,
  57. // default alpha = {1.f / 127.5f, 1.f / 127.5f, 1.f / 127.5f};
  58. std::vector<float> alpha_;
  59. // Argument for image preprocessing step, beta values for normalization,
  60. // default beta = {-1.f, -1.f, -1.f}
  61. std::vector<float> beta_;
  62. // for recording the switch of normalize
  63. bool disable_normalize_ = false;
  64. // Argument for image preprocessing step, whether to swap the B and R channel,
  65. // such as BGR->RGB, default true.
  66. bool disable_permute_ = false;
  67. };
  68. } // namespace faceid
  69. } // namespace vision
  70. } // namespace ultra_infer