From 1c622cd0d7d95709ab224224af18a22630aede75 Mon Sep 17 00:00:00 2001
From: zhangjixing <775834166@qq.com>
Date: 星期一, 28 一月 2019 20:02:04 +0800
Subject: [PATCH] 画框根据概率缩放坐标

---
 QiaoJiaSystem/StructureApp/AppPipeController.cpp      |   33 ++++++----
 QiaoJiaSystem/StructureApp/FaceRpcElement.h           |    1 
 QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.cpp |   24 ++++++-
 QiaoJiaSystem/StructureApp/PerimeterElement.cpp       |   34 +++++-----
 QiaoJiaSystem/StructureApp/PerimeterElement.h         |    1 
 QiaoJiaSystem/DataManagerServer/web-server接口.txt      |    4 
 QiaoJiaSystem/StructureApp/PerStaticElement.h         |    1 
 QiaoJiaSystem/StructureApp/FaceRpcElement.cpp         |   18 ++++-
 QiaoJiaSystem/StructureApp/PerStaticElement.cpp       |   19 ++++-
 QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.h   |    7 ++
 QiaoJiaSystem/StructureApp/AppPipeController.h        |    1 
 11 files changed, 96 insertions(+), 47 deletions(-)

diff --git "a/QiaoJiaSystem/DataManagerServer/web-server\346\216\245\345\217\243.txt" "b/QiaoJiaSystem/DataManagerServer/web-server\346\216\245\345\217\243.txt"
index 9988ae6..2fc9ad8 100644
--- "a/QiaoJiaSystem/DataManagerServer/web-server\346\216\245\345\217\243.txt"
+++ "b/QiaoJiaSystem/DataManagerServer/web-server\346\216\245\345\217\243.txt"
@@ -191,7 +191,7 @@
       "str_longitude" : "39.994827",
       "str_name" : "澶у崕鎽勫儚鏈�2",
       "str_password" : "123456",
-      "str_reserved" : "",
+      "str_reserved" : "group2/M00/02/7F/wKgBnFw1whWAT5DbAALrl1a_A04988.jpg", //瀹炴椂娴佹埅鍥�
      // "str_sdks" : "1,2",
       "str_username" : "admin"
    },
@@ -206,7 +206,7 @@
       "str_longitude" : "39.994833",
       "str_name" : "澶у崕鎽勫儚鏈�3",
       "str_password" : "123433",
-      "str_reserved" : "",
+      "str_reserved" : "group2/M00/02/7F/wKgBnFw1whWAT5DbAALrl1a_A04988.jpg",//瀹炴椂娴佹埅鍥�
       //"str_sdks" : "1,2,3",
       "str_username" : "admin"
    }
diff --git a/QiaoJiaSystem/StructureApp/AppPipeController.cpp b/QiaoJiaSystem/StructureApp/AppPipeController.cpp
index c8e3733..e323265 100644
--- a/QiaoJiaSystem/StructureApp/AppPipeController.cpp
+++ b/QiaoJiaSystem/StructureApp/AppPipeController.cpp
@@ -80,7 +80,9 @@
     leftJudgment(ruleMap[KeepRightSdk]),
     rightJudgment(ruleMap[KeepRightSdk]),
     bRecordVideoEnable(RecordVideoEnable),
