|
@@ -55,9 +55,34 @@ namespace gsd
|
|
|
*/
|
|
|
void MonitorPlugin::MonitorProThrd(){
|
|
|
FrameInferData::Ptr result = std::make_shared<FrameInferData>();
|
|
|
- HepuTarget::Ptr target = std::make_shared<HepuTarget>();
|
|
|
- if(!this->ConsumeData(result,target)) return;
|
|
|
- if(result->Num == 0) return;
|
|
|
+
|
|
|
+ if(config::getPtr()->Hepu)
|
|
|
+ {
|
|
|
+ if(config::getPtr()->HepuProtocol == 17)
|
|
|
+ {
|
|
|
+ HepuTarget::Ptr target = std::make_shared<HepuTarget>();
|
|
|
+ if(!this->ConsumeData1(result,target)) return;
|
|
|
+ if(result->Num == 0) return;
|
|
|
+ if(HepuPlugin::getPtr()->Alive()){
|
|
|
+ HepuPlugin::getPtr()->SendTarget(*target);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(config::getPtr()->HepuProtocol == 31)
|
|
|
+ {
|
|
|
+ HepuTarget2::Ptr target = std::make_shared<HepuTarget2>();
|
|
|
+ if(!this->ConsumeData2(result,target)) return;
|
|
|
+ if(result->Num == 0) return;
|
|
|
+ if(HepuPlugin::getPtr()->Alive()){
|
|
|
+ HepuPlugin::getPtr()->SendTarget2(*target);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(!this->ConsumeData(result)) return;
|
|
|
+ if(result->Num == 0) return;
|
|
|
+ }
|
|
|
+
|
|
|
if(!TcpPlugin::getPtr()->Alive()){
|
|
|
result->uuid = uuid::generate();
|
|
|
std::string sql = result->ObjectToSql();
|
|
@@ -116,14 +141,82 @@ namespace gsd
|
|
|
#endif
|
|
|
});
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- //send data to hepu
|
|
|
- if(config::getPtr()->Hepu)
|
|
|
- {
|
|
|
- if(HepuPlugin::getPtr()->Alive()){
|
|
|
- HepuPlugin::getPtr()->SendTarget(*target);
|
|
|
+ /**
|
|
|
+ * @description:
|
|
|
+ * @param {Ptr&} result
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ bool MonitorPlugin::ConsumeData(FrameInferData::Ptr& result){
|
|
|
+ std::shared_ptr<CNStreamInferData> cnstreamInferData = std::make_shared<CNStreamInferData>();
|
|
|
+ if(this->monitor == nullptr) return false;
|
|
|
+ auto result_data = monitor->ConsumeData(cnstreamInferData);
|
|
|
+ if(result_data.first){
|
|
|
+ // 纠察器
|
|
|
+ if(config::getPtr()->InferChecker){
|
|
|
+ CNStreamInferData data = *cnstreamInferData;
|
|
|
+ std::string _ImageBase64 = data.ImageBase64;
|
|
|
+ data.ImageBase64 = "";
|
|
|
+ std::string _json;
|
|
|
+ data.StreamName = config::getPtr()->getSimCode();
|
|
|
+ data.objectToJson(_json);
|
|
|
+ auto checkResultMsg = HttpPlugin::getPtr()->getCheck(_ImageBase64, _json);
|
|
|
+ if(checkResultMsg.first == false && checkResultMsg.second == "") {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 避免gsd—check服务失效
|
|
|
+ if(checkResultMsg.second != "Service unavailable"){
|
|
|
+ CNStreamInferData ChectResult;
|
|
|
+ if(ChectResult.jsonToObject(checkResultMsg.second)){
|
|
|
+ if(ChectResult.Objects.empty()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 以纠察器的结果为准
|
|
|
+ cnstreamInferData->Objects = ChectResult.Objects;
|
|
|
+ // 相识库数据对比, 避免定点的误识别
|
|
|
+ InfineFilter::getPtr()->SimilarityResult(cnstreamInferData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 解析数据成功
|
|
|
+ rapidjson::StringBuffer buffer;
|
|
|
+ rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
|
|
+ writer.StartArray();
|
|
|
+
|
|
|
+ for(auto &obj : cnstreamInferData->Objects)
|
|
|
+ {
|
|
|
+ writer.StartObject();
|
|
|
+ writer.Key("x");
|
|
|
+ writer.Double(obj.BBox.x * 1920);
|
|
|
+ writer.Key("y");
|
|
|
+ writer.Double(obj.BBox.y * 1080);
|
|
|
+ writer.Key("width");
|
|
|
+ writer.Double(obj.BBox.w * 1920);
|
|
|
+ writer.Key("height");
|
|
|
+ writer.Double(obj.BBox.h * 1080);
|
|
|
+ writer.EndObject();
|
|
|
}
|
|
|
+ writer.EndArray();
|
|
|
+
|
|
|
+ // 获取时间
|
|
|
+ char ctime[80];
|
|
|
+ time_t rawtime;
|
|
|
+ struct tm *info;
|
|
|
+ time(&rawtime);
|
|
|
+ info = localtime(&rawtime);
|
|
|
+ strftime(ctime, 80, "%Y-%m-%d %H:%M:%S", info);
|
|
|
+
|
|
|
+ result->ClassId = 1;
|
|
|
+ result->ImageBase64 = cnstreamInferData->ImageBase64;
|
|
|
+ result->Remark = buffer.GetString();
|
|
|
+ result->Num = cnstreamInferData->Objects.size();
|
|
|
+ result->WarningTime = ctime;
|
|
|
+ result->VideoPath = cnstreamInferData->videoPath;
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -131,7 +224,7 @@ namespace gsd
|
|
|
* @param {Ptr&} result
|
|
|
* @return {*}
|
|
|
*/
|
|
|
- bool MonitorPlugin::ConsumeData(FrameInferData::Ptr& result, HepuTarget::Ptr& target){
|
|
|
+ bool MonitorPlugin::ConsumeData1(FrameInferData::Ptr& result, HepuTarget::Ptr& target){
|
|
|
std::shared_ptr<CNStreamInferData> cnstreamInferData = std::make_shared<CNStreamInferData>();
|
|
|
if(this->monitor == nullptr) return false;
|
|
|
auto result_data = monitor->ConsumeData(cnstreamInferData);
|
|
@@ -184,6 +277,74 @@ namespace gsd
|
|
|
|
|
|
if(config::getPtr()->Hepu)
|
|
|
{
|
|
|
+ //find the biggest target
|
|
|
+ double tar_max = 0;
|
|
|
+ for(auto &obj : cnstreamInferData->Objects)
|
|
|
+ {
|
|
|
+ double size_temp = obj.BBox.w*obj.BBox.w + obj.BBox.h*obj.BBox.h;
|
|
|
+ if( size_temp >= tar_max)
|
|
|
+ {
|
|
|
+ tar_max = size_temp;
|
|
|
+ target->trackingRect.x = obj.BBox.x * 1920;
|
|
|
+ target->trackingRect.y = obj.BBox.y * 1080;
|
|
|
+ target->trackingRect.w = obj.BBox.w * 1920;
|
|
|
+ target->trackingRect.h = obj.BBox.h * 1080;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取时间
|
|
|
+ char ctime[80];
|
|
|
+ time_t rawtime;
|
|
|
+ struct tm *info;
|
|
|
+ time(&rawtime);
|
|
|
+ info = localtime(&rawtime);
|
|
|
+ strftime(ctime, 80, "%Y-%m-%d %H:%M:%S", info);
|
|
|
+
|
|
|
+ result->ClassId = 1;
|
|
|
+ result->ImageBase64 = cnstreamInferData->ImageBase64;
|
|
|
+ result->Remark = buffer.GetString();
|
|
|
+ result->Num = cnstreamInferData->Objects.size();
|
|
|
+ result->WarningTime = ctime;
|
|
|
+ result->VideoPath = cnstreamInferData->videoPath;
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description:
|
|
|
+ * @param {Ptr&} result
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ bool MonitorPlugin::ConsumeData2(FrameInferData::Ptr& result, HepuTarget2::Ptr& target){
|
|
|
+ std::shared_ptr<CNStreamInferData> cnstreamInferData = std::make_shared<CNStreamInferData>();
|
|
|
+ if(this->monitor == nullptr) return false;
|
|
|
+ auto result_data = monitor->ConsumeData(cnstreamInferData);
|
|
|
+ if(result_data.first){
|
|
|
+ // 解析数据成功
|
|
|
+ rapidjson::StringBuffer buffer;
|
|
|
+ rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
|
|
+ writer.StartArray();
|
|
|
+
|
|
|
+ for(auto &obj : cnstreamInferData->Objects)
|
|
|
+ {
|
|
|
+ writer.StartObject();
|
|
|
+ writer.Key("x");
|
|
|
+ writer.Double(obj.BBox.x * 1920);
|
|
|
+ writer.Key("y");
|
|
|
+ writer.Double(obj.BBox.y * 1080);
|
|
|
+ writer.Key("width");
|
|
|
+ writer.Double(obj.BBox.w * 1920);
|
|
|
+ writer.Key("height");
|
|
|
+ writer.Double(obj.BBox.h * 1080);
|
|
|
+ writer.EndObject();
|
|
|
+ }
|
|
|
+ writer.EndArray();
|
|
|
+
|
|
|
+ if(config::getPtr()->Hepu)
|
|
|
+ {
|
|
|
int x_center,y_center,w_center,h_center;
|
|
|
int dist2mid = 167936;//320*320 + 256*256;
|
|
|
for(auto &obj : cnstreamInferData->Objects)
|
|
@@ -201,10 +362,12 @@ namespace gsd
|
|
|
dist2mid = dist2mid_temp;
|
|
|
}
|
|
|
}
|
|
|
- target->trackingRect.x = x_center;
|
|
|
- target->trackingRect.y = y_center;
|
|
|
- target->trackingRect.w = w_center;
|
|
|
- target->trackingRect.h = h_center;
|
|
|
+ target->size.width = 1920;
|
|
|
+ target->size.height = 1080;
|
|
|
+ target->rect.x = x_center;
|
|
|
+ target->rect.y = y_center;
|
|
|
+ target->rect.width = w_center;
|
|
|
+ target->rect.height = h_center;
|
|
|
}
|
|
|
|
|
|
// 获取时间
|