Browse Source

add hepu 4.7.31

qiuyang 1 week ago
parent
commit
b7c9ef9e98

BIN
doc/1_和普威视IPC远程配置协议.docx


+ 156 - 0
framework/request/include/HepuTarget2.h

@@ -0,0 +1,156 @@
+#pragma once
+
+#include <iostream>
+
+#include <rapidjson/document.h>
+#include <rapidjson/rapidjson.h>
+#include <rapidjson/stringbuffer.h>
+#include <rapidjson/writer.h>
+using namespace std;
+
+class HepuTarget2 //doc 4.7.31
+{
+    private:
+    public:
+        using Ptr = std::shared_ptr<HepuTarget2>;
+
+    public:
+        const string cmd = "ivpClientTracking"; 
+        string token;
+        int channelid;//0:红外 1:可见光
+        int trackingStatus;//跟踪状态,0:非跟踪状态;1:跟踪正常;2:跟踪不稳定;3:跟踪目标失锁;4:跟踪目标丢失;10:跟踪通信异常;其他:跟踪失败;
+        typedef struct Size{
+            int width;
+            int height;
+        };
+
+        typedef struct Rect{
+            int x;
+            int y;
+            int width;
+            int height;
+        };
+
+        Size size;//跟踪视频尺寸
+        Rect rect;//跟踪目标在图像上的位置坐标,在跟踪视频尺寸坐标系下
+        
+        double response;//跟踪响应率
+        
+        HepuTarget2(){};
+        ~HepuTarget2(){};
+        void objectToJson(string& str){
+            rapidjson::StringBuffer strBuf;
+            rapidjson::Writer<rapidjson::StringBuffer> writer(strBuf);
+            this->objectToJson(writer);
+            str = strBuf.GetString();
+        }
+
+        void objectToJson(rapidjson::Writer<rapidjson::StringBuffer>& writer){
+            writer.StartObject();
+
+            writer.Key("cmd");
+            writer.String(cmd.c_str());
+
+            writer.Key("param");
+            writer.StartObject();
+
+            writer.Key("token");
+            writer.String(token.c_str());   
+
+            writer.Key("channelid");
+            writer.Int(channelid);
+
+            writer.Key("trackingStatus");
+            writer.Int(trackingStatus);
+
+            writer.Key("size");
+            writer.StartArray();
+            writer.Int(size.width);
+            writer.Int(size.height);
+            writer.EndArray();
+
+            writer.Key("rect");
+            writer.StartArray();
+            writer.Int(rect.x);
+            writer.Int(rect.y);
+            writer.Int(rect.width);
+            writer.Int(rect.height);
+            writer.EndArray();
+
+            writer.Key("response");
+            writer.Double(response);
+
+            writer.EndObject();
+
+            writer.EndObject();
+        }
+
+        bool jsonToObject(std::string& json){
+            rapidjson::Document doc;
+            doc.Parse(json.c_str());
+            if(!doc.IsObject()){
+                return false;
+            }
+
+            const auto end = doc.MemberEnd();
+
+            if(end == doc.FindMember("cmd") || !doc["cmd"].IsString()){
+                return false;
+            }else{
+                if(cmd != doc["cmd"].GetString())
+                    return false;
+            }            
+
+            if(end == doc.FindMember("param") || !doc["param"].IsObject()) {
+                return false;
+            }else{
+                if(end == doc.FindMember("token") || !doc["token"].IsString()) {
+                    return false;
+                }else{
+                    token = doc["token"].GetString();
+                }
+
+                if(end == doc.FindMember("channelid") || !doc["channelid"].IsInt()) {
+                    return false;
+                }else{
+                    channelid = doc["channelid"].GetInt();
+                }
+
+                if(end == doc.FindMember("trackingStatus") || !doc["trackingStatus"].IsInt()) {
+                    return false;
+                }else{
+                    trackingStatus = doc["trackingStatus"].GetInt();
+                }
+
+                if(end == doc.FindMember("size") || !doc["size"].IsArray()) {
+                    return false;
+                }else{
+                    const auto temp = doc["size"].GetArray();
+                    if(temp.Size() < 2)
+                        return false;
+                    size.width = temp[0].GetInt();
+                    size.height = temp[1].GetInt();;
+                }
+
+                if(end == doc.FindMember("rect") || !doc["rect"].IsArray()) {
+                    return false;
+                }else{
+                    const auto temp = doc["rect"].GetArray();
+                    if(temp.Size() < 4)
+                        return false;
+                    rect.x = temp[0].GetInt();
+                    rect.y = temp[1].GetInt();
+                    rect.width = temp[2].GetInt();
+                    rect.height = temp[3].GetInt();;
+                }
+
+                if(end == doc.FindMember("response") || !doc["response"].IsDouble()) {
+                    return false;
+                }else{
+                    response = doc["response"].GetDouble();
+                }
+            }
+
+            return true;
+        }
+};

