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

---
 QiaoJiaSystem/EncodeServer/EncodeVideoManager.cpp     |   24 +++
 QiaoJiaSystem/StructureApp/HiredisTool.cpp            |   12 +
 QiaoJiaSystem/VideoServer/QiaoJia/DB/DBStruct.h       |    2 
 QiaoJiaSystem/StructureApp/PerimeterElement.cpp       |   63 ++++++--
 QiaoJiaSystem/VideoServer/QiaoJia/DB/LDBTool.h        |    1 
 QiaoJiaSystem/StructureApp/NewRecordVideoElement.h    |    3 
 QiaoJiaSystem/EncodeServer/EncodeVideo.cpp            |    5 
 QiaoJiaSystem/StructureApp/TrackingTrigger.h          |    3 
 QiaoJiaSystem/StructureApp/PerStaticElement.cpp       |  130 +++++++++++-------
 QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.h   |    7 
 QiaoJiaSystem/StructureApp/AppPipeController.cpp      |   13 +
 QiaoJiaSystem/StructureApp/NewRecordVideoElement.cpp  |   24 ++
 QiaoJiaSystem/YoloServer/main.cpp                     |    2 
 QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.cpp |   50 +++++--
 QiaoJiaSystem/DataManagerServer/http_configserver.cpp |    6 
 QiaoJiaSystem/StructureApp/PerimeterElement.h         |    5 
 QiaoJiaSystem/VideoServer/QiaoJia/DB/LDBTool.cpp      |   32 ++++
 QiaoJiaSystem/StructureApp/PerStaticElement.h         |    2 
 QiaoJiaSystem/StructureApp/PersonElement.cpp          |    3 
 QiaoJiaSystem/StructureApp/FaceExtractElement.cpp     |   17 +-
 20 files changed, 283 insertions(+), 121 deletions(-)

diff --git a/QiaoJiaSystem/DataManagerServer/http_configserver.cpp b/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
index bc54682..6bdf1ac 100644
--- a/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
+++ b/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
@@ -3069,7 +3069,8 @@
         str_imgName +="-";
         str_imgName += "snapshot.jpg";
         //admin:a1234567@192.168.1.201:554/h264/ch1/main/av_stream -r 1/25 -f image2 -s 1920*1080 /home/basic/work_src/a.jpg
-        std::string cmd("ffmpeg -i " + rtsp_url + " -r 1/25  -f image2 -s 1920*1080 -y " + str_imgName);
+        std::string cmd("ffmpeg -i " + rtsp_url + " -vf select='eq(pict_type\\,I)',setpts='N/(25*TB)' -f image2 -s 1920*1080 -y " + str_imgName);
+//        std::string cmd("ffmpeg -i " + rtsp_url + " -r 1/25  -f image2 -s 1920*1080 -y " + str_imgName);
         DBG(cmd);
         system(cmd.c_str());
 
@@ -3086,13 +3087,14 @@
             CvUtil::cvMat2Buffer(img, 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;
         }
         fdfsClient.rwLock.unlock();
         Json::Value result;
         result["imgUrl"] = strImgUrl;
+        db_c.updateCamDevSnapshot(QString::fromStdString(ip),QString::fromStdString(strImgUrl));
 
         return result.toStyledString();
 
diff --git a/QiaoJiaSystem/EncodeServer/EncodeVideo.cpp b/QiaoJiaSystem/EncodeServer/EncodeVideo.cpp
index b9ce644..9341a44 100644
--- a/QiaoJiaSystem/EncodeServer/EncodeVideo.cpp
+++ b/QiaoJiaSystem/EncodeServer/EncodeVideo.cpp
@@ -12,7 +12,8 @@
 
 void EncodeVideo::threadFunc()
 {
-
+//    std::string tmp="threadFunc";
+//    ClockTimer cl(tmp);
 
     std::string src_path=getProperty("src_path");
     if(src_path.empty())
@@ -45,7 +46,7 @@
 
             videoEncoderElement.doFunc(img);
         }
-         usleep(2*1000);
+       //  usleep(1000);
     }
 
     videoEncoderElement.threadClosing();
diff --git a/QiaoJiaSystem/EncodeServer/EncodeVideoManager.cpp b/QiaoJiaSystem/EncodeServer/EncodeVideoManager.cpp
index fd67754..27523af 100644
--- a/QiaoJiaSystem/EncodeServer/EncodeVideoManager.cpp
+++ b/QiaoJiaSystem/EncodeServer/EncodeVideoManager.cpp
@@ -1,8 +1,10 @@
 #include "EncodeVideoManager.h"
 #include "NewRecordVideoElement.h"
 #include <basic/util/app/AppConfig.h>
