paddlestructure.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 <include/paddleocr.h>
  16. #include <include/structure_layout.h>
  17. #include <include/structure_table.h>
  18. namespace PaddleOCR {
  19. class PaddleStructure : public PPOCR {
  20. public:
  21. explicit PaddleStructure();
  22. ~PaddleStructure();
  23. std::vector<StructurePredictResult> structure(cv::Mat img,
  24. bool layout = false,
  25. bool table = true,
  26. bool ocr = false);
  27. void reset_timer();
  28. void benchmark_log(int img_num);
  29. private:
  30. std::vector<double> time_info_table = {0, 0, 0};
  31. std::vector<double> time_info_layout = {0, 0, 0};
  32. StructureTableRecognizer *table_model_ = nullptr;
  33. StructureLayoutRecognizer *layout_model_ = nullptr;
  34. void layout(cv::Mat img,
  35. std::vector<StructurePredictResult> &structure_result);
  36. void table(cv::Mat img, StructurePredictResult &structure_result);
  37. std::string rebuild_table(std::vector<std::string> rec_html_tags,
  38. std::vector<std::vector<int>> rec_boxes,
  39. std::vector<OCRPredictResult> &ocr_result);
  40. float dis(std::vector<int> &box1, std::vector<int> &box2);
  41. static bool comparison_dis(const std::vector<float> &dis1,
  42. const std::vector<float> &dis2) {
  43. if (dis1[1] < dis2[1]) {
  44. return true;
  45. } else if (dis1[1] == dis2[1]) {
  46. return dis1[0] < dis2[0];
  47. } else {
  48. return false;
  49. }
  50. }
  51. };
  52. } // namespace PaddleOCR