From c56015c5c73861b5f794cac48064d0394f8fd37d Mon Sep 17 00:00:00 2001 From: pansen <pansen626@sina.com> Date: 星期二, 02 四月 2019 15:48:39 +0800 Subject: [PATCH] 对抓拍记录的picMaxUrl字段赋值(大图路径) --- QiaoJiaSystem/StructureApp/AppPipeController.cpp | 66 ++++------ QiaoJiaSystem/StructureApp/FaceExtractElement.h | 8 + QiaoJiaSystem/StructureApp/FaceExtractElement.cpp | 277 ++++++++++++++++++++++++--------------------- 3 files changed, 183 insertions(+), 168 deletions(-) diff --git a/QiaoJiaSystem/StructureApp/AppPipeController.cpp b/QiaoJiaSystem/StructureApp/AppPipeController.cpp index 710118b..68383b4 100644 --- a/QiaoJiaSystem/StructureApp/AppPipeController.cpp +++ b/QiaoJiaSystem/StructureApp/AppPipeController.cpp @@ -19,7 +19,7 @@ //} AppPipeController::AppPipeController(std::string folderPath, const SdkRuleMap &ruleMap) : - m_rpcClient("RtspAnalysServer", "127.0.0.1",appPref.getIntData("RpcServerPort"),"tcp"), + m_rpcClient("RtspAnalysServer", "127.0.0.1", appPref.getIntData("RpcServerPort"), "tcp"), videoCaptureElement("filePath", 25, -1, appPref.getLongData("gpu.index")), // videoCaptureElement(40), m_index(0), @@ -33,8 +33,7 @@ // recordVideoElement(-1, ""), bRecordVideoEnable(false), - m_bSetWH(false) -{ + m_bSetWH(false) { init(); @@ -70,7 +69,7 @@ // intKeepRight(); //} AppPipeController::AppPipeController(std::string camId, const SdkRuleMap &ruleMap, bool RecordVideoEnable) : - m_rpcClient("RtspAnalysServer", "127.0.0.1",appPref.getIntData("RpcServerPort"),"tcp"), + m_rpcClient("RtspAnalysServer", "127.0.0.1", appPref.getIntData("RpcServerPort"), "tcp"), videoCaptureElement(appPref.getStringData(camId + "rtsp"), 25, 3000, appPref.getLongData("gpu.index")), // videoCaptureElement(40), m_index(0), @@ -90,9 +89,7 @@ rightJudgment(ruleMap[KeepRightSdk]), bRecordVideoEnable(RecordVideoEnable), m_sdkRuleMap(ruleMap), - m_bSetWH(false) - - { + m_bSetWH(false) { DBG("camId" << camId); init(); initPerimeter(); @@ -229,6 +226,7 @@ "perStaticElement: "<<perStaticElement.getTriggerState()); }*/ } + void AppPipeController::init() { unsigned char ip_old[15] = {0}; @@ -258,30 +256,27 @@ videoCaptureElement.registerConnector([&] { std::string imgKey; - m_hiredisTool.listRpop(m_camId,imgKey); - if(imgKey.empty()) - { - ERR("CamId "<<m_camId<<" No ImgKey"); + m_hiredisTool.listRpop(m_camId, imgKey); + if (imgKey.empty()) { + ERR("CamId " << m_camId << " No ImgKey"); return; } cv::Mat imageTemp; - m_hiredisTool.getKeyImage(imgKey,imageTemp); - if(!m_bSetWH) - { - INFO("SetWidth:"<<imageTemp.cols<<" Height:"<<imageTemp.rows); - appPref.setIntData(m_camId+"width",imageTemp.cols); - appPref.setIntData(m_camId+"height",imageTemp.rows); - m_bSetWH=true; + m_hiredisTool.getKeyImage(imgKey, imageTemp); + if (!m_bSetWH) { + INFO("SetWidth:" << imageTemp.cols << " Height:" << imageTemp.rows); + appPref.setIntData(m_camId + "width", imageTemp.cols); + appPref.setIntData(m_camId + "height", imageTemp.rows); + m_bSetWH = true; } m_hiredisTool.delKey(imgKey); - if(imageTemp.empty()) - { - ERR("No Image Data In: "<<m_camId<<" ImgKey:"<<imgKey); + if (imageTemp.empty()) { + ERR("No Image Data In: " << m_camId << " ImgKey:" << imgKey); return; } - std::string strNewTime = AppUtil::getTimeUSecString(); + std::string strNewTime = AppUtil::getTimeUSecString(); ImageName_s_t imgSt = ImageName_s_t::fromString(imgKey); @@ -289,8 +284,8 @@ if (!faceRpcElement.isBusy()) { //#todo faceRpcElement.setProperty("time", strNewTime); - faceRpcElement.setProperty("imgKey",imgKey); - INFO("Write To FaceRPC ES time:"<<strNewTime<< " ImgKey: "<<imgKey); + faceRpcElement.setProperty("imgKey", imgKey); + INFO("Write To FaceRPC ES time:" << strNewTime << " ImgKey: " << imgKey); faceRpcElement.setImage(imageTemp); faceRpcElement.submit(); } @@ -298,8 +293,8 @@ if (!yoloRpcElement.isBusy()) { //#todo yoloRpcElement.setProperty("time", strNewTime); - yoloRpcElement.setProperty("imgKey",imgKey); - INFO("Write To YoloES time:"<<strNewTime<< " ImgKey: "<<imgKey); + yoloRpcElement.setProperty("imgKey", imgKey); + INFO("Write To YoloES time:" << strNewTime << " ImgKey: " << imgKey); yoloRpcElement.setImage(imageTemp); yoloRpcElement.submit(); } @@ -385,7 +380,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()); } }); @@ -398,8 +393,7 @@ registerElement(faceRpcElement); registerElement(faceExtractElement); } - if(appPref.getIntData("show.image") == 1) - { + if (appPref.getIntData("show.image") == 1) { imageDrawElement.registerConnector([&] { ImageShowElement::showImage(to_string(this->m_index), *imageDrawElement.getImage()); @@ -409,7 +403,7 @@ registerElement(imageDrawElement); } - // registerElement(newRecordVideoElement); + // registerElement(newRecordVideoElement); //videoCaptureElement.setOutPutInterval(3); faceExtractElement.setProperty("index", to_string(m_index)); registerElement(yoloRpcElement); @@ -543,14 +537,12 @@ leftJudgment.init(rule.strAreas, rule.strLine); rightJudgment.init(rule.strExAreas, rule.strExLine); yoloRpcElement.registerConnector([&] { - if(!leftJudgment.isBusy()) - { - leftJudgment.setYoloObjects(yoloRpcElement.getLastScoreRects()); - leftJudgment.setImage(yoloRpcElement.getImage()); - leftJudgment.submit(); + if (!leftJudgment.isBusy()) { + leftJudgment.setYoloObjects(yoloRpcElement.getLastScoreRects()); + leftJudgment.setImage(yoloRpcElement.getImage()); + leftJudgment.submit(); } - if(!rightJudgment.isBusy()) - { + if (!rightJudgment.isBusy()) { rightJudgment.setYoloObjects(yoloRpcElement.getLastScoreRects()); rightJudgment.setImage(yoloRpcElement.getImage()); diff --git a/QiaoJiaSystem/StructureApp/FaceExtractElement.cpp b/QiaoJiaSystem/StructureApp/FaceExtractElement.cpp index d9883e9..ea85245 100644 --- a/QiaoJiaSystem/StructureApp/FaceExtractElement.cpp +++ b/QiaoJiaSystem/StructureApp/FaceExtractElement.cpp @@ -92,6 +92,20 @@ auto sharedImage = cv::Mat(image.rows, image.cols, CV_8UC3, sharedMemory->data()); image.copyTo(sharedImage); + + // 涓婁紶澶у浘 + string strBigImgUrl; + if (fdfsClient != nullptr && fdfsClient->fastFds != nullptr) { + fdfsClient->rwLock.rdlock(); + std::vector<unsigned char> buffer; + CvUtil::cvMat2Buffer(image, buffer); + fdfsClient->fastFds->uploadFile(buffer, strBigImgUrl, "jpg"); + fdfsClient->rwLock.unlock(); + } else { + strBigImgUrl = ""; + ERR("fdfsClient is nullptr ???"); + } + unsigned long size = faceExtractQueueTmp[i].facesPos.size(); for (int j = 0; j < size; j++) { auto feature = extractServer->faceExtract(image.cols, image.rows, faceExtractQueueTmp[i].facesPos[j], @@ -109,7 +123,6 @@ } features.clear(); features.emplace_back(feature); - std::string strImgUrl = "http://"; if (fdfsClient != nullptr && fdfsClient->fastFds != nullptr) { fdfsClient->rwLock.rdlock(); @@ -127,135 +140,8 @@ strImgUrl = ""; ERR("fdfsClient is nullptr ???"); } + InsertToESDB(faceExtractQueueTmp, t_com_sc, i, j, feature, strImgUrl, strBigImgUrl); - //鎷兼帴json - 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; //涓婚敭 - - std::string feature_base64; - feature_base64 = base64.Encode(feature.data(), feature.size()); - - //#鍦ㄥ姣斾腑娣诲姞鐗瑰緛鍊� - t_json["FaceFeature"] = feature_base64; - 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"] = ""; - - - t_json["personPicUrl"] = "";//浜哄憳鍥剧墖 store - t_json["picAddress"] = getProperty("str_addr");//鎶撴媿鍦板潃 - DBG("picAddress=" << t_json["picAddress"]); - t_json["picMaxUrl"] = "";//澶у浘璺緞 - t_json["picLocalUrl"] = "";//鏈湴璺緞 - t_json["picSmUrl"] = strImgUrl;//浜哄憳鎶撳皬鍥� - //#todo - t_json["picDate"] = faceExtractQueueTmp[i].scoredRects[j].properties["time"]; - DBG("picDate=" << t_json["picDate"].asString()); -// DBG("timeC ::::B" << t_json["picDate"m_bIsMask].asString()); -// t_json["picDate"] = AppUtil::getTimeSecString(); - - 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: 鏈煡 - - - t_json["cluster_id"] = appPref.getStringData("clusterID"); - t_json["ack_alarm"] = "0"; - - //faceExtractElement.setProperty("dev_id", str_device_id); - //faceExtractElement.setProperty("cg_id", str_ch_id); - t_json["videoNum"] = getProperty("dev_id");//Video璁惧缂栧彿//getProperty("path");//Vide缂栧彿 澶栭敭 - t_json["videoReqNum"] = getProperty("dev_id");//Video璁惧缂栧彿 - t_json["ChannlId"] = getProperty("ch_id");//閫氶亾id - t_json["isDelete"] = "1";//榛樿1 ,0鏃犳晥 1鏈夋晥 - - //浜鸿劯灞炴�� - t_json["Age"] = atoi( - faceExtractQueueTmp[i].scoredRects[j].properties["age"].c_str());//妫�娴嬬殑骞撮緞 搴旇涓虹┖ 鏃犳娴嬬粨鏋� - - //#todo 浼樺寲 get vector<string> from json - t_json["Gender"] = faceExtractQueueTmp[i].scoredRects[j].properties["gender"];//妫�娴嬬殑鎬у埆 涓虹┖ 鏃犳娴嬬粨鏋� - switch (atoi(faceExtractQueueTmp[i].scoredRects[j].properties["gender"].c_str())) { - case 0: - t_json["Gender"] = "濂�"; - break; - case 1: - t_json["Gender"] = "鐢�"; - break; - } - - t_json["BeautyLevel"] = faceExtractQueueTmp[i].scoredRects[j].properties["beauty"];//妫�娴嬬殑缇庡寲姘村钩 涓虹┖ 鏃犳娴嬬粨鏋� - t_json["SimleLevel"] = faceExtractQueueTmp[i].scoredRects[j].properties["smile"];//妫�娴嬬殑寰瑧姘村钩 涓虹┖ 鏃犳娴嬬粨鏋� - t_json["Race"] = "";//妫�娴嬬殑绉嶆棌 搴旇涓虹┖ 鏃犳娴嬬粨鏋� - t_json["videoIp"] = getProperty("local_ip");//褰撳墠鏈嶅姟鍣↖P鍦板潃 - - t_json["cluster_id"] = appConfig.getStringProperty("clusterID");//闆嗙兢id - t_json["ack_alarm"] = "0";//ack_alarm鏄惁鎶ヨ - - //#todo 浼樺寲 get vector<string> from json - switch (atoi(faceExtractQueueTmp[i].scoredRects[j].properties["race"].c_str())) { - case 1: - t_json["Race"] = "鐧戒汉"; - break; - case 2: - t_json["Race"] = "榛勪汉"; - break; - case 3: - t_json["Race"] = "榛戜汉"; - break; - } - -// DBG(t_json.toStyledString()); - - t_json["indeviceid"] = appPref.getStringData("fxDevID"); - t_json["indevicename"] = appPref.getStringData("fxDevNAME"); - - std::string strImageKey = faceExtractQueueTmp[i].scoredRects[j].properties["imgKey"]; - INFO("SaveImageKey To ES: " << strImageKey); - t_json["imgKey"] = strImageKey; - - try { - auto server = m_rpcClient.getServer(); - if (!server) { - ERR("server is null"); - //return; - } - INFO("Record Video " << strImageKey); - server->recordVideo(strImageKey); - } catch (std::exception &e) { - ERR("Record Video Err: " << strImageKey << " Message: " << e.what()); - //return; - } - auto faceSearchServer = faceSearchRpcClient.getServer(); - if (!faceSearchServer) { - ERR("faceSearchServer is null"); - EsDBTool pManagerEsDB(appPref.getStringData("ipAdd"), appPref.getIntData("ipPort")); - bool retface = false; - retface = pManagerEsDB.insertData("videopersons", "perVideoPicture", t_json.toStyledString(), - str_uuid); -// if (retface) { -// INFO("facedb success"); -// } else { -// ERR("facedb fail"); -// } - } else { - INFO("send faceSearchTopN "); - auto faceSearchResults = faceSearchServer->faceSearchTopN(feature, t_json.toStyledString(), 2, - t_com_sc); - } } } } catch (std::exception &e) { @@ -264,7 +150,140 @@ if (!features.empty())fireConnectors(); } +void FaceExtractElement::InsertToESDB(const vector<FaceToExtract> &faceExtractQueueTmp, float t_com_sc, int i, int j, + FaceDetect::Data &feature, string &strImgUrl, string &strBigImgUrl) { + //鎷兼帴json + 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; //涓婚敭 + + string feature_base64; + feature_base64 = base64.Encode(feature.data(), feature.size()); + + //#鍦ㄥ姣斾腑娣诲姞鐗瑰緛鍊� + t_json["FaceFeature"] = feature_base64; + 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"] = ""; + + + t_json["personPicUrl"] = "";//浜哄憳鍥剧墖 store + t_json["picAddress"] = getProperty("str_addr");//鎶撴媿鍦板潃 + DBG("picAddress=" << t_json["picAddress"]); + t_json["picMaxUrl"] = strBigImgUrl;//澶у浘璺緞 + t_json["picLocalUrl"] = "";//鏈湴璺緞 + t_json["picSmUrl"] = strImgUrl;//浜哄憳鎶撳皬鍥� +//#todo + t_json["picDate"] = faceExtractQueueTmp[i].scoredRects[j].properties["time"]; + DBG("picDate=" << t_json["picDate"].asString()); +// DBG("timeC ::::B" << t_json["picDate"m_bIsMask].asString()); +// t_json["picDate"] = AppUtil::getTimeSecString(); + + t_json["content"] = ""; + //t_json["viType"] = "2";//鍙湁4绉嶇被鍨� 1:personface 2:personbody 3:car 4:bicycle 5:none 鏈煡绫诲瀷 + t_json["sdkType"] = to_string( + m_sdkRule.nSdkType);//鍙湁4绉嶇被鍨� 1:personface 2:personbody 3:car 4:bicycle 5:none 鏈煡绫诲瀷 + t_json["personIsHub"] = "4";//1: 鎶ヨ 2: 鍙枒 3: 瀹夊叏 4: 鏈煡 + + + t_json["cluster_id"] = appPref.getStringData("clusterID"); + t_json["ack_alarm"] = "0"; + + //faceExtractElement.setProperty("dev_id", str_device_id); +//faceExtractElement.setProperty("cg_id", str_ch_id); + t_json["videoNum"] = getProperty("dev_id");//Video璁惧缂栧彿//getProperty("path");//Vide缂栧彿 澶栭敭 + t_json["videoReqNum"] = getProperty("dev_id");//Video璁惧缂栧彿 + t_json["ChannlId"] = getProperty("ch_id");//閫氶亾id + t_json["isDelete"] = "1";//榛樿1 ,0鏃犳晥 1鏈夋晥 + + //浜鸿劯灞炴�� + t_json["Age"] = atoi( + faceExtractQueueTmp[i].scoredRects[j].properties["age"].c_str());//妫�娴嬬殑骞撮緞 搴旇涓虹┖ 鏃犳娴嬬粨鏋� + + //#todo 浼樺寲 get vector<string> from json + t_json["Gender"] = faceExtractQueueTmp[i].scoredRects[j].properties["gender"];//妫�娴嬬殑鎬у埆 涓虹┖ 鏃犳娴嬬粨鏋� + switch (atoi(faceExtractQueueTmp[i].scoredRects[j].properties["gender"].c_str())) { + case 0: + t_json["Gender"] = "濂�"; + break; + case 1: + t_json["Gender"] = "鐢�"; + break; + } + + t_json["BeautyLevel"] = faceExtractQueueTmp[i].scoredRects[j].properties["beauty"];//妫�娴嬬殑缇庡寲姘村钩 涓虹┖ 鏃犳娴嬬粨鏋� + t_json["SimleLevel"] = faceExtractQueueTmp[i].scoredRects[j].properties["smile"];//妫�娴嬬殑寰瑧姘村钩 涓虹┖ 鏃犳娴嬬粨鏋� + t_json["Race"] = "";//妫�娴嬬殑绉嶆棌 搴旇涓虹┖ 鏃犳娴嬬粨鏋� + t_json["videoIp"] = getProperty("local_ip");//褰撳墠鏈嶅姟鍣↖P鍦板潃 + + t_json["cluster_id"] = appConfig.getStringProperty("clusterID");//闆嗙兢id + t_json["ack_alarm"] = "0";//ack_alarm鏄惁鎶ヨ + + //#todo 浼樺寲 get vector<string> from json + switch (atoi(faceExtractQueueTmp[i].scoredRects[j].properties["race"].c_str())) { + case 1: + t_json["Race"] = "鐧戒汉"; + break; + case 2: + t_json["Race"] = "榛勪汉"; + break; + case 3: + t_json["Race"] = "榛戜汉"; + break; + } + +// DBG(t_json.toStyledString()); + + t_json["indeviceid"] = appPref.getStringData("fxDevID"); + t_json["indevicename"] = appPref.getStringData("fxDevNAME"); + + string strImageKey = faceExtractQueueTmp[i].scoredRects[j].properties["imgKey"]; + INFO("SaveImageKey To ES: " << strImageKey); + t_json["imgKey"] = strImageKey; + + try { + auto server = m_rpcClient.getServer(); + if (!server) { + ERR("server is null"); + //return; + } + INFO("Record Video " << strImageKey); + server->recordVideo(strImageKey); + } catch (exception &e) { + ERR("Record Video Err: " << strImageKey << " Message: " << e.what()); + //return; + } + auto faceSearchServer = faceSearchRpcClient.getServer(); + if (!faceSearchServer) { + ERR("faceSearchServer is null"); + EsDBTool pManagerEsDB(appPref.getStringData("ipAdd"), appPref.getIntData("ipPort")); + bool retface = false; + retface = pManagerEsDB.insertData("videopersons", "perVideoPicture", t_json.toStyledString(), + str_uuid); +// if (retface) { +// INFO("facedb success"); +// } else { +// ERR("facedb fail"); +// } + } else { + INFO("send faceSearchTopN "); + auto faceSearchResults = faceSearchServer->faceSearchTopN(feature, t_json.toStyledString(), 2, + t_com_sc); + } +} + std::vector<::FaceDetect::Data> FaceExtractElement::getFeatures() const { return features; } + diff --git a/QiaoJiaSystem/StructureApp/FaceExtractElement.h b/QiaoJiaSystem/StructureApp/FaceExtractElement.h index 94f21b0..bbf7266 100644 --- a/QiaoJiaSystem/StructureApp/FaceExtractElement.h +++ b/QiaoJiaSystem/StructureApp/FaceExtractElement.h @@ -14,6 +14,7 @@ #include <mutex> #include <jsoncpp/json/json.h> #include "DBStruct.h" + #define VECTOR_MAX 50 class QSharedMemory; @@ -30,7 +31,7 @@ class FaceExtractElement : public TimerElement { public: - FaceExtractElement(std::string shareMemoryName,const SdkRule& rule); + FaceExtractElement(std::string shareMemoryName, const SdkRule &rule); //FaceExtractElement(std::string shareMemoryName,const SdkRule& rule,SaveVideoRpcClient_t& rpcClient); ~FaceExtractElement(); @@ -57,10 +58,13 @@ // AlarmServerInterface::TableNames tableNames; std::vector<::FaceDetect::Data> features; - + cv::Mat m_image; Base64 base64; SdkRule m_sdkRule; SaveVideoRpcClient_t m_rpcClient; + + void InsertToESDB(const vector<FaceToExtract> &faceExtractQueueTmp, float t_com_sc, int i, int j, + FaceDetect::Data &feature, string &strImgUrl, string &strBigImgUrl); }; -- Gitblit v1.8.0