+ 51 - 0
framework/request/include/HepuTarget2Re.h

@@ -0,0 +1,51 @@
+#pragma once
+
+#include <iostream>
+
+#include <rapidjson/document.h>
+#include <rapidjson/rapidjson.h>
+#include <rapidjson/stringbuffer.h>
+#include <rapidjson/writer.h>
+using namespace std;
+
+class HepuTarget2Re
+{
+    private:
+    public:
+        const string cmd = "ivpClientTracking";
+        int ackvalue;
+        int channelid;
+        bool bTracking;
+        
+        HepuTarget2Re(){};
+        ~HepuTarget2Re(){};
+
+        bool jsonToObject(string& json){
+            rapidjson::Document doc;
+            doc.Parse(json.c_str());
+            if(!doc.IsObject()){
+                return false;
+            }
+
+            const auto end = doc.MemberEnd();
+
+            if(end == doc.FindMember("cmd") || !doc["cmd"].IsString()){
+                return false;
+            }else{
+                if(cmd != doc["cmd"].GetString())
+                    return false;
+            }
+
+            if(end == doc.FindMember("param") || !doc["param"].IsObject()) {
+                return false;
+            }else{
+                const rapidjson::Value& object = doc["param"];
+                if(end == object.FindMember("ackvalue") || !object["ackvalue"].IsInt()) {
+                    return false;
+                }else{
+                    ackvalue = object["ackvalue"].GetInt();
+                }
+            }
+            return true;
+        }
+};

+ 1 - 0
framework/request/include/requests.hpp

@@ -24,6 +24,7 @@
 #include "HepuHB.h"
 #include "HepuLogin.h"
 #include "HepuTarget.h"
+#include "HepuTarget2.h"
 
 #include "SendBird.h"
 #include "SendDevice.h"

+ 4 - 0
modules/Hepu/include/Hepu.hpp

@@ -27,6 +27,8 @@
 #include "HepuTargetRe.h"
 #include "HepuGetSalt.h"
 #include "HepuGetSaltRe.h"
+#include "HepuTarget2.h"
+#include "HepuTarget2Re.h"
 
 using namespace std;
 using namespace toolkit;
