| | |
| | | // |
| | | // Created by basic on 18-8-24. |
| | | // |
| | | |
| | | #include "JudgmentRetrogradeTool.h" |
| | | #include <basic/util/opencv/CvMath.hpp> |
| | | #include <QtCore/QDebug> |
| | | #include <basic/db/Elasticsearch/EsDBTool.h> |
| | | #include <basic/util/opencv/CvUtil.h> |
| | | #include <uuid/uuid.h> |
| | | #include <basic/util/app/AppPreference.hpp> |
| | | |
| | | JudgmentRetrogradeTool::JudgmentRetrogradeTool(): |
| | | JudgmentRetrogradeTool::JudgmentRetrogradeTool(const SdkRule &rule) : |
| | | TimerElement(1000), |
| | | m_triggerElement(0,50) |
| | | { |
| | | |
| | | m_triggerElement(0, rule.nTriggerDelay * 1000 * 1000), |
| | | m_sdkRule(rule), |
| | | pManagerEsDB(nullptr) { |
| | | pManagerEsDB = new EsDBTool(appPref.getStringData("ipAdd"), appPref.getIntData("ipPort")); |
| | | } |
| | | |
| | | JudgmentRetrogradeTool::~JudgmentRetrogradeTool() { |
| | | |
| | | if (pManagerEsDB) { |
| | | delete pManagerEsDB; |
| | | pManagerEsDB = nullptr; |
| | | } |
| | | } |
| | | |
| | | bool JudgmentRetrogradeTool::init(QString area,QString line) { |
| | | |
| | | //#todo string ->json |
| | | QJsonArray arrayAreas = getJsonArrayFromQString(area); |
| | | if(arrayAreas.isEmpty()) |
| | | { |
| | | if (arrayAreas.isEmpty()) { |
| | | return false;//do not detect |
| | | } |
| | | QVector<QPoint> vec; |
| | | for(int i = 0;i < arrayAreas.size();++i){ |
| | | QJsonValue jsonValue = arrayAreas[i]; |
| | | QJsonObject obj = jsonValue.toObject(); |
| | | int x = obj.value("x").toInt()*2 ; |
| | | int y = obj.value("y").toInt()*2 ; |
| | | int x = obj.value("x").toDouble() * 4; |
| | | int y = obj.value("y").toDouble() * 4; |
| | | vec.push_back(QPoint(x,y)); |
| | | } |
| | | |
| | |
| | | if(arrayLine.size() == 2){ |
| | | QJsonValue jsonValue = arrayLine[0]; |
| | | QJsonObject obj = jsonValue.toObject(); |
| | | start.x = obj.value("x").toInt() ; |
| | | start.y = obj.value("y").toInt() ; |
| | | start.x = obj.value("x").toDouble(); |
| | | start.y = obj.value("y").toDouble(); |
| | | |
| | | |
| | | QJsonValue jsonValue2 = arrayLine[1]; |
| | | QJsonObject obj2 = jsonValue2.toObject(); |
| | | end.x = obj2.value("x").toInt() ; |
| | | end.y = obj2.value("y").toInt() ; |
| | | end.x = obj2.value("x").toDouble(); |
| | | end.y = obj2.value("y").toDouble(); |
| | | |
| | | }else{ |
| | | return false; |
| | |
| | | return true; |
| | | } |
| | | |
| | | void JudgmentRetrogradeTool::setYoloObjects(std::vector<ScoredRect> value) |
| | | { |
| | | 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); |
| | | } |
| | | } |
| | |
| | | if(m_polygon.containsPoint(center,Qt::OddEvenFill)){ |
| | | temp.push_back(JRTOOL::low_filter(temp.back(), getTheta(m_UpBaseLine, tt))); |
| | | //DBG("ID="<<id<<" left getTheta="<<getTheta(m_DownBaseLine, tt)); |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | temp.clear(); |
| | | } |
| | | listCache.clear(); |
| | |
| | | return JRTOOL::getAngelOfTwoVector(directionVectorPoint, point); |
| | | } |
| | | |
| | | void JudgmentRetrogradeTool::timerFunc() |
| | | { |
| | | void JudgmentRetrogradeTool::timerFunc() { |
| | | func(); |
| | | fireConnectors(); |
| | | } |
| | |
| | | } |
| | | // DBG("id="<<item.first<<" a="<<a<<" b="<<b); |
| | | bool ret = a >= b ? true : false; |
| | | m_mapPerRet[item.first] = ret; |
| | | if (!ret) { |
| | | m_mapPerRet.insert(std::make_pair(item.first, false)); |
| | | // m_mapPerRet[item.first] = false; |
| | | |
| | | } |
| | | |
| | | |
| | | if (temp.size() > 9) { |
| | | temp.pop_front(); |
| | | } |
| | |
| | | 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 |
| | | { |
| | | } else { |
| | | m_triggerElement.setState(false); |
| | | |
| | | } |
| | |
| | | m_triggerElement.triggerOnce(); |
| | | } |
| | | |
| | | QJsonArray JudgmentRetrogradeTool::getJsonArrayFromQString(const QString strJson) |
| | | { |
| | | std::string JudgmentRetrogradeTool::uploadImgToFdfs(cv::Mat &image) { |
| | | std::string strImgUrl = "http://"; |
| | | if (fdfsClient != nullptr && fdfsClient->fastFds != nullptr) { |
| | | fdfsClient->rwLock.rdlock(); |
| | | std::vector<unsigned char> buffer; |
| | | CvUtil::cvMat2Buffer(image, buffer); |
| | | std::string strImgUrlTmp = ""; |
| | | fdfsClient->fastFds->uploadFile(buffer, strImgUrlTmp, "jpg"); |
| | | strImgUrl.append(fdfsClient->fastFds->getIp() + "/" + strImgUrlTmp); |
| | | strImgUrl.clear(); |
| | | strImgUrl = strImgUrlTmp; |
| | | // strImgUrl.append("/").append(strImgUrlTmp); |
| | | fdfsClient->rwLock.unlock(); |
| | | } |
| | | return strImgUrl; |
| | | } |
| | | |
| | | bool JudgmentRetrogradeTool::saveInfoToEs(const std::string &imgUrl, const ScoredRect &obj) { |
| | | |
| | | |
| | | string str_uuid; |
| | | uuid_t t_uuid; |
| | | char str[36]; |
| | | uuid_generate(t_uuid); |
| | | uuid_unparse(t_uuid, str); |
| | | str_uuid = str; |
| | | |
| | | |
| | | Json::Value t_json; |
| | | t_json["Id"] = str_uuid; //主键 |
| | | //#todo |
| | | |
| | | t_json["videoReqNum"] = m_sdkRule.strCamId.toStdString(); |
| | | 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["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["Age"] ="wait todo"; |
| | | t_json["picDate"] = obj.properties["time"]; // 抓拍时间,必须有 |
| | | t_json["picLocalUrl"] = "wait todo"; // 本地路径 |
| | | t_json["isDelete"] = "1";//默认1 ,0无效 1有效 |
| | | |
| | | t_json["likePer"] = obj.score; // 相似值 |
| | | |
| | | t_json["BaseName"] = "wait todo";// 地库名称 |
| | | |
| | | 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["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");//当前服务器IP地址 |
| | | t_json["ack_alarm"] = m_triggerElement.getTriggerState() ? "0" : ""; // que ren shi fou bao jing |
| | | t_json["cluster_id"] = "wait todo"; // ji qun id |
| | | |
| | | bool retface = false; |
| | | if (pManagerEsDB) |
| | | retface = pManagerEsDB->insertData("personaction", "perVideoAction", t_json.toStyledString(), str_uuid); |
| | | |
| | | if (retface) { |
| | | INFO("perVideoAction db success"); |
| | | } else { |
| | | ERR("personaction db fail"); |
| | | } |
| | | } |
| | | |
| | | bool JudgmentRetrogradeTool::isInWeek(const std::vector<LActRuleWeekRecord> &ruleWeek) { |
| | | |
| | | int nWeek = QDate::currentDate().dayOfWeek(); |
| | | for (int i = 0; i < ruleWeek.size(); ++i) { |
| | | if (ruleWeek[i].m_nType == nWeek) { |
| | | QString strCurrent = QDateTime::currentDateTime().toString("hh:mm"); |
| | | if (strCurrent >= ruleWeek[i].m_strBegin && strCurrent <= ruleWeek[i].m_strEnd) { |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | QJsonArray JudgmentRetrogradeTool::getJsonArrayFromQString(const QString strJson) { |
| | | QJsonDocument jsonDocument = QJsonDocument::fromJson(strJson.toLocal8Bit()); |
| | | if( jsonDocument.isNull() ){ |
| | | qDebug()<< "please check the string"<< strJson.toLocal8Bit(); |
| | |
| | | return jsonArray; |
| | | } |
| | | |
| | | void JudgmentRetrogradeTool::setUpDetectionArea() |
| | | { |
| | | void JudgmentRetrogradeTool::setUpDetectionArea() { |
| | | |
| | | } |
| | | void JudgmentRetrogradeTool::setDownDetectionArea() |
| | | { |
| | | |
| | | void JudgmentRetrogradeTool::setDownDetectionArea() { |
| | | |
| | | } |
| | | |
| | | bool JudgmentRetrogradeTool::getTriggerState() const { |
| | | return m_triggerElement.getTriggerState(); |
| | | } |
| | | |
| | | void JudgmentRetrogradeTool::setImage(const cv::Mat &value) { |
| | | value.copyTo(image); |
| | | } |