+#include <qdatetime.h>
+
 EncodeVideoManager::EncodeVideoManager():
-TimerElement(1000)
+TimerElement(10*1000)
 {
    // m_hiredisTool.delKey("")
     int thread_num=appConfig.getIntProperty("encode_thread_num");
@@ -28,12 +30,16 @@
         {
             m_newEncodeVideoVec[i]->stop();
             delete m_newEncodeVideoVec[i];
+            m_newEncodeVideoVec[i]=nullptr;
         }
     }
+    m_newEncodeVideoVec.clear();
 
 }
 void EncodeVideoManager::timerFunc()
 {
+        //    std::string tmp="camId="+m_camId+"videoCaptureElement";
+            ClockTimer cl("timerFunc");
    std::map<std::string,int> fileMap=m_hiredisTool.findAllFileStatus();
 //   auto it=fileMap.begin();
    for(auto it=fileMap.begin();it!=fileMap.end();it++)
@@ -54,5 +60,21 @@
 
 
        }
+       else
+       {
+           //----/home/basic/work/qiaojia/cut/DS-2CD2T46WDA2-I20180622AACHC30488278/201901/22/2019012210/2019-01-22 10:32:38:171.mp4
+
+           std::string file_name=it->first;
+           int begin=file_name.find_last_of("/")+1;
+           int end= file_name.find(".mp4");
+           std::string file_time=file_name.substr(begin,end-begin);
+           QDateTime dt = QDateTime::fromString(QString::fromStdString(file_time), "yyyy-MM-dd hh:mm:ss:zzz");
+           if( (AppUtil::getCurrentUs()-dt.toMSecsSinceEpoch())>5*60*1000*1000)
+           {
+               DBG(file_name<<">5*60*1000*1000");
+               m_hiredisTool.hashSet(file_list,file_name,RECORD_ENDING);
+           }
+
+       }
    }
 }