-    m_sdkRuleMap(ruleMap) {
+    m_sdkRuleMap(ruleMap),
+    m_bSetWH(false)
+{
     DBG("camId" << camId);
     init();
     initPerimeter();
@@ -192,12 +194,17 @@
     //  int max=appPref.getIntData("n_cut_max_duration");
     // recordInit(40,100);
     videoCaptureElement.registerConnector([&] {
-//        mutex.lock();
 
 
-//        std::string tmp="camId="+m_camId+"videoCaptureElement";
-//        ClockTimer cl(tmp);
         cv::Mat imageTemp = videoCaptureElement.getImage();
+
+        if(!m_bSetWH)
+        {
+            appPref.setIntData(m_camId+"width",imageTemp.cols);
+            appPref.setIntData(m_camId+"height",imageTemp.rows);
+            m_bSetWH=true;
+        }
+
         std::string  strNewTime = AppUtil::getTimeUSecString();;
 
         //DBG("m_camId="<<m_camId<<"  strNewTime="<<strNewTime);
@@ -233,7 +240,7 @@
             strNewTime = newDt.toString("yyyy-MM-dd hh:mm:ss").toStdString();
 
         }
-//  mutex.unlock();
+
 //        DBG(strNewTime);
 //        std::string tmp1="camId="+m_camId+"strNewTime"+strNewTime;
 //        ClockTimer cl1(tmp1);
@@ -254,10 +261,10 @@
             yoloRpcElement.submit();
         }
 
-        if (!imageDrawElement.isBusy()) {
-            imageDrawElement.setImage(imageTemp);
-            imageDrawElement.submit();
-        }
+//        if (!imageDrawElement.isBusy()) {
+//            imageDrawElement.setImage(imageTemp);
+//            imageDrawElement.submit();
+//        }
 
 //        if (bRecordVideoEnable) {
 //            registerElement(triggerElement);
@@ -266,7 +273,7 @@
 
 
     yoloRpcElement.registerConnector([&] {
-        imageDrawElement.setYoloObjects(personElement.getLastScoreRects());
+//        imageDrawElement.setYoloObjects(personElement.getLastScoreRects());
         if (!personElement.isBusy()) {
 
             personElement.setObjsResults(yoloRpcElement.getLastScoreRects());
@@ -275,7 +282,7 @@
     });
 
     faceRpcElement.registerConnector([&] {
-        imageDrawElement.setFaces(faceRpcElement.getLastScoreRects());
+//        imageDrawElement.setFaces(faceRpcElement.getLastScoreRects());
     });
 
     yoloRpcElement.registerConnector("YoloTrigger", [&] {
@@ -294,7 +301,7 @@
 
     imageDrawElement.registerConnector([&] {
         if (appPref.getIntData("show.image") == 1) {
-            ImageShowElement::showImage(to_string(this->m_index), *imageDrawElement.getImage());
+           ImageShowElement::showImage(to_string(this->m_index), *imageDrawElement.getImage());
         }
     });
 
@@ -307,7 +314,7 @@
         registerElement(faceRpcElement);
         registerElement(faceExtractElement);
     }
-    registerElement(imageDrawElement);
+//    registerElement(imageDrawElement);
    // registerElement(newRecordVideoElement);
     videoCaptureElement.setOutPutInterval(3);
     faceExtractElement.setProperty("index", to_string(m_index));
diff --git a/QiaoJiaSystem/StructureApp/AppPipeController.h b/QiaoJiaSystem/StructureApp/AppPipeController.h
index 9e031af..b7effa4 100644
--- a/QiaoJiaSystem/StructureApp/AppPipeController.h
+++ b/QiaoJiaSystem/StructureApp/AppPipeController.h
@@ -110,6 +110,7 @@
     std::string m_localIp;
     std::string getFullFileName();
     std::mutex mutex;
+    bool m_bSetWH;
 };
 
 #endif // APPPIPECONTROLLER_H
diff --git a/QiaoJiaSystem/StructureApp/FaceRpcElement.cpp b/QiaoJiaSystem/StructureApp/FaceRpcElement.cpp
index 3a4c807..ce9272c 100644
--- a/QiaoJiaSystem/StructureApp/FaceRpcElement.cpp
+++ b/QiaoJiaSystem/StructureApp/FaceRpcElement.cpp
@@ -39,7 +39,8 @@
     sharedMemory(nullptr),
     trackingTrigger(nullptr),
     m_sdkRule(rule),
-    m_bIsMask(true)
+    m_bIsMask(true),
+    m_bSetWH(false)
 {
     sharedMemory = new QSharedMemory(QString(shareMemoryName.c_str()));
     if (!sharedMemory->create(4608 * 2592 * 4)) {
@@ -68,7 +69,7 @@
     t_score = t_score / 100;
 
     trackingTrigger = new TrackingTrigger(t_score);
-    setMask(m_sdkRule.strAreas.toStdString());
+//    setMask(m_sdkRule.strAreas.toStdString());
 }
 
 FaceRpcElement::~FaceRpcElement() {
@@ -178,6 +179,11 @@
         image = cv::Mat(value.rows, value.cols, CV_8UC3, sharedMemory->data());
     }
     value.copyTo(image);
+    if(!m_bSetWH)
+    {
+        setMask(m_sdkRule.strAreas.toStdString());
+        m_bSetWH=true;
+    }
 }
 
 bool FaceRpcElement::getTriggerState() const {
@@ -191,13 +197,17 @@
         m_bIsMask=false;
         return;//do not detect
     }
+    float sizeW=(float)appPref.getIntData(m_sdkRule.strCamId.toStdString()+"width")/480;
+    float sizeH=(float)appPref.getIntData(m_sdkRule.strCamId.toStdString()+"height")/270;
     for(int i = 0;i < arrayAreas.size();++i)
     {
         QJsonValue jsonValue = arrayAreas[i];
         QJsonObject obj = jsonValue.toObject();
-        int x = obj.value("x").toDouble()*4;
-        int y = obj.value("y").toDouble()*4;
+        int x = obj.value("x").toDouble() *sizeW ;
+        int y = obj.value("y").toDouble() *sizeH;
         mPolygon<<(QPoint(x,y));
+        DBG("width="<<sizeW);
+        DBG("height="<<sizeH);
 
     }
 }
diff --git a/QiaoJiaSystem/StructureApp/FaceRpcElement.h b/QiaoJiaSystem/StructureApp/FaceRpcElement.h
index bb12780..64002da 100644
--- a/QiaoJiaSystem/StructureApp/FaceRpcElement.h
+++ b/QiaoJiaSystem/StructureApp/FaceRpcElement.h
@@ -54,6 +54,7 @@
     TriggerElement m_triggerElement;
     SdkRule m_sdkRule;
     bool m_bIsMask;
+    bool m_bSetWH;
 };
 
 #endif // FACERPCELEMENT_H
diff --git a/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.cpp b/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.cpp
index d0f6d34..34d4b3c 100644
--- a/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.cpp
+++ b/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.cpp
@@ -13,6 +13,7 @@
     m_triggerElement(0, 0),
     m_sdkRule(rule),
     pManagerEsDB(nullptr),
+    m_bSetWH(false),
     pointArray(nullptr),
     npts(0)
 {
@@ -31,8 +32,13 @@
     }
 
 }
