|
@@ -4,7 +4,7 @@
|
|
* @Autor: lishengyin
|
|
* @Autor: lishengyin
|
|
* @Date: 2022-03-22 14:00:46
|
|
* @Date: 2022-03-22 14:00:46
|
|
* @LastEditors: lishengyin
|
|
* @LastEditors: lishengyin
|
|
- * @LastEditTime: 2022-05-16 09:22:22
|
|
|
|
|
|
+ * @LastEditTime: 2022-06-28 11:13:49
|
|
*/
|
|
*/
|
|
#include "InfineFilter.h"
|
|
#include "InfineFilter.h"
|
|
|
|
|
|
@@ -26,8 +26,22 @@ namespace cnstream{
|
|
labels.push_back(objs[i].GetString());
|
|
labels.push_back(objs[i].GetString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- for(auto iter = labels.begin(); iter != labels.end(); iter++){
|
|
|
|
- LOGE(InfineFilter) << *iter << ",";
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (paramSet.find("AlienLabels") != paramSet.end()) {
|
|
|
|
+ std::string json = paramSet["AlienLabels"];
|
|
|
|
+ rapidjson::Document doc;
|
|
|
|
+ if (doc.Parse<rapidjson::kParseCommentsFlag>(json.c_str()).HasParseError()) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ const auto end = doc.MemberEnd();
|
|
|
|
+ if(end == doc.FindMember("label")|| !(doc["label"].IsArray())){
|
|
|
|
+ return false;
|
|
|
|
+ }else{
|
|
|
|
+ const rapidjson::Value& objs = doc["label"];
|
|
|
|
+ for(size_t i = 0; i < objs.Size(); i++){
|
|
|
|
+ AlienLabels.push_back(objs[i].GetString());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if(paramSet.find("files") != paramSet.end()){
|
|
if(paramSet.find("files") != paramSet.end()){
|
|
@@ -39,6 +53,11 @@ namespace cnstream{
|
|
if(paramSet.find("Night_Filter") != paramSet.end()){
|
|
if(paramSet.find("Night_Filter") != paramSet.end()){
|
|
this->Night_Filter = paramSet["Night_Filter"] == "true" ? true : false;
|
|
this->Night_Filter = paramSet["Night_Filter"] == "true" ? true : false;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if(paramSet.find("Proportion_th") != paramSet.end()){
|
|
|
|
+ this->Proportion_th = atof(paramSet["Proportion_th"].c_str());
|
|
|
|
+ }
|
|
|
|
+
|
|
if(paramSet.find("lock_period") != paramSet.end()){
|
|
if(paramSet.find("lock_period") != paramSet.end()){
|
|
std::string json = paramSet["lock_period"];
|
|
std::string json = paramSet["lock_period"];
|
|
rapidjson::Document doc;
|
|
rapidjson::Document doc;
|
|
@@ -77,6 +96,9 @@ namespace cnstream{
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 异类过滤器
|
|
|
|
+ this->AlienFilter(frame->ImageBGR(), objs_holder);
|
|
|
|
+
|
|
// 过滤某些Id
|
|
// 过滤某些Id
|
|
for(auto iter = objs_holder->objs_.begin(); iter != objs_holder->objs_.end(); ){
|
|
for(auto iter = objs_holder->objs_.begin(); iter != objs_holder->objs_.end(); ){
|
|
std::shared_ptr<cnstream::CNInferObject> object = *iter;
|
|
std::shared_ptr<cnstream::CNInferObject> object = *iter;
|
|
@@ -161,6 +183,51 @@ namespace cnstream{
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * @description: 异类过滤器
|
|
|
|
+ * @param {Mat} image
|
|
|
|
+ * @return {*}
|
|
|
|
+ */
|
|
|
|
+ bool InfineFilter::AlienFilter(cv::Mat image, CNInferObjsPtr& objs_holder){
|
|
|
|
+ // 计算占比
|
|
|
|
+ int num = 0;
|
|
|
|
+ if(objs_holder->objs_.size() == 0) return true;
|
|
|
|
+ for(auto iter = objs_holder->objs_.begin(); iter != objs_holder->objs_.end(); ){
|
|
|
|
+ std::shared_ptr<cnstream::CNInferObject> object = *iter;
|
|
|
|
+ if (!object) continue;
|
|
|
|
+ auto it = find(this->AlienLabels.begin(), this->AlienLabels.end(), object->id);
|
|
|
|
+ if(it != this->AlienLabels.end()){
|
|
|
|
+ num++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ double Proportion = (double)num / (double)(objs_holder->objs_.size());
|
|
|
|
+ if(Proportion > this->Proportion_th) {
|
|
|
|
+ if(this->saveFilterResult){
|
|
|
|
+ cv::Mat img = image.clone();
|
|
|
|
+ for(auto iter = objs_holder->objs_.begin(); iter != objs_holder->objs_.end(); ){
|
|
|
|
+ std::shared_ptr<cnstream::CNInferObject> object = *iter;
|
|
|
|
+ if (!object) continue;
|
|
|
|
+ cv::Point top_left;
|
|
|
|
+ cv::Point bottom_right;
|
|
|
|
+ top_left.x = object->bbox.x * image.cols;
|
|
|
|
+ top_left.y = object->bbox.y * image.rows;
|
|
|
|
+ bottom_right.x = top_left.x + (object->bbox.w * image.cols);
|
|
|
|
+ bottom_right.y = top_left.y + (object->bbox.h * image.rows);
|
|
|
|
+ cv::Point logo_pos(5, image.rows - 5);
|
|
|
|
+ cv::Scalar color(200, 200, 200);
|
|
|
|
+ cv::putText(img, object->id, logo_pos, 0, 1, color, 2);
|
|
|
|
+ cv::rectangle(img, top_left, bottom_right, cv::Scalar(0, 255, 0), 4);
|
|
|
|
+ }
|
|
|
|
+ if(opendir(this->files.c_str()) == NULL){
|
|
|
|
+ mkdir((this->files).c_str(),S_IRWXU|S_IRWXG|S_IRWXO);
|
|
|
|
+ }
|
|
|
|
+ cv::imwrite(this->files + getTime() + "Alien.jpg", img);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
* @description: 判断时间是否为晚上
|
|
* @description: 判断时间是否为晚上
|
|
* @param {*}
|
|
* @param {*}
|
|
* @return {*}
|
|
* @return {*}
|