diff --git a/QiaoJiaSystem/StructureApp/AppPipeController.cpp b/QiaoJiaSystem/StructureApp/AppPipeController.cpp
index 8bf95e3..c8e3733 100644
--- a/QiaoJiaSystem/StructureApp/AppPipeController.cpp
+++ b/QiaoJiaSystem/StructureApp/AppPipeController.cpp
@@ -192,14 +192,18 @@
     //  int max=appPref.getIntData("n_cut_max_duration");
     // recordInit(40,100);
     videoCaptureElement.registerConnector([&] {
-        mutex.lock();
-        cv::Mat imageTemp = videoCaptureElement.getImage();
+//        mutex.lock();
 
+
+//        std::string tmp="camId="+m_camId+"videoCaptureElement";
+//        ClockTimer cl(tmp);
+        cv::Mat imageTemp = videoCaptureElement.getImage();
         std::string  strNewTime = AppUtil::getTimeUSecString();;
 
         //DBG("m_camId="<<m_camId<<"  strNewTime="<<strNewTime);
         cv::putText(imageTemp, strNewTime, cv::Point(408, 540), cv::HersheyFonts::FONT_HERSHEY_PLAIN, 5,
                     cv::Scalar(255, 255, 0), 2);
+
         if (m_camId.size() > 0) {
 
 
@@ -229,9 +233,10 @@
             strNewTime = newDt.toString("yyyy-MM-dd hh:mm:ss").toStdString();
 
         }
-         mutex.unlock();
+//  mutex.unlock();
 //        DBG(strNewTime);
-
+//        std::string tmp1="camId="+m_camId+"strNewTime"+strNewTime;
+//        ClockTimer cl1(tmp1);
         if (!faceRpcElement.isBusy()) {
 //            faceRpcElement.setProperty("uuid", uuid);
             //#todo
diff --git a/QiaoJiaSystem/StructureApp/FaceExtractElement.cpp b/QiaoJiaSystem/StructureApp/FaceExtractElement.cpp
index f81e18b..4fed07d 100644
--- a/QiaoJiaSystem/StructureApp/FaceExtractElement.cpp
+++ b/QiaoJiaSystem/StructureApp/FaceExtractElement.cpp
@@ -134,20 +134,20 @@
 
                 //#鍦ㄥ姣斾腑娣诲姞鐗瑰緛鍊�
                 t_json["FaceFeature"] = "base64";
-                t_json["personId"] = "wait todo";//鍏宠仈搴曞簱浜哄憳id,浜鸿劯id
-                t_json["BaseName"] = "wait todo";//鍏宠仈搴曞簱琛ㄥ悕
+                t_json["personId"] = "";//鍏宠仈搴曞簱浜哄憳id,浜鸿劯id
+                t_json["BaseName"] = "";//鍏宠仈搴曞簱琛ㄥ悕
                 //#end
 //                t_json["likePer"] = faceExtractQueueTmp[i].scoredRects[j].score;//浜哄憳鐩镐技搴� Score
                 t_json["likeDate"] = AppUtil::getTimeSecString();//"2018-01-01 01:01:01";//姣旇緝鏃堕棿
 
-                t_json["picName"] = "wait todo";
+                t_json["picName"] = "";
 
 
-                t_json["personPicUrl"] = "wait todo";//浜哄憳鍥剧墖 store
+                t_json["personPicUrl"] = "";//浜哄憳鍥剧墖 store
                 t_json["picAddress"] = getProperty("str_addr");//鎶撴媿鍦板潃
                   DBG("picAddress="<< t_json["picAddress"] );
-                t_json["picMaxUrl"] = "wait todo";//澶у浘璺緞
-                t_json["picLocalUrl"] = "wait todo";//鏈湴璺緞
+                t_json["picMaxUrl"] = "";//澶у浘璺緞
+                t_json["picLocalUrl"] = "";//鏈湴璺緞
                 t_json["picSmUrl"] = strImgUrl;//浜哄憳鎶撳皬鍥�
                 //#todo
                 t_json["picDate"] = faceExtractQueueTmp[i].scoredRects[j].properties["time"];
@@ -155,8 +155,9 @@
 //                DBG("timeC ::::B" << t_json["picDate"m_bIsMask].asString());
 //                t_json["picDate"] = AppUtil::getTimeSecString();
 
-                t_json["content"] = "wait todo";
-                t_json["viType"] = "1";//鍙湁4绉嶇被鍨� 1:personface 2:personbody 3:car 4:bicycle 5:none 鏈煡绫诲瀷
+                t_json["content"] = "";
+                //t_json["viType"] = "2";//鍙湁4绉嶇被鍨� 1:personface 2:personbody 3:car 4:bicycle 5:none 鏈煡绫诲瀷
+                t_json["sdkType"] = std::to_string(m_sdkRule.nSdkType);//鍙湁4绉嶇被鍨� 1:personface 2:personbody 3:car 4:bicycle 5:none 鏈煡绫诲瀷
                 t_json["personIsHub"] = "4";//1: 鎶ヨ  2: 鍙枒  3: 瀹夊叏  4: 鏈煡
 
 
diff --git a/QiaoJiaSystem/StructureApp/HiredisTool.cpp b/QiaoJiaSystem/StructureApp/HiredisTool.cpp
index a54a9bd..6a8715b 100644
--- a/QiaoJiaSystem/StructureApp/HiredisTool.cpp
+++ b/QiaoJiaSystem/StructureApp/HiredisTool.cpp
@@ -89,15 +89,19 @@
       CvUtil::cvMat2Buffer(img,buf);
 //      json["time"]=info.time;
       json["img"]=std::string(buf.begin(),buf.end());
-  //    buf.clear();
-      std::string strBuf=std::string(buf.begin(),buf.end());
-      if(!listLpush(file_name,json.toStyledString()));
+      if(!checkParam())
       {
+          return false;
+      }
+      redisReply *reply;
 
+      reply = (redisReply*)redisCommand(m_redis,"lpush %s %s", file_name.c_str(),json.toStyledString().c_str());
+      if(!checkResult(reply))
+      {
           return false;
       }
 
-      //DBG(json.toStyledString());
+      freeReplyObject(reply);
 
       return true;
 }
diff --git a/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.cpp b/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.cpp
index bcf0518..d0f6d34 100644
--- a/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.cpp
+++ b/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.cpp
@@ -12,7 +12,9 @@
 JudgmentRetrogradeTool::JudgmentRetrogradeTool(const SdkRule &rule) :
     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) {
@@ -31,12 +39,15 @@
     if (arrayAreas.isEmpty()) {
         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));
     }
 
