postprocess_op.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #include "include/clipper.h"
  27. #include "include/utility.h"
  28. using namespace std;
  29. namespace PaddleOCR {
  30. class PostProcessor {
  31. public:
  32. void GetContourArea(const std::vector<std::vector<float>> &box,
  33. float unclip_ratio, float &distance);
  34. cv::RotatedRect UnClip(std::vector<std::vector<float>> box,
  35. const float &unclip_ratio);
  36. float **Mat2Vec(cv::Mat mat);
  37. std::vector<std::vector<int>>
  38. OrderPointsClockwise(std::vector<std::vector<int>> pts);
  39. std::vector<std::vector<float>> GetMiniBoxes(cv::RotatedRect box,
  40. float &ssid);
  41. float BoxScoreFast(std::vector<std::vector<float>> box_array, cv::Mat pred);
  42. std::vector<std::vector<std::vector<int>>>
  43. BoxesFromBitmap(const cv::Mat pred, const cv::Mat bitmap,
  44. const float &box_thresh, const float &det_db_unclip_ratio);
  45. std::vector<std::vector<std::vector<int>>>
  46. FilterTagDetRes(std::vector<std::vector<std::vector<int>>> boxes,
  47. float ratio_h, float ratio_w, cv::Mat srcimg);
  48. private:
  49. static bool XsortInt(std::vector<int> a, std::vector<int> b);
  50. static bool XsortFp32(std::vector<float> a, std::vector<float> b);
  51. std::vector<std::vector<float>> Mat2Vector(cv::Mat mat);
  52. inline int _max(int a, int b) { return a >= b ? a : b; }
  53. inline int _min(int a, int b) { return a >= b ? b : a; }
  54. template <class T> inline T clamp(T x, T min, T max) {
  55. if (x > max)
  56. return max;
  57. if (x < min)
  58. return min;
  59. return x;
  60. }
  61. inline float clampf(float x, float min, float max) {
  62. if (x > max)
  63. return max;
  64. if (x < min)
  65. return min;
  66. return x;
  67. }
  68. };
  69. } // namespace PaddleOCR