bbox_utils.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright (c) 2021 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 "model_deploy/utils/include/bbox_utils.h"
  15. namespace PaddleDeploy {
  16. bool FilterBbox(const std::vector<Result> &results,
  17. const float &score_thresh,
  18. std::vector<Result>* filter_results) {
  19. for (auto i = 0; i < results.size(); ++i) {
  20. if ("det" != results[i].model_type) {
  21. std::cerr << "FilterBbox can be only done on results from a det model, "
  22. << "but the received results are from a "
  23. << results[i].model_type << " model." << std::endl;
  24. return false;
  25. }
  26. }
  27. for (auto i = 0; i < results.size(); ++i) {
  28. Result result;
  29. result.model_type = "det";
  30. result.det_result = new DetResult();
  31. std::vector<Box> boxes = results[i].det_result->boxes;
  32. for (auto j = 0; j < boxes.size(); ++j) {
  33. if (boxes[j].score >= score_thresh) {
  34. Box box;
  35. box.category_id = boxes[j].category_id;
  36. box.category = boxes[j].category;
  37. box.score = boxes[j].score;
  38. box.coordinate.assign(boxes[j].coordinate.begin(),
  39. boxes[j].coordinate.end());
  40. box.mask.data.assign(boxes[j].mask.data.begin(),
  41. boxes[j].mask.data.end());
  42. box.mask.shape.assign(boxes[j].mask.shape.begin(),
  43. boxes[j].mask.shape.end());
  44. result.det_result->boxes.push_back(std::move(box));
  45. }
  46. }
  47. result.det_result->mask_resolution = results[i].det_result->mask_resolution;
  48. filter_results->push_back(std::move(result));
  49. }
  50. return true;
  51. }
  52. } // namespace PaddleDeploy