@@ -146,12 +157,23 @@
 
         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(
+//                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);
+
+            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;
 
@@ -243,30 +265,30 @@
     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"] = m_sdkRule.strAddr.toStdString();// 鎶撴媿鍦板潃
     DBG("picAddress="<<m_sdkRule.strAddr.toStdString());
-    t_json["picMaxUrl"] = "wait todo"; // 澶у浘璺緞
+    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: 鏈煡
diff --git a/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.h b/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.h
index e3cd93f..d69df24 100644
--- a/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.h
+++ b/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.h
@@ -22,8 +22,8 @@
 #include <jsoncpp/json/json.h>
 #include <basic/pipe/PipeElement.h>
 struct VectorPoint {
-    cv::Point2f start_Point;
-    cv::Point2f end_Point;
+    cv::Point2i start_Point;
+    cv::Point2i end_Point;
 };
 
 typedef VectorPoint BaseLine;
@@ -138,6 +138,9 @@
 
     cv::Mat image;
     EsDBTool *pManagerEsDB;
+    cv::Point2i* pointArray;
+
+    int npts;
 };
 
 
diff --git a/QiaoJiaSystem/StructureApp/NewRecordVideoElement.cpp b/QiaoJiaSystem/StructureApp/NewRecordVideoElement.cpp
index 6897343..3b8498f 100644
--- a/QiaoJiaSystem/StructureApp/NewRecordVideoElement.cpp
+++ b/QiaoJiaSystem/StructureApp/NewRecordVideoElement.cpp
@@ -5,11 +5,12 @@
 //#todo index int -> string
 NewRecordVideoElement::NewRecordVideoElement(std::string camid) :
 //videoEncoderElement(cv::Size(1920, 1080), 5, 0),
