uvdoc_preprocessor.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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/manager.h"
  16. #include "ultra_infer/vision/common/processors/normalize_and_permute.h"
  17. #include "ultra_infer/vision/common/result.h"
  18. namespace ultra_infer {
  19. namespace vision {
  20. namespace ocr {
  21. /*! @brief Preprocessor object for UVDoc serials model.
  22. */
  23. class ULTRAINFER_DECL UVDocPreprocessor : public ProcessorManager {
  24. public:
  25. UVDocPreprocessor();
  26. /** \brief Process the input image and prepare input tensors for runtime
  27. *
  28. * \param[in] images The input image data list, all the elements are returned
  29. * wrapped by FDMat. \param[in] output The output tensors which will feed in
  30. * runtime \return true if the preprocess succeeded, otherwise false
  31. */
  32. virtual bool Apply(FDMatBatch *image_batch, std::vector<FDTensor> *outputs);
  33. /// Set preprocess normalize parameters, please call this API to customize
  34. /// the normalize parameters, otherwise it will use the default normalize
  35. /// parameters.
  36. void SetNormalize(const std::vector<float> &mean,
  37. const std::vector<float> &std, bool is_scale) {
  38. normalize_permute_op_ =
  39. std::make_shared<NormalizeAndPermute>(mean, std, is_scale);
  40. }
  41. /// This function will disable normalize in preprocessing step.
  42. void DisableNormalize() { disable_permute_ = true; }
  43. /// This function will disable hwc2chw in preprocessing step.
  44. void DisablePermute() { disable_normalize_ = true; }
  45. private:
  46. // for recording the switch of hwc2chw
  47. bool disable_permute_ = false;
  48. // for recording the switch of normalize
  49. bool disable_normalize_ = false;
  50. std::shared_ptr<NormalizeAndPermute> normalize_permute_op_;
  51. };
  52. } // namespace ocr
  53. } // namespace vision
  54. } // namespace ultra_infer