From f676f7af18163b4532b6b982bbe1dc57b32e96dd Mon Sep 17 00:00:00 2001
From: zhangjixing <775834166@qq.com>
Date: 星期四, 24 一月 2019 15:38:22 +0800
Subject: [PATCH] 

---
 QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.cpp |  137 +++++++++++++++++++++++++++++----------------
 1 files changed, 89 insertions(+), 48 deletions(-)

diff --git a/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.cpp b/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.cpp
index d04013c..d0f6d34 100644
--- a/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.cpp
+++ b/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.cpp
@@ -10,10 +10,12 @@
 #include <basic/util/app/AppPreference.hpp>
 
 JudgmentRetrogradeTool::JudgmentRetrogradeTool(const SdkRule &rule) :
-    TimerElement(1000),
-    m_triggerElement(0, rule.nTriggerDelay * 1000 * 1000),
+    m_triggerElement(0, 0),
     m_sdkRule(rule),
-    pManagerEsDB(nullptr) {
+    pManagerEsDB(nullptr),
+    pointArray(nullptr),
+    npts(0)
+{
     pManagerEsDB = new EsDBTool(appPref.getStringData("ipAdd"), appPref.getIntData("ipPort"));
 }
 
@@ -22,6 +24,12 @@
         delete pManagerEsDB;
         pManagerEsDB = nullptr;
     }
+    if(pointArray)
+    {
+        delete pointArray;
+        pointArray=nullptr;
+    }
+
 }
 
 bool JudgmentRetrogradeTool::init(QString area, QString line) {
@@ -29,14 +37,17 @@
     //#todo string ->json
     QJsonArray arrayAreas = getJsonArrayFromQString(area);
     if (arrayAreas.isEmpty()) {
-        return false;//do not detect
+        return false;
     }
+    int size=arrayAreas.size();
     QVector<QPoint> vec;
-    for (int i = 0; i < arrayAreas.size(); ++i) {
+    pointArray=new cv::Point2i[size];
+    for (int i = 0; i < size; ++i) {
         QJsonValue jsonValue = arrayAreas[i];
         QJsonObject obj = jsonValue.toObject();
         int x = obj.value("x").toDouble() * 4;
         int y = obj.value("y").toDouble() * 4;
+        pointArray[i]={x,y};
         vec.push_back(QPoint(x, y));
     }
 
@@ -79,14 +90,9 @@
 }
 
 void JudgmentRetrogradeTool::setYoloObjects(std::vector<ScoredRect> value) {
-    if (!isInWeek(m_sdkRule.weekRuleVec))
-        return;
-    mObjs = value;
-    for (auto &item :value) {
-        if (item.score < m_sdkRule.fSensitivity)continue;
 
-        setPerRect(item.id, item.rect);
-    }
+    mObjs = value;
+
 }
 
 
@@ -118,7 +124,7 @@
 }
 
 bool JudgmentRetrogradeTool::getPerRet(const long &id) {
-    bool ret = (m_mapPerRet.find(id) == m_mapPerRet.end()) ? true : m_mapPerRet[id];
+    bool ret = (m_mapPerRet.find(id) == m_mapPerRet.end()) ? false :m_mapPerRet[id]>=m_sdkRule.nTriggerDelay * 8;
     return ret;
 }
 
@@ -137,12 +143,58 @@
     return JRTOOL::getAngelOfTwoVector(directionVectorPoint, point);
 }
 