-camID(camid)
+camID(camid),
+m_bSaveWH(false)
 {
 
    // basicPath();
-    isRecord=false;
+    //isRecord=false;
     m_cutPath= appPref.getStringData("user.loop.absolute.path");
 
      recordInit(appPref.getIntData("n_cut_min_duration"),appPref.getIntData("n_cut_max_duration"));
@@ -19,18 +20,23 @@
     std::queue<ImgInfo> empty;
     empty.swap(m_imgBufQue);
 
-//m_imgBufQue.clear();
+
 }
 
 std::string NewRecordVideoElement::startRecord() {
 
-//    ImgInfo info=m_HiredisTool.getImage(camID);
-     //isRecord=true;
+
+
      ImgInfo info;
      getImg(info);
     std::string srcPath= getFileName(info.time);
     m_filename=srcPath;
    // DBG("m_filename: " << m_filename);
+    if(!m_bSaveWH)
+    {
+       m_bSaveWH=m_hiredisTool.hashSet(camID,"width",info.img.cols) && m_hiredisTool.hashSet(camID,"height",info.img.rows);
+       DBG("m_bSaveWH="<<m_bSaveWH);
+    }
 
     m_hiredisTool.pushImageBuf(m_filename,info.img);
      m_hiredisTool.addFileInfo(m_filename,RECORD_DOING);
@@ -47,7 +53,7 @@
 //    DBG("sdkTrigger:" << sdkTrigger);
     m_hiredisTool.pushImageBuf(m_filename,info.img);
     m_hiredisTool.addFileInfo(m_filename,RECORD_ENDING);
-   // isRecord=false;
+
 }
 
 void NewRecordVideoElement::doRecord() {
@@ -97,6 +103,8 @@
 }
 void NewRecordVideoElement::pushImgBuf(const std::string& time,cv::Mat& img)
 {
+//    std::string tmp="camId="+camID+"pushImgBuf";
+//    ClockTimer cl(tmp);
      ImgInfo info;
      img.copyTo(info.img);
 //     info.img=img;
@@ -109,6 +117,8 @@
 }
  void NewRecordVideoElement::getImg(ImgInfo& info)
  {
+//     std::string tmp="camId="+camID+"getImg";
+//     ClockTimer cl(tmp);
         info=m_imgBufQue.front();
         int size=m_imgBufQue.size();
 //        DBG("m_imgBufQue size="<<size<<" camId="<<camID<<" fileMin="<<fileMin/2);
@@ -200,6 +210,8 @@
      }
  }
  void NewRecordVideoElement::setSdkTrigger(bool isTrigger) {
+//     std::string tmp="camId="+camID+"setSdkTrigger";
+//     ClockTimer cl(tmp);
      if(isTrigger)
      {
 //         DBG("setSdkTrigger time=" << AppUtil::getTimeUSecString());
diff --git a/QiaoJiaSystem/StructureApp/NewRecordVideoElement.h b/QiaoJiaSystem/StructureApp/NewRecordVideoElement.h
index dc35006..2b578f5 100644
--- a/QiaoJiaSystem/StructureApp/NewRecordVideoElement.h
+++ b/QiaoJiaSystem/StructureApp/NewRecordVideoElement.h
@@ -35,7 +35,6 @@
 #define RECORD_STOP (0)
 #define RECORD_DOING (1)
 #define RECORD_ENDING (2)
-
     int recordStatus;
     int videoLength;
     int recordDelay;
@@ -53,7 +52,7 @@
     std::queue<ImgInfo> m_imgBufQue;
     HiredisTool m_hiredisTool;
     std::string m_filename;
-    bool isRecord;
+    bool m_bSaveWH;
 };
 
 #endif // RECORDVIDEOELEMENT_H
diff --git a/QiaoJiaSystem/StructureApp/PerStaticElement.cpp b/QiaoJiaSystem/StructureApp/PerStaticElement.cpp
index a8156c3..667bb9a 100644
--- a/QiaoJiaSystem/StructureApp/PerStaticElement.cpp
+++ b/QiaoJiaSystem/StructureApp/PerStaticElement.cpp
@@ -46,9 +46,9 @@
     if(!isInWeek(m_sdkRule.weekRuleVec))
         return;
     int num=0;
-
-
-    for(auto obj:mObjs)
+    bool state=false;
+    time_t now= AppUtil::getCurrentUs();
+    for(auto& obj:mObjs)
     {
 
             if(obj.score < m_sdkRule.fSensitivity)continue;
@@ -57,11 +57,31 @@
             QPoint center = rect.center();
             if(mPolygon.containsPoint(center,Qt::OddEvenFill) || !m_bIsMask)
             {
-                for(auto score:m_lastScoreRect)
+                for(auto ele:m_lastScoreRect)
                 {
-                    if(obj.id == score.id)
+                    if(obj.id == ele.id && (obj.rect&ele.rect).area()>ele.rect.area()*m_sdkRule.fSensitivity)
                     {
-                        obj.isMove = score.isMove;
+                        if(obj.times ==0)
+                        {
+                            obj.times=AppUtil::getCurrentUs();
+                        }
+                        else if( (now-obj.times)>m_sdkRule.nTriggerDelay*60*1000*1000)
+                        {
+                            DBG("now-obj.times="<<now-obj.times);
+                            if(pointArray!=nullptr)
+                            {
+                                const cv::Point2i* ppt[1] = { pointArray };
+
+                                int npt[]={npts};
+
+                                cv::polylines(image, ppt,npt, 1, true,cv::Scalar(255,255,0));
+                            }
+                            cv::rectangle(image, obj.rect,  cv::Scalar(0, 0, 255), 2);
+                            auto t_image = image(CvUtil::zoomRectEqual(obj.rect, 1.2, 1.2) & cv::Rect(0, 0, image.cols, image.rows)).clone();
+                            std::string imgUrl=uploadImgToFdfs(t_image);
+                            saveInfoToEs(imgUrl,obj);
+                            obj.times=0;
+                        }
                         //DBG("moving? "<<_TrackingInfo.m_bMoveState)
                         break;
                     }
@@ -71,44 +91,47 @@
             }
 
     }
-    if((AppUtil::getCurrentUs()-m_lTime)>(m_sdkRule.nTriggerDelay*60*1000*1000))
-    {
-        for(auto& obj: mObjs){
-
-            //compare with last temp memery and clear temp memery
-            for(auto ele:m_lastScoreRect)
-            {
-                if(ele.id==obj.id)
-                {
-                    if((obj.rect&ele.rect).area()>ele.rect.area()*m_sdkRule.fSensitivity)
-                    {
-                        //not moving
-                        obj.isMove = true;
-
-                         auto t_image = image(CvUtil::zoomRectEqual(obj.rect, 1.2, 1.2) & cv::Rect(0, 0, image.cols, image.rows)).clone();
-                         std::string imgUrl=uploadImgToFdfs(t_image);
-                         saveInfoToEs(imgUrl,obj);
-                         m_triggerElement.setState(true);
-                        //DBG("not moving")
-                    }
-                    else
-                    {
-                        obj.isMove = false;
-                        m_triggerElement.setState(false);
-                        //DBG("moving")
-                    }
-                    break;
-                }
-            }
-            //do temp memery
-
-        }
-     //   m_lastScoreRect = mObjs;
-        m_lTime =AppUtil::getCurrentUs();
-    }
-
     m_lastScoreRect=mObjs;
-    m_triggerElement.triggerOnce();
+//    if((AppUtil::getCurrentUs()-m_lTime)>(m_sdkRule.nTriggerDelay*60*1000*1000))
+//    {
+//        for(auto& obj: mObjs){
+
+//            //compare with last temp memery and clear temp memery
+//            for(auto ele:m_lastScoreRect)
+//            {
+//                if(ele.id==obj.id)
+//                {
+//                    if((obj.rect&ele.rect).area()>ele.rect.area()*m_sdkRule.fSensitivity)
+//                    {
+//                        //not moving
+//                        obj.isMove = true;
+
+//                         auto t_image = image(CvUtil::zoomRectEqual(obj.rect, 1.2, 1.2) & cv::Rect(0, 0, image.cols, image.rows)).clone();
+//                         std::string imgUrl=uploadImgToFdfs(t_image);
+//                         saveInfoToEs(imgUrl,obj);
+//                         m_triggerElement.setState(true);
+//                        //DBG("not moving")
+//                    }
+//                    else
+//                    {
+//                        obj.isMove = false;
+//                        m_triggerElement.setState(false);
+//                        //DBG("moving")
+//                    }
+//                    break;
+//                }
+//            }
+//            //do temp memery
+
+//        }
+//     //   m_lastScoreRect = mObjs;
+//        m_lTime =AppUtil::getCurrentUs();
+//    }
+
+//    m_lastScoreRect=mObjs;
+
+  m_triggerElement.setState(true);
+  m_triggerElement.triggerOnce();
 
 
     fireConnectors();
@@ -149,6 +172,9 @@
         m_bIsMask=false;
         return;//do not detect
     }
+    int size=arrayAreas.size();
+    npts=size;
+    pointArray=new cv::Point2i[size];
     for(int i = 0;i < arrayAreas.size();++i)
     {
         QJsonValue jsonValue = arrayAreas[i];
@@ -211,29 +237,29 @@
     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"] =m_sdkRule.strAddr.toStdString();// 鎶撴媿鍦板潃
-    t_json["picMaxUrl"] = "wait todo"; // 澶у浘璺緞
+    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: 鏈煡
diff --git a/QiaoJiaSystem/StructureApp/PerStaticElement.h b/QiaoJiaSystem/StructureApp/PerStaticElement.h
index edb88b8..fb55313 100644
--- a/QiaoJiaSystem/StructureApp/PerStaticElement.h
+++ b/QiaoJiaSystem/StructureApp/PerStaticElement.h
@@ -80,6 +80,8 @@
     unsigned long long m_lTime;
     EsDBTool* pManagerEsDB;
     bool m_bIsMask;
+     cv::Point2i* pointArray;
+     int npts;
 };
 
 #endif // PAELEMENT_H
diff --git a/QiaoJiaSystem/StructureApp/PerimeterElement.cpp b/QiaoJiaSystem/StructureApp/PerimeterElement.cpp
index b605b07..c081c6b 100644
--- a/QiaoJiaSystem/StructureApp/PerimeterElement.cpp
+++ b/QiaoJiaSystem/StructureApp/PerimeterElement.cpp
@@ -21,7 +21,8 @@
     mRealNum(0),
     m_triggerElement(rule.nTriggerDelay*8,0),
     pManagerEsDB(nullptr),
-    m_bIsMask(true)
+    m_bIsMask(true),
+    pointArray(nullptr)
 {
 
     pManagerEsDB = new EsDBTool(appPref.getStringData("ipAdd"), appPref.getIntData("ipPort"));
@@ -31,6 +32,11 @@
     if (pManagerEsDB) {
         delete pManagerEsDB;
         pManagerEsDB = nullptr;
+    }
+    if(pointArray)
+    {
+//        delete[] pointArray[0];
+        delete[] pointArray;
     }
 }
 
@@ -157,13 +163,29 @@
     if (m_triggerElement.getTriggerState() )
     {
         if(num > 0) {
-            cv::Mat t_image = image(CutMask()).clone();
-            if(t_image.empty())
+
+
+
+            if(pointArray!=nullptr)
             {
-                DBG("t_image empty");
-                return;
+                const cv::Point2i* ppt[1] = { pointArray };
+
+                int npt[]={npts};
+
+                cv::polylines(image, ppt,npt, 1, true,cv::Scalar(255,255,0));
             }
-            std::string imgUrl = uploadImgToFdfs(t_image);
+
+            for(auto rect:m_recVec)
+            {
+                cv::rectangle(image, rect,  cv::Scalar(0, 0, 255), 2);
+            }
+//            cv::Mat t_image = image(CutMask()).clone();
+//            if(t_image.empty())
+//            {
+//                DBG("t_image empty");
+//                return;
+//            }
+            std::string imgUrl = uploadImgToFdfs(image);
             saveInfoToEs(imgUrl, picDate);
         }
         DBG("num=" << num << " lastnum=" << mRealNum);
@@ -235,12 +257,22 @@
     }
     int size = arrayAreas.size();
     npts = size;
+//    pointArray=new cv::Point2i*[1];
+//    pointArray[0]=new cv::Point2i[size];
+
+        pointArray=new cv::Point2i[npts];
+
+
     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};
