preprocess_op.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (c) 2020 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 "opencv2/core.hpp"
  16. #include "opencv2/imgcodecs.hpp"
  17. #include "opencv2/imgproc.hpp"
  18. #include <chrono>
  19. #include <iomanip>
  20. #include <iostream>
  21. #include <ostream>
  22. #include <vector>
  23. #include <cstring>
  24. #include <fstream>
  25. #include <numeric>
  26. using namespace std;
  27. using namespace paddle;
  28. namespace PaddleOCR {
  29. class Normalize {
  30. public:
  31. virtual void Run(cv::Mat *im, const std::vector<float> &mean,
  32. const std::vector<float> &scale, const bool is_scale = true);
  33. };
  34. // RGB -> CHW
  35. class Permute {
  36. public:
  37. virtual void Run(const cv::Mat *im, float *data);
  38. };
  39. class ResizeImgType0 {
  40. public:
  41. virtual void Run(const cv::Mat &img, cv::Mat &resize_img, int max_size_len,
  42. float &ratio_h, float &ratio_w, bool use_tensorrt);
  43. };
  44. class CrnnResizeImg {
  45. public:
  46. virtual void Run(const cv::Mat &img, cv::Mat &resize_img, float wh_ratio,
  47. bool use_tensorrt = false,
  48. const std::vector<int> &rec_image_shape = {3, 32, 320});
  49. };
  50. class ClsResizeImg {
  51. public:
  52. virtual void Run(const cv::Mat &img, cv::Mat &resize_img,
  53. bool use_tensorrt = false,
  54. const std::vector<int> &rec_image_shape = {3, 48, 192});
  55. };
  56. } // namespace PaddleOCR