12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- /*
- * @Author: lishengyin lishengyin@sz-sunwin.com
- * @Date: 2022-09-04 21:52:11
- * @LastEditors: lishengyin
- * @LastEditTime: 2022-09-08 11:31:47
- * @FilePath: /gsd_check/models/InfineFilter.cpp
- * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
- */
- #include "InfineFilter.hpp"
- namespace gsd
- {
-
- /**
- * @description: 获取ptr
- * @return {*}
- */
- std::shared_ptr<InfineFilter> InfineFilter::getPtr(){
- static std::shared_ptr<InfineFilter> m_InfineFilter = nullptr;
- if(m_InfineFilter == nullptr) m_InfineFilter = std::shared_ptr<InfineFilter>(new InfineFilter);
- return m_InfineFilter;
- }
-
- /**
- * @description: 比例过滤器
- * @param {Ptr} result
- * @return {*}
- */
- bool InfineFilter::proportionalFilter(CNStreamInferData::Ptr result){
- int target_num = 0, Alien_num = 0;
- auto Alien = config::getPtr()->getAlienLabels();
- auto targets = config::getPtr()->getInferTargets();
- if(result->Objects.empty() || Alien.empty() || targets.empty()) return true;
- for(auto iter = result->Objects.begin(); iter != result->Objects.end(); iter++){
- auto it = find(targets.begin(), targets.end(), std::atoi(iter->Label.c_str()));
- if(it != targets.end()){
- target_num++;
- continue;
- }
- it = find(Alien.begin(), Alien.end(), std::atoi(iter->Label.c_str()));
- if(it != Alien.end()){
- Alien_num++;
- }
- }
- double Proportion = (double)Alien_num / (double)(target_num + Alien_num);
- if(Proportion < config::getPtr()->Proportion_th) return true;
- return false;
- }
- /**
- * @description: 异物过滤器
- * @param {Ptr} result
- * @return {*}
- */
- bool InfineFilter::AlienFilter(CNStreamInferData::Ptr result){
- auto targets = config::getPtr()->getInferTargets();
- if(result->Objects.size() == 0 || targets.empty()) return false;
- for(auto iter = result->Objects.begin(); iter != result->Objects.end();){
- auto it = find(targets.begin(), targets.end(), std::atoi(iter->Label.c_str()));
- // 不在目标范围内
- if(it == targets.end()) iter = result->Objects.erase(iter);
- else iter++;
- }
- return true;
- }
- } // namespace gsd
|