+
+
         if(m_sdkRule.nSdkType == PerimeterSdk)
         {
              poly1.push_back(Point(x,y));
@@ -312,31 +344,31 @@
 //    DBG("to_string(m_sdkRule.nSdkType)="<<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"] = m_sdkRule.strAddr.toStdString();// 鎶撴媿鍦板潃
     DBG("picAddress="<<m_sdkRule.strAddr.toStdString());
-    t_json["picMaxUrl"] = "wait todo"; // 澶у浘璺緞
+    t_json["picMaxUrl"] = ""; // 澶у浘璺緞
 
 
     //   t_json["Age"] ="wait todo";
     t_json["picDate"] = time; // 鎶撴媿鏃堕棿锛屽繀椤绘湁
      DBG("picDate="<<time);
-    t_json["picLocalUrl"] = "wait todo";  // 鏈湴璺緞
+    t_json["picLocalUrl"] = "";  // 鏈湴璺緞
     t_json["isDelete"] = "1";//榛樿1 ,0鏃犳晥 1鏈夋晥
 
-    t_json["likePer"] = "0"; // 鐩镐技鍊�
+    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: 鏈煡
@@ -416,7 +448,4 @@
 //   DBG("RECT x="<<rect.x<<"y"<<rect.y<<"w"<<rect.width<<"h"<<rect.height);
     return rect;
 }
