preprocessor.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 AdaFace serials model.
  21. */
  22. class ULTRAINFER_DECL AdaFacePreprocessor {
  23. public:
  24. /** \brief Create a preprocessor instance for AdaFace serials model
  25. */
  26. AdaFacePreprocessor();
  27. /** \brief Process the input image and prepare input tensors for runtime
  28. *
  29. * \param[in] images The input image data list, all the elements are returned
  30. * by cv::imread() \param[in] outputs The output tensors which will feed in
  31. * runtime \return true if the preprocess succeeded, otherwise false
  32. */
  33. bool Run(std::vector<FDMat> *images, std::vector<FDTensor> *outputs);
  34. /// Get Size
  35. std::vector<int> GetSize() { return size_; }
  36. /// Set size.
  37. void SetSize(std::vector<int> &size) { size_ = size; }
  38. /// Get alpha
  39. std::vector<float> GetAlpha() { return alpha_; }
  40. /// Set alpha.
  41. void SetAlpha(std::vector<float> &alpha) { alpha_ = alpha; }
  42. /// Get beta
  43. std::vector<float> GetBeta() { return beta_; }
  44. /// Set beta.
  45. void SetBeta(std::vector<float> &beta) { beta_ = beta; }
  46. bool GetPermute() { return permute_; }
  47. /// Set permute.
  48. void SetPermute(bool permute) { permute_ = permute; }
  49. protected:
  50. bool Preprocess(FDMat *mat, FDTensor *output);
  51. // Argument for image preprocessing step, tuple of (width, height),
  52. // decide the target size after resize, default (112, 112)
  53. std::vector<int> size_;
  54. // Argument for image preprocessing step, alpha values for normalization,
  55. // default alpha = {1.f / 127.5f, 1.f / 127.5f, 1.f / 127.5f};
  56. std::vector<float> alpha_;
  57. // Argument for image preprocessing step, beta values for normalization,
  58. // default beta = {-1.f, -1.f, -1.f}
  59. std::vector<float> beta_;
  60. // Argument for image preprocessing step, whether to swap the B and R channel,
  61. // such as BGR->RGB, default true.
  62. bool permute_;
  63. };
  64. } // namespace faceid
  65. } // namespace vision
  66. } // namespace ultra_infer