uvdoc_preprocessor.cc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #include "ultra_infer/vision/ocr/ppocr/uvdoc_preprocessor.h"
  15. #include "ultra_infer/vision/ocr/ppocr/utils/ocr_utils.h"
  16. namespace ultra_infer {
  17. namespace vision {
  18. namespace ocr {
  19. UVDocPreprocessor::UVDocPreprocessor() {
  20. normalize_permute_op_ = std::make_shared<NormalizeAndPermute>(
  21. std::vector<float>({0.0f, 0.0f, 0.0f}),
  22. std::vector<float>({1.0f, 1.0f, 1.0f}), true);
  23. }
  24. bool UVDocPreprocessor::Apply(FDMatBatch *image_batch,
  25. std::vector<FDTensor> *outputs) {
  26. if (!disable_normalize_ && !disable_permute_) {
  27. (*normalize_permute_op_)(image_batch);
  28. }
  29. outputs->resize(1);
  30. FDTensor *tensor = image_batch->Tensor();
  31. (*outputs)[0].SetExternalData(tensor->Shape(), tensor->Dtype(),
  32. tensor->Data(), tensor->device,
  33. tensor->device_id);
  34. return true;
  35. }
  36. } // namespace ocr
  37. } // namespace vision
  38. } // namespace ultra_infer