@@ -76,6 +78,8 @@ namespace gsd{
 
             int32_t sendHepuTarget(HepuTarget& hepuTargetMsg);
 
+            int32_t sendHepuTarget2(HepuTarget2& hepuTargetMsg);
+
             void setUsr(string usr);
 
             void setPwd(string pwd);

+ 39 - 1
modules/Hepu/src/Hepu.cpp

@@ -234,7 +234,7 @@ namespace gsd{
 
         std::string msg;
         HepuTargetMsg.token = this->token_;
-        HepuTargetMsg.channelid = 1;
+        HepuTargetMsg.channelid = 0; //1 for infrared 0 for visible light
         HepuTargetMsg.bTracking = true;
         HepuTargetMsg.trackingTime = 0;
         HepuTargetMsg.objectToJson(msg);
@@ -267,6 +267,44 @@ namespace gsd{
         return ERR;
     }
 
+    int32_t Hepu::sendHepuTarget2(HepuTarget2& HepuTargetMsg){
+        if(m_hepu == nullptr) return ERR;
+
+        std::string msg;
+        HepuTargetMsg.token = this->token_;
+        HepuTargetMsg.channelid = 0; //1 for infrared 0 for visible light
+        HepuTargetMsg.trackingStatus = 1;
+        HepuTargetMsg.response = 0;
+        HepuTargetMsg.objectToJson(msg);
+        msg+="\r\n";
+        
+        cout<<"Target json msg: "<<endl;
+        cout<<msg<<endl;
+
+        if(auto res = m_hepu->Post("/cgi-bin/proc.cgi", msg,"application/json")){
+            cout<<res->body<<endl;
+            if(res->status != 100){
+                HepuTarget2Re hepuTargetReMsg;
+                if(!hepuTargetReMsg.jsonToObject(res->body)){
+                    cout<<"target res json2object fail."<<endl;
+                    return ERR;
+                }
+                if(hepuTargetReMsg.ackvalue != 100){
+                    cout<<"hb res ack err: "<<hepuTargetReMsg.ackvalue<<endl;
+                    return ERR;
+                }
+                return OK;
+            }
+            return ERR;
+        }else{
+            auto err = res.error();
+            cout<<"Hepu send target failed,"<<err<<endl;
+            ErrorL << "Hepu send target failed,"<<err<<endl;
+            return ERR;
+        }
+        return ERR;
+    }
+
     void Hepu::setUsr(string username)
     {
         this->username_ = username;

+ 1 - 0
modules/config/include/config.hpp

@@ -102,6 +102,7 @@ public:
     std::string HepuURL = "/cgi-bin/proc.cgi";
     std::string HepuUsr = "sunwin";
     std::string HepuPwd = "123456";
+    int HepuProtocol = 31;
 
 protected:
     #ifdef RELEASE

+ 2 - 0
modules/config/src/config.cpp

@@ -56,6 +56,7 @@ bool config::Update(){
     this->sensitivity = m_ini.getIntValue("Filter", "sensitivity", ret);
     this->interval = m_ini.getIntValue("Filter", "interval", ret);
     this->TimeOut = m_ini.getIntValue("Filter", "TimeOut", ret);
+    this->filterLevel = m_ini.getIntValue("Filter","filterLevel",ret);
 
     this->Spug_IP = m_ini.getStringValue("Spug", "Spug_IP", ret);
     this->Spug_Port = m_ini.getIntValue("Spug", "Spug_Port", ret);
@@ -72,6 +73,7 @@ bool config::Update(){
     this->HepuURL = m_ini.getStringValue("Hepu","hepu_url",ret);
     this->HepuUsr = m_ini.getStringValue("Hepu","hepu_usr",ret);
     this->HepuPwd = m_ini.getStringValue("Hepu","hepu_pwd",ret);
+    this->HepuProtocol = m_ini.getIntValue("Hepu","hepu_protocol",ret);
 
     this->SimCode = this->getSimCode();
     this->app = this->getApp();

+ 2 - 0
plugins/HepuPlugin/include/HepuPlugin.hpp

@@ -44,6 +44,8 @@ namespace gsd
 
             void SendTarget(HepuTarget& HepuTargetMsg);
 
+            void SendTarget2(HepuTarget2& HepuTargetMsg);
+
             bool Alive();
 
             virtual bool RestPlugin();

+ 7 - 0
plugins/HepuPlugin/src/HepuPlugin.cpp

@@ -68,6 +68,13 @@ namespace gsd
         return;
     }
 
+    void HepuPlugin::SendTarget2(HepuTarget2& HepuTargetMsg){
+        InfoL<<"Send target command."<<endl;
+        if(this->m_hepuClient == nullptr) return;
+        this->m_hepuClient->sendHepuTarget2(HepuTargetMsg);
+        return;
+    }
+
     void HepuPlugin::Destroy(){
         InfoL<<"Hepu IPC httpclient plugin destroyed"<<endl;
         stop_ = true;

+ 16 - 2
plugins/MonitorPlugin/include/MonitorPlugin.hpp

@@ -63,11 +63,25 @@ namespace gsd
         void MonitorProThrd();
 
         /**
-         * @description: 消费数据
+         * @description: 消费数据 
          * @param {Ptr&} result
          * @return {*}
          */    
-        bool ConsumeData(FrameInferData::Ptr& result, HepuTarget::Ptr& target);
+        bool ConsumeData(FrameInferData::Ptr& result);
+
+        /**
+         * @description: 消费数据 Hepu 4.7.17
+         * @param {Ptr&} result
+         * @return {*}
+         */    
+        bool ConsumeData1(FrameInferData::Ptr& result, HepuTarget::Ptr& target);
+
+        /**
+         * @description: 消费数据 Hepu 4.7.31
+         * @param {Ptr&} result
+         * @return {*}
+         */    
+        bool ConsumeData2(FrameInferData::Ptr& result, HepuTarget2::Ptr& target);
 
         /**
         * @description: 保存视频记录

+ 176 - 13
plugins/MonitorPlugin/src/MonitorPlugin.cpp

@@ -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;
             }
 
             // 获取时间