-bool PerimeterElement::isAnd()
-{
 
-}
diff --git a/QiaoJiaSystem/StructureApp/PerimeterElement.h b/QiaoJiaSystem/StructureApp/PerimeterElement.h
index 3e6e35e..24f32f7 100644
--- a/QiaoJiaSystem/StructureApp/PerimeterElement.h
+++ b/QiaoJiaSystem/StructureApp/PerimeterElement.h
@@ -66,7 +66,6 @@
     void setMask(std::string mask);
     bool isInWeek(const std::vector<LActRuleWeekRecord>& ruleWeek);
     cv::Rect CutMask();
-    bool isAnd();
 private:
     cv::Mat image;
     //cv::Mat mask;
@@ -83,12 +82,12 @@
     EsDBTool* pManagerEsDB;
 
 
-   int npts;
+    int npts;
    std::vector<cv::Rect> m_recVec;
 
    bool m_bIsMask;
    std::vector<Point> poly1;
-
+   cv::Point2i* pointArray;
 
 };
 
diff --git a/QiaoJiaSystem/StructureApp/PersonElement.cpp b/QiaoJiaSystem/StructureApp/PersonElement.cpp
index 6509449..5a73369 100644
--- a/QiaoJiaSystem/StructureApp/PersonElement.cpp
+++ b/QiaoJiaSystem/StructureApp/PersonElement.cpp
@@ -91,7 +91,8 @@
 //                    faceRpcElement.setProperty("frame_number", frame_number);
                     t_json["picDate"] = obj.properties["time"];
                     t_json["content"] = "wait todo";
-                    t_json["viType"] = "2";//鍙湁4绉嶇被鍨� 1:personface 2:personbody 3:car 4:bicycle 5:none 鏈煡绫诲瀷
+                    t_json["sdkType"] = std::to_string(m_sdkRule.nSdkType);
+                    //t_json["viType"] = "2";//鍙湁4绉嶇被鍨� 1:personface 2:personbody 3:car 4:bicycle 5:none 鏈煡绫诲瀷
                     t_json["personIsHub"] = "4";//1: 鎶ヨ  2: 鍙枒  3: 瀹夊叏  4: 鏈煡
                     t_json["videoIp"] = getProperty("local_ip");//褰撳墠鏈嶅姟鍣↖P鍦板潃
 