+bool JudgmentRetrogradeTool::init(QString area, QString line)
+{
+    m_area=area;
+    m_line=line;
+}
 
-bool JudgmentRetrogradeTool::init(QString area, QString line) {
+bool JudgmentRetrogradeTool::setMask(QString area, QString line) {
 
     //#todo string ->json
     QJsonArray arrayAreas = getJsonArrayFromQString(area);
@@ -41,14 +47,17 @@
     }
     int size=arrayAreas.size();
     QVector<QPoint> vec;
+    float sizeW=(float)appPref.getIntData(m_sdkRule.strCamId.toStdString()+"width")/480;
+    float sizeH=(float)appPref.getIntData(m_sdkRule.strCamId.toStdString()+"height")/270;
+    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};
+        int x = obj.value("x").toDouble() *sizeW;
+        int y = obj.value("y").toDouble() *sizeH;
         vec.push_back(QPoint(x, y));
+        DBG("width="<<sizeW);
+        DBG("height="<<sizeH);
     }
 
 
@@ -345,4 +354,9 @@
 
 void JudgmentRetrogradeTool::setImage(const cv::Mat &value) {
     value.copyTo(image);
+    if(!m_bSetWH)
+    {
+        setMask(m_area,m_line);
+        m_bSetWH=true;
+    }
 }
diff --git a/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.h b/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.h
index d69df24..6ab8995 100644
--- a/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.h
+++ b/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.h
@@ -1,4 +1,4 @@
-//
+锘�//
 // Created by basic on 18-8-24.
 //
 
@@ -74,6 +74,8 @@
     void setImage(const cv::Mat &value);
 
 private:
+    bool setMask(QString area, QString line);
+
     void setPerPoint(const long &, cv::Point2f);
 
     void setPerRect(const long &, cv::Rect rect);
@@ -141,6 +143,9 @@
     cv::Point2i* pointArray;
 
     int npts;
+    QString m_area;
+    QString m_line;
+    bool m_bSetWH;
 };
 
 
diff --git a/QiaoJiaSystem/StructureApp/PerStaticElement.cpp b/QiaoJiaSystem/StructureApp/PerStaticElement.cpp
index 667bb9a..1aa7c86 100644
--- a/QiaoJiaSystem/StructureApp/PerStaticElement.cpp
+++ b/QiaoJiaSystem/StructureApp/PerStaticElement.cpp
@@ -17,7 +17,8 @@
 m_triggerElement(0,0),
 m_lTime(AppUtil::getCurrentUs()),
 pManagerEsDB(nullptr),
-m_bIsMask(true)
+m_bIsMask(true),
+m_bSetWH(false)
 {
    pManagerEsDB=new EsDBTool(appPref.getStringData("ipAdd"), appPref.getIntData("ipPort"));
 
@@ -36,7 +37,7 @@
 
 void PerStaticElement::threadInitial()
 {
-   setMask(m_sdkRule.strAreas.toStdString());
+//   setMask(m_sdkRule.strAreas.toStdString());
 }
 
 
@@ -175,14 +176,17 @@
     int size=arrayAreas.size();
     npts=size;
     pointArray=new cv::Point2i[size];
+    float sizeW=(float)appPref.getIntData(m_sdkRule.strCamId.toStdString()+"width")/480;
+    float sizeH=(float)appPref.getIntData(m_sdkRule.strCamId.toStdString()+"height")/270;
     for(int i = 0;i < arrayAreas.size();++i)
     {
         QJsonValue jsonValue = arrayAreas[i];
         QJsonObject obj = jsonValue.toObject();
-        int x = obj.value("x").toDouble()*4;
-        int y = obj.value("y").toDouble()*4;
+        int x = obj.value("x").toDouble() *sizeW;
+        int y = obj.value("y").toDouble() *sizeH;
         mPolygon<<(QPoint(x,y));
-
+        DBG("width="<<sizeW);
+        DBG("height="<<sizeH);
     }
 }
 QJsonArray PerStaticElement::getJsonArrayFromQString(const QString& strJson)
