InfineFilter.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * @Author: lishengyin lishengyin@sz-sunwin.com
  3. * @Date: 2022-09-04 21:52:11
  4. * @LastEditors: lishengyin
  5. * @LastEditTime: 2022-09-08 11:31:47
  6. * @FilePath: /gsd_check/models/InfineFilter.cpp
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. #include "InfineFilter.hpp"
  10. namespace gsd
  11. {
  12. /**
  13. * @description: 获取ptr
  14. * @return {*}
  15. */
  16. std::shared_ptr<InfineFilter> InfineFilter::getPtr(){
  17. static std::shared_ptr<InfineFilter> m_InfineFilter = nullptr;
  18. if(m_InfineFilter == nullptr) m_InfineFilter = std::shared_ptr<InfineFilter>(new InfineFilter);
  19. return m_InfineFilter;
  20. }
  21. /**
  22. * @description: 比例过滤器
  23. * @param {Ptr} result
  24. * @return {*}
  25. */
  26. bool InfineFilter::proportionalFilter(CNStreamInferData::Ptr result){
  27. int target_num = 0, Alien_num = 0;
  28. auto Alien = config::getPtr()->getAlienLabels();
  29. auto targets = config::getPtr()->getInferTargets();
  30. if(result->Objects.empty() || Alien.empty() || targets.empty()) return true;
  31. for(auto iter = result->Objects.begin(); iter != result->Objects.end(); iter++){
  32. auto it = find(targets.begin(), targets.end(), std::atoi(iter->Label.c_str()));
  33. if(it != targets.end()){
  34. target_num++;
  35. continue;
  36. }
  37. it = find(Alien.begin(), Alien.end(), std::atoi(iter->Label.c_str()));
  38. if(it != Alien.end()){
  39. Alien_num++;
  40. }
  41. }
  42. double Proportion = (double)Alien_num / (double)(target_num + Alien_num);
  43. if(Proportion < config::getPtr()->Proportion_th) return true;
  44. return false;
  45. }
  46. /**
  47. * @description: 异物过滤器
  48. * @param {Ptr} result
  49. * @return {*}
  50. */
  51. bool InfineFilter::AlienFilter(CNStreamInferData::Ptr result){
  52. auto targets = config::getPtr()->getInferTargets();
  53. if(result->Objects.size() == 0 || targets.empty()) return false;
  54. for(auto iter = result->Objects.begin(); iter != result->Objects.end();){
  55. auto it = find(targets.begin(), targets.end(), std::atoi(iter->Label.c_str()));
  56. // 不在目标范围内
  57. if(it == targets.end()) iter = result->Objects.erase(iter);
  58. else iter++;
  59. }
  60. return true;
  61. }
  62. } // namespace gsd