diff --git a/QiaoJiaSystem/StructureApp/TrackingTrigger.h b/QiaoJiaSystem/StructureApp/TrackingTrigger.h
index a9aa7a8..3f1019c 100644
--- a/QiaoJiaSystem/StructureApp/TrackingTrigger.h
+++ b/QiaoJiaSystem/StructureApp/TrackingTrigger.h
@@ -9,8 +9,9 @@
 using namespace std;
 
 struct ScoredRect {
-    ScoredRect() : id(-1) ,isMove(false){}
+    ScoredRect() : id(-1) ,isMove(false),times(0){}
     bool isMove;
+    time_t times;
     float score;
     cv::Rect rect;
     long id;
diff --git a/QiaoJiaSystem/VideoServer/QiaoJia/DB/DBStruct.h b/QiaoJiaSystem/VideoServer/QiaoJia/DB/DBStruct.h
index 64e0d36..684890d 100644
--- a/QiaoJiaSystem/VideoServer/QiaoJia/DB/DBStruct.h
+++ b/QiaoJiaSystem/VideoServer/QiaoJia/DB/DBStruct.h
@@ -44,7 +44,7 @@
     QDateTime tim_start_time;//寮�濮嬩笅杞界殑鏂囦欢鐨勬椂闂�
     int n_duration;//姣忔涓嬭浇鐨勬椂闂撮暱搴︼紝鍗曚綅锛氬皬鏃�
     QString str_brand;//鍝佺墝
-    QString str_reserved;//棰勭暀
+    QString str_reserved;//鎴浘鍦板潃
 };
 
 struct Record_Cam_Dev
diff --git a/QiaoJiaSystem/VideoServer/QiaoJia/DB/LDBTool.cpp b/QiaoJiaSystem/VideoServer/QiaoJia/DB/LDBTool.cpp
index 93ca3ab..8b8a3e1 100644
--- a/QiaoJiaSystem/VideoServer/QiaoJia/DB/LDBTool.cpp
+++ b/QiaoJiaSystem/VideoServer/QiaoJia/DB/LDBTool.cpp
@@ -453,7 +453,39 @@
         return false;
     }
 }
+bool LDBTool::updateCamDevSnapshot(const QString& strIp,const QString& imgUrl)
+{
+    QMutexLocker mutexLocker(&m_mutexVisit);//TODO
+    QSqlTableModel pModel(NULL, m_db);
+    pModel.setTable("cam_dev");
+    pModel.setFilter(
+        QObject::tr("ip = '%1'").arg(strIp));
+    pModel.setEditStrategy(QSqlTableModel::OnManualSubmit);//OnManualSubmit OnFieldChange
+    pModel.select();
 
+    QSqlRecord rec = pModel.record(0);
+    rec.setValue("reserved", imgUrl);
+
+    int rowCount = pModel.rowCount();
+    if (rowCount > 0)
+    {
+        pModel.setRecord(0, rec);//TODO
+    }
+
+    m_db.transaction();//寮�濮嬩簨鍔℃搷浣�
+
+    if (pModel.submitAll())
+    {
+        m_db.commit();//鎻愪氦
+        return true;
+    }
+    else
+    {
+        m_db.rollback();//鍥炴粴
+        ERR("updateCamDevSnapshot err ,Database Error: " << pModel.lastError().text().toStdString());
+        return false;
+    }
+}
 int LDBTool::searchCamDevNumber(void) {
     QSqlTableModel pModel(NULL, m_db);
     pModel.setTable("cam_dev");
diff --git a/QiaoJiaSystem/VideoServer/QiaoJia/DB/LDBTool.h b/QiaoJiaSystem/VideoServer/QiaoJia/DB/LDBTool.h
index a3eaa3e..3521d79 100644
--- a/QiaoJiaSystem/VideoServer/QiaoJia/DB/LDBTool.h
+++ b/QiaoJiaSystem/VideoServer/QiaoJia/DB/LDBTool.h
@@ -52,6 +52,7 @@
     std::list<Record_Cam_Dev> searchCamDevTableAll(void);
     int searchCamDevNumber(void);
     bool searchCamDevByCamId(QString strCamId);
+    bool updateCamDevSnapshot(const QString& strIp ,const QString& imgUrl);
 
     //load_file_info
     bool insertLoadFileTable(Record_Load_File_info loadfileRec);
diff --git a/QiaoJiaSystem/YoloServer/main.cpp b/QiaoJiaSystem/YoloServer/main.cpp
index a44a900..20f2a6c 100644
--- a/QiaoJiaSystem/YoloServer/main.cpp
+++ b/QiaoJiaSystem/YoloServer/main.cpp
@@ -29,7 +29,7 @@
 //        return -1;
 //    }
 
-    int gpuindex = 1;
+    int gpuindex = 0;
     int poolNum = 1;
     int portNum = 10003;
 

--
Gitblit v1.8.0