-void JudgmentRetrogradeTool::timerFunc() {
+void JudgmentRetrogradeTool::threadFunc() {
     func();
     fireConnectors();
 }
 
 void JudgmentRetrogradeTool::func() {
+    if (!isInWeek(m_sdkRule.weekRuleVec))
+        return;
+    bool state=false;
+    for (auto &scoredRect :mObjs) {
+        if (scoredRect.score < m_sdkRule.fSensitivity)continue;
+
+        if (getPerRet(scoredRect.id))//judgment.bool
+        {
+
+            DBG("scoredRect.id" << scoredRect.id << " val=" << m_mapPerRet[scoredRect.id]);
+            m_mapPerRet[scoredRect.id] -=2400;
+//            auto t_image = image(
+//                CvUtil::zoomRectEqual(scoredRect.rect, 1.2, 1.2) & cv::Rect(0, 0, image.cols, image.rows)).clone();
+            //  auto t_image = image(scoredRect.rect& cv::Rect(0, 0, image.cols, image.rows)).clone();
+
+            if(pointArray==nullptr)  return;
+            const cv::Point2i* ppt[1] = { pointArray };
+
+            int npt[]={npts};
+            cv::polylines(image, ppt,npt, 1, true,cv::Scalar(255,255,0));
+            cv::arrowedLine(image,m_UpBaseLine.start_Point,m_UpBaseLine.end_Point,cv::Scalar(0,0,255));
+
+            cv::rectangle(image, scoredRect.rect,  cv::Scalar(0, 0, 255), 2);
+
+            std::string imgUrl = uploadImgToFdfs(image);
+            saveInfoToEs(imgUrl, scoredRect);
+            state=true;
+
+
+           // break;
+        }
+//          m_triggerElement.triggerOnce();
+//          if(m_triggerElement.getState())
+//          {
+
+//              auto t_image = image(
+//                  CvUtil::zoomRectEqual(scoredRect.rect, 1.2, 1.2) & cv::Rect(0, 0, image.cols, image.rows)).clone();
+//              //  auto t_image = image(scoredRect.rect& cv::Rect(0, 0, image.cols, image.rows)).clone();
+//              std::string imgUrl = uploadImgToFdfs(t_image);
+//              saveInfoToEs(imgUrl, scoredRect);
+//          }
+
+        setPerRect(scoredRect.id, scoredRect.rect);
+    }
+    m_triggerElement.setState(state);
+    m_triggerElement.triggerOnce();
     for (auto &item : m_mapPerDirection) {
         int a = 0;
         int b = 0;
@@ -154,13 +206,18 @@
                 a++;
             }
         }
-        // DBG("id="<<item.first<<" a="<<a<<"  b="<<b);
-        bool ret = a >= b ? true : false;
-        if (!ret) {
-            m_mapPerRet.insert(std::make_pair(item.first, false));
-            // m_mapPerRet[item.first] = false;
+        if(b!=0)
+        {
+            bool ret = a >= b ? true : false;
+           //  DBG("id="<<item.first<<" a="<<a<<"  b="<<b<<" ret="<<ret);
+            if (!ret) {
+                m_mapPerRet[item.first]+=1;
+               // m_mapPerRet.insert(std::make_pair(item.first, false));
+                // m_mapPerRet[item.first] = false;
 
+            }
         }
+
 
 
         if (temp.size() > 9) {
@@ -168,25 +225,8 @@
         }
     }
 
-    for (auto scoredRect:mObjs) {
-        if (!getPerRet(scoredRect.id))//judgment.bool
-        {
-            DBG("scoredRect.id" << scoredRect.id << " val=" << m_mapPerRet[scoredRect.id]);
-            m_mapPerRet[scoredRect.id] = true;
 
-            m_triggerElement.setState(true);
-            auto t_image = image(
-                CvUtil::zoomRectEqual(scoredRect.rect, 1.2, 1.2) & cv::Rect(0, 0, image.cols, image.rows)).clone();
-            //  auto t_image = image(scoredRect.rect& cv::Rect(0, 0, image.cols, image.rows)).clone();
-            std::string imgUrl = uploadImgToFdfs(t_image);
-            saveInfoToEs(imgUrl, scoredRect);
-            break;
-        } else {
-            m_triggerElement.setState(false);
 
-        }
-    }
-    m_triggerElement.triggerOnce();
 }
 
 std::string JudgmentRetrogradeTool::uploadImgToFdfs(cv::Mat &image) {
@@ -197,7 +237,7 @@
         CvUtil::cvMat2Buffer(image, buffer);
         std::string strImgUrlTmp = "";
         fdfsClient->fastFds->uploadFile(buffer, strImgUrlTmp, "jpg");
-        strImgUrl.append(fdfsClient->fastFds->getIp() + "/" + strImgUrlTmp);
+      //  strImgUrl.append(fdfsClient->fastFds->getIp() + "/" + strImgUrlTmp);
         strImgUrl.clear();
         strImgUrl = strImgUrlTmp;
 //                    strImgUrl.append("/").append(strImgUrlTmp);
@@ -225,35 +265,36 @@
     t_json["sdkType"] = to_string(m_sdkRule.nSdkType);
 //        t_json["Gender"] = obj.score;
 
-    t_json["picName"] = "wait todo";// 鎶撴媿鐓х墖鍚嶇О
-    t_json["content"] = "wait todo";// 鍐呭鎻忚堪
+    t_json["picName"] = "";// 鎶撴媿鐓х墖鍚嶇О
+    t_json["content"] = "";// 鍐呭鎻忚堪
     t_json["personPicUrl"] = "";// 浜哄憳 鍦板簱鍥剧墖
     t_json["ChannlId"] = getProperty("ch_id"); // 閫氶亾id
     t_json["likeDate"] = AppUtil::getTimeSecString(); // 姣斿鏃堕棿
-    t_json["picAddress"] = getProperty("str_addr");// 鎶撴媿鍦板潃
-    t_json["picMaxUrl"] = "wait todo"; // 澶у浘璺緞
+    t_json["picAddress"] = m_sdkRule.strAddr.toStdString();// 鎶撴媿鍦板潃
+    DBG("picAddress="<<m_sdkRule.strAddr.toStdString());
+    t_json["picMaxUrl"] = ""; // 澶у浘璺緞
 
 
-    //   t_json["Age"] ="wait todo";
+    //   t_json["Age"] ="";
     t_json["picDate"] = obj.properties["time"]; // 鎶撴媿鏃堕棿锛屽繀椤绘湁
-    t_json["picLocalUrl"] = "wait todo";  // 鏈湴璺緞
+    t_json["picLocalUrl"] = "";  // 鏈湴璺緞
     t_json["isDelete"] = "1";//榛樿1 ,0鏃犳晥 1鏈夋晥
 
-    t_json["likePer"] = obj.score; // 鐩镐技鍊�
+    t_json["likePer"] = 1.0; // 鐩镐技鍊�
 
-    t_json["BaseName"] = "wait todo";// 鍦板簱鍚嶇О
+    t_json["BaseName"] = "";// 鍦板簱鍚嶇О
 
     t_json["videoNum"] = m_sdkRule.strCamId.toStdString();//Video璁惧缂栧彿
     t_json["picSmUrl"] = imgUrl; // 鎶撴媿鍥剧墖
     t_json["indeviceid"] = appPref.getStringData("fxDevID");;// 璁惧id
-    t_json["idcard"] = "wait todo";
-    t_json["personId"] = "wait todo";
+    t_json["idcard"] = "";
+    t_json["personId"] = "";
     t_json["indevicename"] = appPref.getStringData("fxDevNAME");// 璁惧鍚嶇О
     t_json["FaceFeature"] = "base64";
     t_json["personIsHub"] = m_triggerElement.getTriggerState() ? "1" : "4"; //1: 鎶ヨ  2: 鍙枒  3: 瀹夊叏  4: 鏈煡
     t_json["videoIp"] = getProperty("local_ip");//褰撳墠鏈嶅姟鍣↖P鍦板潃
     t_json["ack_alarm"] = m_triggerElement.getTriggerState() ? "0" : "";  //  que ren shi fou bao jing
-    t_json["cluster_id"] = "wait todo"; // ji qun id
+    t_json["cluster_id"] = appPref.getStringData("clusterID");; // ji qun id
 
     bool retface = false;
     if (pManagerEsDB)

--
Gitblit v1.8.0