@@ -300,4 +304,9 @@
 {
 
     value.copyTo(image);
+    if(!m_bSetWH)
+    {
+        setMask(m_sdkRule.strAreas.toStdString());
+        m_bSetWH=true;
+    }
 }
diff --git a/QiaoJiaSystem/StructureApp/PerStaticElement.h b/QiaoJiaSystem/StructureApp/PerStaticElement.h
index fb55313..6380f24 100644
--- a/QiaoJiaSystem/StructureApp/PerStaticElement.h
+++ b/QiaoJiaSystem/StructureApp/PerStaticElement.h
@@ -80,6 +80,7 @@
     unsigned long long m_lTime;
     EsDBTool* pManagerEsDB;
     bool m_bIsMask;
+    bool m_bSetWH;
      cv::Point2i* pointArray;
      int npts;
 };
diff --git a/QiaoJiaSystem/StructureApp/PerimeterElement.cpp b/QiaoJiaSystem/StructureApp/PerimeterElement.cpp
index c081c6b..bdb066f 100644
--- a/QiaoJiaSystem/StructureApp/PerimeterElement.cpp
+++ b/QiaoJiaSystem/StructureApp/PerimeterElement.cpp
@@ -22,6 +22,7 @@
     m_triggerElement(rule.nTriggerDelay*8,0),
     pManagerEsDB(nullptr),
     m_bIsMask(true),
+    m_bSetWH(false),
     pointArray(nullptr)
 {
 
@@ -42,7 +43,7 @@
 
 
 void PerimeterElement::threadInitial() {
-    setMask(m_sdkRule.strAreas.toStdString());
+//    setMask(m_sdkRule.strAreas.toStdString());
 }
 
 
@@ -56,7 +57,7 @@
     bool state = false;
 
     m_recVec.clear();
-    //   DBG("Objs="<<mObjs.size()<<" fSensitivity="<<m_sdkRule.fSensitivity<<" nThreshold"<<m_sdkRule.nThreshold);
+//    DBG("Objs="<<mObjs.size()<<" fSensitivity="<<m_sdkRule.fSensitivity<<" nThreshold"<<m_sdkRule.nThreshold);
 
     for (auto obj:mObjs) {
 
@@ -111,6 +112,7 @@
 
     }
 
+
     switch (m_sdkRule.nSdkType) {
         case PerimeterSdk:
             //state = num > 0 ;
@@ -163,9 +165,6 @@
     if (m_triggerElement.getTriggerState() )
     {
         if(num > 0) {
-
-
-
             if(pointArray!=nullptr)
             {
                 const cv::Point2i* ppt[1] = { pointArray };
@@ -257,22 +256,16 @@
     }
     int size = arrayAreas.size();
     npts = size;
-//    pointArray=new cv::Point2i*[1];
-//    pointArray[0]=new cv::Point2i[size];
-
-        pointArray=new cv::Point2i[npts];
-
-
+    float sizeW=(float)appPref.getIntData(m_sdkRule.strCamId.toStdString()+"width")/480;
+    float sizeH=(float)appPref.getIntData(m_sdkRule.strCamId.toStdString()+"height")/270;
+    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;
-
+        int x = obj.value("x").toDouble() *sizeW;
+        int y = obj.value("y").toDouble() *sizeH;
         pointArray[i]={x,y};
-
-
         if(m_sdkRule.nSdkType == PerimeterSdk)
         {
              poly1.push_back(Point(x,y));
@@ -281,7 +274,8 @@
         {
              mPolygon << (QPoint(x, y));
         }
-
+        DBG("width="<<sizeW);
+        DBG("height="<<sizeH);
 
 
     }
@@ -302,6 +296,12 @@
 //        image = cv::Mat(value.rows, value.cols, CV_8UC3, sharedMemory->data());
 //    }
     value.copyTo(image);
+    if(!m_bSetWH)
+    {
+        setMask(m_sdkRule.strAreas.toStdString());
+        m_bSetWH=true;
+    }
+
 }
 
 bool PerimeterElement::getTriggerState() const {
diff --git a/QiaoJiaSystem/StructureApp/PerimeterElement.h b/QiaoJiaSystem/StructureApp/PerimeterElement.h
index 24f32f7..4a1d3fe 100644
--- a/QiaoJiaSystem/StructureApp/PerimeterElement.h
+++ b/QiaoJiaSystem/StructureApp/PerimeterElement.h
@@ -87,6 +87,7 @@
 
    bool m_bIsMask;
    std::vector<Point> poly1;
+   bool m_bSetWH;
    cv::Point2i* pointArray;
 
 };

--
Gitblit v1.8.0