From 9f08028f23d9e5cbfa159bec1e07d63b141a6809 Mon Sep 17 00:00:00 2001 From: zhangjixing <775834166@qq.com> Date: 星期五, 18 一月 2019 10:17:00 +0800 Subject: [PATCH] --- QiaoJiaSystem/build/EncodeServer | 0 QiaoJiaSystem/VideoAnalysFromHC/RtspAnalysElement.cpp | 29 +- QiaoJiaSystem/build/RapidStructureApp | 0 QiaoJiaSystem/StructureApp/PerimeterElement.cpp | 118 ++++++++--- QiaoJiaSystem/build/FaceSearchServer | 0 QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.h | 3 QiaoJiaSystem/YoloServer/main.cpp | 14 QiaoJiaSystem/build/DataWebServer | 0 QiaoJiaSystem/StructureApp/IntAreaCalcUtil.cpp | 2 QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.cpp | 88 +++++--- QiaoJiaSystem/StructureApp/IntAreaCalcUtil.h | 238 +++++++++++++++++++++++ QiaoJiaSystem/RapidStructureApp/TriggerElement.cpp | 6 QiaoJiaSystem/StructureApp/PerimeterElement.h | 6 QiaoJiaSystem/build/RecordVideo | 0 QiaoJiaSystem/build/scpToSer.sh | 2 QiaoJiaSystem/CMakeLists.txt | 2 QiaoJiaSystem/build/YoloServer | 0 QiaoJiaSystem/build/YoloDetectClientTest | 0 QiaoJiaSystem/StructureApp/PerStaticElement.cpp | 4 QiaoJiaSystem/build/RapidStructureAppRtsp | 0 QiaoJiaSystem/RapidStructureApp/TriggerElement.h | 2 QiaoJiaSystem/StructureApp/AppPipeController.cpp | 10 QiaoJiaSystem/DataManagerServer/http_configserver.cpp | 21 + QiaoJiaSystem/VideoServer/QiaoJia/DB/LDBTool.cpp | 28 ++ QiaoJiaSystem/VideoAnalysFromHC/CMakeLists.txt | 1 QiaoJiaSystem/YoloServer/YoloDetectServerI.cpp | 1 QiaoJiaSystem/build/VideoAnalysFromHC | 0 QiaoJiaSystem/StructureApp/CMakeLists.txt | 1 QiaoJiaSystem/build/config.db | 0 QiaoJiaSystem/StructureApp/YoloRpcElement.cpp | 18 - QiaoJiaSystem/build/StructureApp | 0 31 files changed, 478 insertions(+), 116 deletions(-) diff --git a/QiaoJiaSystem/CMakeLists.txt b/QiaoJiaSystem/CMakeLists.txt index 0d53a05..24bb196 100644 --- a/QiaoJiaSystem/CMakeLists.txt +++ b/QiaoJiaSystem/CMakeLists.txt @@ -14,7 +14,7 @@ ../../BasicPlatForm/libs/libuuid/include ) -#add_subdirectory(StructureApp) +add_subdirectory(StructureApp) add_subdirectory(FaceDetectServer) add_subdirectory(YoloServer) add_subdirectory(FaceSearchServer) diff --git a/QiaoJiaSystem/DataManagerServer/http_configserver.cpp b/QiaoJiaSystem/DataManagerServer/http_configserver.cpp index bc399be..bc54682 100644 --- a/QiaoJiaSystem/DataManagerServer/http_configserver.cpp +++ b/QiaoJiaSystem/DataManagerServer/http_configserver.cpp @@ -395,6 +395,7 @@ /*sdk login*/ ulRet = IMOS_MW_Login(username, passwd, ip, 0, szUserID); if (ERR_COMMON_SUCCEED != ulRet) { + (VOID) IMOS_MW_Cleanup(); printf("Login error ulRet[%lu]", ulRet); return false; } @@ -402,6 +403,8 @@ pstBasicInfo = (IMOS_MW_BASIC_DEVICE_INFO_S *) malloc(sizeof(IMOS_MW_BASIC_DEVICE_INFO_S)); ulRet = IMOS_MW_GetDeviceStatus(szUserID, 0, IMOS_MW_STATUS_BASIC_INFO, (void *) pstBasicInfo); if (ERR_COMMON_SUCCEED != ulRet) { + (VOID) IMOS_MW_Logout(szUserID); + (VOID) IMOS_MW_Cleanup(); printf("GetDeviceStatus Error[%lu]\n", ulRet); return false; } @@ -1048,7 +1051,7 @@ { if(is_exist) { - return "{\"ret_status\": \"鍐呭鏈夎锛岃妫�鏌ワ紒\"}"; + return "{\"ret_status\": \"璇峰嬁閲嶅娣诲姞!\"}"; } else { @@ -3043,13 +3046,27 @@ std::string pass = value["str_password"].asString(); std::string brand = value["str_brand"].asString(); std::string rtsp_url = rtspAddrBuild(ip, port, username, pass, brand); - if (rtsp_url.empty()) { + if (rtsp_url.empty() ) + { return "{\"ret_status\":\"鍐呭鏈夎锛岃妫�鏌ワ紒\"}"; } +// unsigned char serialnumber[SERIALNO_LEN] = {0}; +// int ret = getDevSerialNumber(ip.c_str(), port,username.c_str(),pass.c_str(),brand.c_str(),serialnumber); + + +// if ((!ret) || (serialnumber[0] == 0)) +// { +// return "{\"ret_status\": \"鍐呭鏈夎锛岃妫�鏌ワ紒\"}"; +// } + +// std::string str_cam_dev_id = std::string((char *) serialnumber);//鎽勫儚鏈篿d cam_mac + std::string str_imgName = appConfig.getStringProperty("cutPath"); if (str_imgName.back() != '/') { str_imgName.push_back('/'); } + str_imgName +=ip; + 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); diff --git a/QiaoJiaSystem/RapidStructureApp/TriggerElement.cpp b/QiaoJiaSystem/RapidStructureApp/TriggerElement.cpp index 6f0272d..11233ce 100644 --- a/QiaoJiaSystem/RapidStructureApp/TriggerElement.cpp +++ b/QiaoJiaSystem/RapidStructureApp/TriggerElement.cpp @@ -78,7 +78,13 @@ lastDown = 0; triggerType = DOWN; } +void TriggerElement::resetTriggerState() +{ + //state=false; + triggerState=false; + triggerTimes=0; +} void TriggerElement::timerFunc() { diff --git a/QiaoJiaSystem/RapidStructureApp/TriggerElement.h b/QiaoJiaSystem/RapidStructureApp/TriggerElement.h index ce6e32d..3c4627f 100644 --- a/QiaoJiaSystem/RapidStructureApp/TriggerElement.h +++ b/QiaoJiaSystem/RapidStructureApp/TriggerElement.h @@ -29,6 +29,8 @@ bool getTriggerState() const; + void resetTriggerState(); + private: bool state; bool triggerState; diff --git a/QiaoJiaSystem/StructureApp/AppPipeController.cpp b/QiaoJiaSystem/StructureApp/AppPipeController.cpp index 321f170..457c8db 100644 --- a/QiaoJiaSystem/StructureApp/AppPipeController.cpp +++ b/QiaoJiaSystem/StructureApp/AppPipeController.cpp @@ -195,9 +195,9 @@ mutex.lock(); cv::Mat imageTemp = videoCaptureElement.getImage(); - std::string strNewTime; - strNewTime = AppUtil::getTimeUSecString(); - + std::string strNewTime = AppUtil::getTimeUSecString();; + mutex.unlock(); +//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) { @@ -252,7 +252,7 @@ imageDrawElement.setImage(imageTemp); imageDrawElement.submit(); } - mutex.unlock(); + // if (bRecordVideoEnable) { // registerElement(triggerElement); // } @@ -440,12 +440,14 @@ { leftJudgment.setYoloObjects(yoloRpcElement.getLastScoreRects()); leftJudgment.setImage(yoloRpcElement.getImage()); + leftJudgment.submit(); } if(!rightJudgment.isBusy()) { rightJudgment.setYoloObjects(yoloRpcElement.getLastScoreRects()); rightJudgment.setImage(yoloRpcElement.getImage()); + rightJudgment.submit(); } }); diff --git a/QiaoJiaSystem/StructureApp/CMakeLists.txt b/QiaoJiaSystem/StructureApp/CMakeLists.txt index a06601a..393119d 100644 --- a/QiaoJiaSystem/StructureApp/CMakeLists.txt +++ b/QiaoJiaSystem/StructureApp/CMakeLists.txt @@ -17,6 +17,7 @@ HiredisTool.cpp PersonElement.cpp PerStaticElement.cpp + IntAreaCalcUtil.cpp TrackingTrigger.cpp FaceRpcElement.cpp diff --git a/QiaoJiaSystem/StructureApp/IntAreaCalcUtil.cpp b/QiaoJiaSystem/StructureApp/IntAreaCalcUtil.cpp new file mode 100644 index 0000000..e920d72 --- /dev/null +++ b/QiaoJiaSystem/StructureApp/IntAreaCalcUtil.cpp @@ -0,0 +1,2 @@ +#include "IntAreaCalcUtil.h" + diff --git a/QiaoJiaSystem/StructureApp/IntAreaCalcUtil.h b/QiaoJiaSystem/StructureApp/IntAreaCalcUtil.h new file mode 100644 index 0000000..5654be8 --- /dev/null +++ b/QiaoJiaSystem/StructureApp/IntAreaCalcUtil.h @@ -0,0 +1,238 @@ +#ifndef INTAREACALCUTIL_H +#define INTAREACALCUTIL_H +#include <iostream> +#include <vector> +#include <map> +using namespace std; +struct Point +{ + Point(){} + Point(int x1,int y1) + { + x=x1; + y=y1; + } + int x; + int y; +}; +class IntAreaCalcUtil +{ + + +public: +//鑻ョ偣a澶т簬鐐筨,鍗崇偣a鍦ㄧ偣b椤烘椂閽堟柟鍚�,杩斿洖true,鍚﹀垯杩斿洖false +static bool PointCmp(const Point &a,const Point &b,const Point ¢er) +{ + if (a.x >= 0 && b.x < 0) + return true; + if (a.x == 0 && b.x == 0) + return a.y > b.y; + //鍚戦噺OA鍜屽悜閲廜B鐨勫弶绉� + int det = (a.x - center.x) * (b.y - center.y) - (b.x - center.x) * (a.y - center.y); + if (det < 0) + return true; + if (det > 0) + return false; + //鍚戦噺OA鍜屽悜閲廜B鍏辩嚎锛屼互璺濈鍒ゆ柇澶у皬 + int d1 = (a.x - center.x) * (a.x - center.x) + (a.y - center.y) * (a.y - center.y); + int d2 = (b.x - center.x) * (b.x - center.y) + (b.y - center.y) * (b.y - center.y); + return d1 > d2; +} +static void ClockwiseSortPoints(std::vector<Point> &vPoints) +{ + //璁$畻閲嶅績 + Point center; + double x = 0,y = 0; + for (int i = 0;i < vPoints.size();i++) + { + x += vPoints[i].x; + y += vPoints[i].y; + } + center.x = (int)x/vPoints.size(); + center.y = (int)y/vPoints.size(); + + //鍐掓场鎺掑簭 + for(int i = 0;i < vPoints.size() - 1;i++) + { + for (int j = 0;j < vPoints.size() - i - 1;j++) + { + if (PointCmp(vPoints[j],vPoints[j+1],center)) + { + Point tmp = vPoints[j]; + vPoints[j] = vPoints[j + 1]; + vPoints[j + 1] = tmp; + } + } + } +} +// The function will return YES if the point x,y is inside the polygon, or +// NO if it is not. If the point is exactly on the edge of the polygon, +// then the function may return YES or NO. +static bool IsPointInPolygon(std::vector<Point> poly,Point pt) +{ + int i,j; + bool c = false; + for (i = 0,j = poly.size() - 1;i < poly.size();j = i++) + { + if ((((poly[i].y <= pt.y) && (pt.y < poly[j].y)) || + ((poly[j].y <= pt.y) && (pt.y < poly[i].y))) + && (pt.x < (poly[j].x - poly[i].x) * (pt.y - poly[i].y)/(poly[j].y - poly[i].y) + poly[i].x)) + { + c = !c; + } + } + return c; +} +//鎺掓枼瀹為獙 +static bool IsRectCross(const Point &p1,const Point &p2,const Point &q1,const Point &q2) +{ + bool ret = min(p1.x,p2.x) <= max(q1.x,q2.x) && + min(q1.x,q2.x) <= max(p1.x,p2.x) && + min(p1.y,p2.y) <= max(q1.y,q2.y) && + min(q1.y,q2.y) <= max(p1.y,p2.y); + return ret; +} +//璺ㄧ珛鍒ゆ柇 +static bool IsLineSegmentCross(const Point &pFirst1,const Point &pFirst2,const Point &pSecond1,const Point &pSecond2) +{ + long line1,line2; + line1 = pFirst1.x * (pSecond1.y - pFirst2.y) + + pFirst2.x * (pFirst1.y - pSecond1.y) + + pSecond1.x * (pFirst2.y - pFirst1.y); + line2 = pFirst1.x * (pSecond2.y - pFirst2.y) + + pFirst2.x * (pFirst1.y - pSecond2.y) + + pSecond2.x * (pFirst2.y - pFirst1.y); + if (((line1 ^ line2) >= 0) && !(line1 == 0 && line2 == 0)) + return false; + + line1 = pSecond1.x * (pFirst1.y - pSecond2.y) + + pSecond2.x * (pSecond1.y - pFirst1.y) + + pFirst1.x * (pSecond2.y - pSecond1.y); + line2 = pSecond1.x * (pFirst2.y - pSecond2.y) + + pSecond2.x * (pSecond1.y - pFirst2.y) + + pFirst2.x * (pSecond2.y - pSecond1.y); + if (((line1 ^ line2) >= 0) && !(line1 == 0 && line2 == 0)) + return false; + return true; +} + +static bool GetCrossPoint(const Point &p1,const Point &p2,const Point &q1,const Point &q2,long &x,long &y) +{ + if(IsRectCross(p1,p2,q1,q2)) + { + if (IsLineSegmentCross(p1,p2,q1,q2)) + { + //姹備氦鐐� + long tmpLeft,tmpRight; + tmpLeft = (q2.x - q1.x) * (p1.y - p2.y) - (p2.x - p1.x) * (q1.y - q2.y); + tmpRight = (p1.y - q1.y) * (p2.x - p1.x) * (q2.x - q1.x) + q1.x * (q2.y - q1.y) * (p2.x - p1.x) - p1.x * (p2.y - p1.y) * (q2.x - q1.x); + + x = (int)((double)tmpRight/(double)tmpLeft); + + tmpLeft = (p1.x - p2.x) * (q2.y - q1.y) - (p2.y - p1.y) * (q1.x - q2.x); + tmpRight = p2.y * (p1.x - p2.x) * (q2.y - q1.y) + (q2.x- p2.x) * (q2.y - q1.y) * (p1.y - p2.y) - q2.y * (q1.x - q2.x) * (p2.y - p1.y); + y = (int)((double)tmpRight/(double)tmpLeft); + return true; + } + } + return false; +} +static bool PolygonClip(const vector<Point> &poly1,const vector<Point> &poly2, std::vector<Point> &interPoly) +{ + if (poly1.size() < 3 || poly2.size() < 3) + { + return false; + } + + long x,y; + //璁$畻澶氳竟褰氦鐐箆ector<Point> poly1; + for (int i = 0;i < poly1.size();i++) + { + int poly1_next_idx = (i + 1) % poly1.size(); + for (int j = 0;j < poly2.size();j++) + { + int poly2_next_idx = (j + 1) % poly2.size(); + if (GetCrossPoint(poly1[i],poly1[poly1_next_idx], + poly2[j],poly2[poly2_next_idx], + x,y)) + { + if(x<0 || y<0) continue; + interPoly.push_back(Point(x,y)); + } + } + } + + //璁$畻澶氳竟褰㈠唴閮ㄧ偣 + for(int i = 0;i < poly1.size();i++) + { + if (IsPointInPolygon(poly2,poly1[i])) + { + interPoly.push_back(poly1[i]); + } + } + for (int i = 0;i < poly2.size();i++) + { + if (IsPointInPolygon(poly1,poly2[i])) + { + interPoly.push_back(poly2[i]); + } + } + + if(interPoly.size() <= 0) + return false; + + //鐐归泦鎺掑簭 + ClockwiseSortPoints(interPoly); + return true; +} +static float intAreaCalc(vector<Point> &vecPoly)//姹傝В澶氳竟褰㈢殑闈㈢Н(鐭ラ亾澶氳竟褰㈢殑椤剁偣锛屾寜椤烘椂閽堟垨鑰呴�嗘椂閽�) +{ + int i_count=vecPoly.size(); + // iCycle=0; + int area_temp=0; + for(int i=0;i<i_count;i++) + { + area_temp=area_temp+(vecPoly[i].x*vecPoly[(i+1) % i_count].y-vecPoly[(i+1) % i_count].x*vecPoly[i].y); + } + return abs(area_temp*100/2); +} + +//int main() +//{ +// vector<Point> poly1; +// poly1.push_back(Point(1,0)); +// poly1.push_back(Point(1,2)); +// poly1.push_back(Point(3,0)); +// // poly1.push_back(Point(1,2)); +// vector<Point> poly2; +//// poly2.push_back(Point(2,0)); +//// poly2.push_back(Point(7,0)); +//// poly2.push_back(Point(7,5)); +//// poly2.push_back(Point(2,5)); +// poly2.push_back(Point(0,0)); +// poly2.push_back(Point(4,0)); +// poly2.push_back(Point(4,4)); +// poly2.push_back(Point(0,4)); +// vector<Point> poly3; +// PolygonClip(poly1,poly2,poly3); +// float inter = intAreaCalc(poly3); +// float total = intAreaCalc(poly2); +// int perset1 = (int)(inter / total * 100); +// if(ALARM_PERCENT <= perset) +// { + +// } + + + + +// for(int i=0;i<poly3.size();++i) +// { + +// } +// return 0; +//} + +}; + +#endif // INTAREACALCUTIL_H diff --git a/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.cpp b/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.cpp index 9c6cda9..bcf0518 100644 --- a/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.cpp +++ b/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.cpp @@ -10,7 +10,7 @@ #include <basic/util/app/AppPreference.hpp> JudgmentRetrogradeTool::JudgmentRetrogradeTool(const SdkRule &rule) : - m_triggerElement(rule.nTriggerDelay * 8, 0), + m_triggerElement(0, 0), m_sdkRule(rule), pManagerEsDB(nullptr) { @@ -79,14 +79,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 +113,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; } @@ -143,6 +138,41 @@ } 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(); + std::string imgUrl = uploadImgToFdfs(t_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 +184,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,30 +203,7 @@ } } - 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); - - - break; - } else { - m_triggerElement.setState(false); - - } - m_triggerElement.triggerOnce(); - if(m_triggerElement.getTriggerState()) - { - 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); - } - } } @@ -203,7 +215,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); diff --git a/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.h b/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.h index 9988245..e3cd93f 100644 --- a/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.h +++ b/QiaoJiaSystem/StructureApp/JudgmentRetrogradeTool.h @@ -123,7 +123,8 @@ std::map<long, std::list<float>> m_mapPerDirection; //璺熻釜id,閫嗚鐘舵�� - std::map<long, bool> m_mapPerRet; + // std::map<long, bool> m_mapPerRet; + std::map<long, int> m_mapPerRet; QPolygon m_polygon; diff --git a/QiaoJiaSystem/StructureApp/PerStaticElement.cpp b/QiaoJiaSystem/StructureApp/PerStaticElement.cpp index 4877fbe..a8156c3 100644 --- a/QiaoJiaSystem/StructureApp/PerStaticElement.cpp +++ b/QiaoJiaSystem/StructureApp/PerStaticElement.cpp @@ -80,7 +80,7 @@ { if(ele.id==obj.id) { - if((obj.rect&ele.rect).area()>ele.rect.area()*0.8) + if((obj.rect&ele.rect).area()>ele.rect.area()*m_sdkRule.fSensitivity) { //not moving obj.isMove = true; @@ -183,7 +183,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); diff --git a/QiaoJiaSystem/StructureApp/PerimeterElement.cpp b/QiaoJiaSystem/StructureApp/PerimeterElement.cpp index 5e480ee..b605b07 100644 --- a/QiaoJiaSystem/StructureApp/PerimeterElement.cpp +++ b/QiaoJiaSystem/StructureApp/PerimeterElement.cpp @@ -13,6 +13,7 @@ #include <uuid/uuid.h> #include <jsoncpp/json/json.h> +#define ALARM_PERCENT (10) //10% PerimeterElement::PerimeterElement(const SdkRule &rule) : m_sdkRule(rule), PipeElement(true), @@ -41,7 +42,7 @@ void PerimeterElement::threadFunc() { - // ClockTimer ct("PerimeterElement::threadFunc"); + //ClockTimer ct("PerimeterElement::threadFunc"); if (!isInWeek(m_sdkRule.weekRuleVec)) return; int num = 0; @@ -57,41 +58,72 @@ QRect rect(obj.rect.x, obj.rect.y, obj.rect.width, obj.rect.height); QPoint center = rect.center(); - if (mPolygon.containsPoint(center, Qt::OddEvenFill) || !m_bIsMask) { - m_recVec.push_back(obj.rect); - if (picDate.empty()) { - picDate = obj.properties["time"]; - // DBG("picDate="<<picDate); + if (picDate.empty()) { + picDate = obj.properties["time"]; + // DBG("picDate="<<picDate); + + } + if (m_sdkRule.nSdkType == PerimeterSdk) + { + + if(m_bIsMask) + { + std::vector<Point> poly2; + std::vector<Point> interPoly; + poly2.push_back(Point(rect.x(),rect.y())); + poly2.push_back(Point(rect.x()+rect.width(),rect.y())); + poly2.push_back(Point(rect.x()+rect.width(),rect.y()+rect.height())); + poly2.push_back(Point(rect.x(),rect.y()+rect.height())); + IntAreaCalcUtil::PolygonClip(poly1,poly2,interPoly); + float inter = IntAreaCalcUtil::intAreaCalc(interPoly); + float total1 =IntAreaCalcUtil::intAreaCalc(poly1); + float total2 = IntAreaCalcUtil::intAreaCalc(poly2); + int per1 = (int)(inter / total1 * 100); + int per2 = (int)(inter / total2 * 100); + int per=std::max(per1,per2); + + if(ALARM_PERCENT <= per) + { + //DBG("per 1="<<per1<<" per2="<<per2<<" per="<<per); + m_recVec.push_back(obj.rect); + num++; + } } - num++; - } - else + else if (mPolygon.containsPoint(center, Qt::OddEvenFill) || !m_bIsMask) { - // DBG("id="<< obj.properties["id"]<<" no containts x="<<rect.center().x()<<" y="<<rect.center().y()); + m_recVec.push_back(obj.rect); + + + num++; } + } switch (m_sdkRule.nSdkType) { case PerimeterSdk: - state = num > 0 ; + //state = num > 0 ; + state =( num !=mRealNum); + // DBG("num="<<num<< "time="<< picDate); break; case CrowdSdk: - state = num > m_sdkRule.nAlarmNumLowerLimit ; + state = num > m_sdkRule.nAlarmNumLowerLimit && num !=mRealNum; break; case PerHubSdk: - state = num > m_sdkRule.nAlarmNumLowerLimit && num < m_sdkRule.nAlarmNumUpperLimit ; -// if(m_sdkRule.nAlarmNumLowerLimit>0) + state = num > m_sdkRule.nAlarmNumLowerLimit && num < m_sdkRule.nAlarmNumUpperLimit && num !=mRealNum; + + +// if(m_sdkRule.nAlarmNumLowerLimit>=0) // { -// if( m_sdkRule.nAlarmNumUpperLimit>m_sdkRule.nAlarmNumLowerLimit+1) +// if( m_sdkRule.nAlarmNumUp2019-01-16 09:49:57perLimit>m_sdkRule.nAlarmNumLowerLimit+1) // { // m_triggerElement.setState(num>m_sdkRule.nAlarmNumLowerLimit && num<m_sdkRule.nAlarmNumUpperLimit); @@ -122,33 +154,43 @@ m_triggerElement.setState(state); m_triggerElement.triggerOnce(); - // DBG("imgUrl="<<imgUrl); - if (m_triggerElement.getTriggerState() && num!=mRealNum) + if (m_triggerElement.getTriggerState() ) { - - cv::Mat t_image = image(CutMask()).clone(); - if(t_image.empty()) - { - if(image.empty()) + if(num > 0) { + cv::Mat t_image = image(CutMask()).clone(); + if(t_image.empty()) { - DBG("image empty"); + DBG("t_image empty"); + return; } - DBG("t_image empty"); - return; + std::string imgUrl = uploadImgToFdfs(t_image); + saveInfoToEs(imgUrl, picDate); } - std::string imgUrl = uploadImgToFdfs(t_image); - saveInfoToEs(imgUrl, picDate); DBG("num=" << num << " lastnum=" << mRealNum); mRealNum = num; } -// if(state) -//DBG("mRealNum=" << mRealNum <<"m_triggerElement.getTriggerState()="<<m_triggerElement.getTriggerState()); + +// if (m_triggerElement.getTriggerState() && num!=mRealNum) +// { + +// cv::Mat t_image = image(CutMask()).clone(); +// if(t_image.empty()) +// { +// DBG("t_image empty"); +// return; +// } +// std::string imgUrl = uploadImgToFdfs(t_image); +// saveInfoToEs(imgUrl, picDate); +// DBG("num=" << num << " lastnum=" << mRealNum); +// mRealNum = num; +// } - if(!state) - { - mRealNum = num; - } + +// if(!state) +// { +// mRealNum = num; +// } // DBG("m_sdkRule.nSdkType="<<m_sdkRule.nSdkType<<" num="<<num); @@ -199,8 +241,16 @@ QJsonObject obj = jsonValue.toObject(); int x = obj.value("x").toDouble() * 4; int y = obj.value("y").toDouble() * 4; + if(m_sdkRule.nSdkType == PerimeterSdk) + { + poly1.push_back(Point(x,y)); + } + else + { + mPolygon << (QPoint(x, y)); + } - mPolygon << (QPoint(x, y)); + } } diff --git a/QiaoJiaSystem/StructureApp/PerimeterElement.h b/QiaoJiaSystem/StructureApp/PerimeterElement.h index b7a4dfd..3e6e35e 100644 --- a/QiaoJiaSystem/StructureApp/PerimeterElement.h +++ b/QiaoJiaSystem/StructureApp/PerimeterElement.h @@ -11,6 +11,7 @@ #include <basic/util/fastdfs/FastFds.hpp> #include "DBStruct.h" #include <basic/db/Elasticsearch/EsDBTool.h> +#include "IntAreaCalcUtil.h" class PerimeterElement : public basic::PipeElement { public: @@ -83,9 +84,12 @@ int npts; - vector<cv::Rect> m_recVec; + std::vector<cv::Rect> m_recVec; bool m_bIsMask; + std::vector<Point> poly1; + + }; #endif // PAELEMENT_H diff --git a/QiaoJiaSystem/StructureApp/YoloRpcElement.cpp b/QiaoJiaSystem/StructureApp/YoloRpcElement.cpp index a56a7e7..31a2e2f 100644 --- a/QiaoJiaSystem/StructureApp/YoloRpcElement.cpp +++ b/QiaoJiaSystem/StructureApp/YoloRpcElement.cpp @@ -64,7 +64,7 @@ void YoloRpcElement::threadFunc() { - // ClockTimer ct("YoloRpcElement::threadFunc"); + // ClockTimer ct("YoloRpcElement::threadFunc"); triggerScoredRects.clear(); try { auto server = rpcClient.getServer(); @@ -79,17 +79,13 @@ { ERR(e.what()) } - int size=objs.size(); - if(size>30) - { +// int size=objs.size(); +// if(size>30) +// { -// cv::imshow("image", image); - -// cv::waitKey(); - - DBG("size="<<size); - return; - } +// DBG("size="<<size); +// return; +// } for (auto &obj: objs) { diff --git a/QiaoJiaSystem/VideoAnalysFromHC/CMakeLists.txt b/QiaoJiaSystem/VideoAnalysFromHC/CMakeLists.txt index d4a83d9..a006a46 100644 --- a/QiaoJiaSystem/VideoAnalysFromHC/CMakeLists.txt +++ b/QiaoJiaSystem/VideoAnalysFromHC/CMakeLists.txt @@ -59,6 +59,7 @@ ../StructureApp/HiredisTool.cpp ../StructureApp/PersonElement.cpp ../StructureApp/PerStaticElement.cpp + ../StructureApp/IntAreaCalcUtil.cpp ../YoloServer/rpc/YoloServer.cpp ../FaceDetectServer/rpc/FaceServer.cpp diff --git a/QiaoJiaSystem/VideoAnalysFromHC/RtspAnalysElement.cpp b/QiaoJiaSystem/VideoAnalysFromHC/RtspAnalysElement.cpp index 828dc70..25b961b 100644 --- a/QiaoJiaSystem/VideoAnalysFromHC/RtspAnalysElement.cpp +++ b/QiaoJiaSystem/VideoAnalysFromHC/RtspAnalysElement.cpp @@ -85,20 +85,29 @@ rule.second.strAddr = item.str_addr; rule.second.weekRuleVec = m_lDBTool->searchCameraWeekRuleByCamId(item.str_cam_dev_id, rule.first); - if(rule.second.nSdkType == FaceSdk) continue; + if(rule.second.nSdkType == PerStaticSdk) + { + float temp=1-(float)(rule.second.nThreshold)/100; + rule.second.fSensitivity=(75+25*temp)/100; - if (rule.second.nThreshold < 5 ) - { - rule.second.fSensitivity=0.95; } - else if(rule.second.nThreshold > 95) + else if(rule.second.nSdkType != FaceSdk) { - rule.second.fSensitivity=0.05; + float temp=1-(float)(rule.second.nThreshold)/100; + rule.second.fSensitivity=(5+90*temp)/100; } - else - { - rule.second.fSensitivity = 1-(float) (rule.second.nThreshold) / 100; - } +// if (rule.second.nThreshold < 5 ) +// { +// rule.second.fSensitivity=0.95; +// } +// else if(rule.second.nThreshold > 95) +// { +// rule.second.fSensitivity=0.05; +// } +// else +// { +// rule.second.fSensitivity = 1-(float) (rule.second.nThreshold) / 100; +// } DBG("fSensitivity" << rule.second.fSensitivity); } diff --git a/QiaoJiaSystem/VideoServer/QiaoJia/DB/LDBTool.cpp b/QiaoJiaSystem/VideoServer/QiaoJia/DB/LDBTool.cpp index acabafb..93ca3ab 100644 --- a/QiaoJiaSystem/VideoServer/QiaoJia/DB/LDBTool.cpp +++ b/QiaoJiaSystem/VideoServer/QiaoJia/DB/LDBTool.cpp @@ -356,11 +356,23 @@ pModel_cam.setEditStrategy(QSqlTableModel::OnManualSubmit);//OnManualSubmit OnFieldChange pModel_cam.select(); +// QSqlTableModel pModel_sdk(NULL, m_db); +// pModel_sdk.setTable("cam_sdk"); +// pModel_sdk.setFilter(QObject::tr("cam_dev_id = '%1'").arg(strCamId)); +// pModel_sdk.setEditStrategy(QSqlTableModel::OnManualSubmit);//OnManualSubmit OnFieldChange +// pModel_sdk.select(); + QSqlTableModel pModel_sdk(NULL, m_db); - pModel_sdk.setTable("cam_sdk"); - pModel_sdk.setFilter(QObject::tr("cam_dev_id = '%1'").arg(strCamId)); + pModel_sdk.setTable("sdk_rule"); + pModel_sdk.setFilter(QObject::tr("cam_id = '%1'").arg(strCamId)); pModel_sdk.setEditStrategy(QSqlTableModel::OnManualSubmit);//OnManualSubmit OnFieldChange pModel_sdk.select(); + + QSqlTableModel pModel_week(NULL, m_db); + pModel_week.setTable("rule_week"); + pModel_week.setFilter(QObject::tr("camera_id = '%1'").arg(strCamId)); + pModel_week.setEditStrategy(QSqlTableModel::OnManualSubmit);//OnManualSubmit OnFieldChange + pModel_week.select(); int rowCount_cam = pModel_cam.rowCount(); if (rowCount_cam >= 1) { @@ -376,17 +388,25 @@ } } + int rowCount_week = pModel_week.rowCount(); + if (rowCount_week >= 1) { + for (int i = 0; i < rowCount_week; i++) { + pModel_week.removeRow(i);//TODO + } + } + m_db.transaction();//寮�濮嬩簨鍔℃搷浣� if (pModel_cam.submitAll() && \ - pModel_sdk.submitAll()) { + pModel_sdk.submitAll() && pModel_week.submitAll()) { m_db.commit();//鎻愪氦 return true; } else { m_db.rollback();//鍥炴粴 ERR("deleteLDeviceTable err ,Database Error: " \ << pModel_cam.lastError().text().toStdString() \ - << pModel_sdk.lastError().text().toStdString()); + << pModel_sdk.lastError().text().toStdString() \ + << pModel_week.lastError().text().toStdString() ); // QMessageBox::warning(NULL,QObject::tr("deleteLDeviceTable"),QObject::tr("Database Error: %1").arg(pModel.lastError().text())); return false; } diff --git a/QiaoJiaSystem/YoloServer/YoloDetectServerI.cpp b/QiaoJiaSystem/YoloServer/YoloDetectServerI.cpp index b270ed1..33ebe72 100644 --- a/QiaoJiaSystem/YoloServer/YoloDetectServerI.cpp +++ b/QiaoJiaSystem/YoloServer/YoloDetectServerI.cpp @@ -70,6 +70,7 @@ int nboxes = 0; detection *dets = get_network_boxes(m_net, im.w, im.h, m_thresh, m_hier_thresh, 0, 1, &nboxes); if (nboxes > 30) { + DBG("nboxes="<<nboxes); return objInfos; } if (m_nms) do_nms_sort(dets, nboxes, l.classes, m_nms); diff --git a/QiaoJiaSystem/YoloServer/main.cpp b/QiaoJiaSystem/YoloServer/main.cpp index a69beb9..a44a900 100644 --- a/QiaoJiaSystem/YoloServer/main.cpp +++ b/QiaoJiaSystem/YoloServer/main.cpp @@ -24,14 +24,14 @@ // adapter->activate(); // ich->waitForShutdown(); - if (argc < 3) { - ERR("argc error"); - return -1; - } +// if (argc < 3) { +// ERR("argc error"); +// return -1; +// } - int gpuindex = atoi(argv[1]); - int poolNum = atoi(argv[2]); - int portNum = atoi(argv[3]); + int gpuindex = 1; + int poolNum = 1; + int portNum = 10003; appPref.setIntData("gpu.index", gpuindex); appPref.setFloatData("thresh.detect", 0.7); diff --git a/QiaoJiaSystem/build/DataWebServer b/QiaoJiaSystem/build/DataWebServer index 3b246c1..e760142 100755 --- a/QiaoJiaSystem/build/DataWebServer +++ b/QiaoJiaSystem/build/DataWebServer Binary files differ diff --git a/QiaoJiaSystem/build/EncodeServer b/QiaoJiaSystem/build/EncodeServer index b289e10..ea46651 100755 --- a/QiaoJiaSystem/build/EncodeServer +++ b/QiaoJiaSystem/build/EncodeServer Binary files differ diff --git a/QiaoJiaSystem/build/FaceSearchServer b/QiaoJiaSystem/build/FaceSearchServer index b6c3698..3953b34 100755 --- a/QiaoJiaSystem/build/FaceSearchServer +++ b/QiaoJiaSystem/build/FaceSearchServer Binary files differ diff --git a/QiaoJiaSystem/build/RapidStructureApp b/QiaoJiaSystem/build/RapidStructureApp index 9a972e5..8e421e7 100755 --- a/QiaoJiaSystem/build/RapidStructureApp +++ b/QiaoJiaSystem/build/RapidStructureApp Binary files differ diff --git a/QiaoJiaSystem/build/RapidStructureAppRtsp b/QiaoJiaSystem/build/RapidStructureAppRtsp index 1e5921c..83c8c8e 100755 --- a/QiaoJiaSystem/build/RapidStructureAppRtsp +++ b/QiaoJiaSystem/build/RapidStructureAppRtsp Binary files differ diff --git a/QiaoJiaSystem/build/RecordVideo b/QiaoJiaSystem/build/RecordVideo index 62d159a..f1c34cc 100755 --- a/QiaoJiaSystem/build/RecordVideo +++ b/QiaoJiaSystem/build/RecordVideo Binary files differ diff --git a/QiaoJiaSystem/build/StructureApp b/QiaoJiaSystem/build/StructureApp index fe02b93..a8e0934 100755 --- a/QiaoJiaSystem/build/StructureApp +++ b/QiaoJiaSystem/build/StructureApp Binary files differ diff --git a/QiaoJiaSystem/build/VideoAnalysFromHC b/QiaoJiaSystem/build/VideoAnalysFromHC index 51db0de..9e1015b 100755 --- a/QiaoJiaSystem/build/VideoAnalysFromHC +++ b/QiaoJiaSystem/build/VideoAnalysFromHC Binary files differ diff --git a/QiaoJiaSystem/build/YoloDetectClientTest b/QiaoJiaSystem/build/YoloDetectClientTest new file mode 100755 index 0000000..7d376dd --- /dev/null +++ b/QiaoJiaSystem/build/YoloDetectClientTest Binary files differ diff --git a/QiaoJiaSystem/build/YoloServer b/QiaoJiaSystem/build/YoloServer old mode 100644 new mode 100755 index 5f42776..662587b --- a/QiaoJiaSystem/build/YoloServer +++ b/QiaoJiaSystem/build/YoloServer Binary files differ diff --git a/QiaoJiaSystem/build/config.db b/QiaoJiaSystem/build/config.db index 32de39c..bb0bacb 100755 --- a/QiaoJiaSystem/build/config.db +++ b/QiaoJiaSystem/build/config.db Binary files differ diff --git a/QiaoJiaSystem/build/scpToSer.sh b/QiaoJiaSystem/build/scpToSer.sh index cb570db..fda9895 100644 --- a/QiaoJiaSystem/build/scpToSer.sh +++ b/QiaoJiaSystem/build/scpToSer.sh @@ -9,7 +9,7 @@ echo $1 des_pass=123 expect -c " -# spawn scp -P44100 ${CUR_PATH}"/"$1 dell@58.118.225.79:/home/dell/Apps/QiaoJiaSystem/build +# spawn scp -P41100 ${CUR_PATH}"/"$1 basic@58.118.225.79:/home/basic/Apps/QiaoJiaSystem/build spawn scp ${CUR_PATH}"/"$1 basic@192.168.1.203:/home/basic/Apps/QiaoJiaSystem/build expect \"password:\" send \"${des_pass}\r\" -- Gitblit v1.8.0