From b5ac5f7d1e0f79d332dcddc3dabd8709b1e2a2ea Mon Sep 17 00:00:00 2001 From: chenshijun <csj_sky@126.com> Date: 星期三, 10 四月 2019 19:42:29 +0800 Subject: [PATCH] 解决nsg消费者的topic名称带有./的bug 注释一些错误打印 --- QiaoJiaSystem/StructureApp/FaceExtractElement.cpp | 277 +++++++++++++++++++++++++++++++++--------------------- 1 files changed, 168 insertions(+), 109 deletions(-) diff --git a/QiaoJiaSystem/StructureApp/FaceExtractElement.cpp b/QiaoJiaSystem/StructureApp/FaceExtractElement.cpp index 7f6e288..56da883 100644 --- a/QiaoJiaSystem/StructureApp/FaceExtractElement.cpp +++ b/QiaoJiaSystem/StructureApp/FaceExtractElement.cpp @@ -4,6 +4,7 @@ #include <QtCore/QString> #include <basic/util/app/AppUtil.h> #include <basic/util/opencv/CvUtil.h> +#include <basic/util/app/AppPreference.hpp> //diao鐢ㄥ搴攅s鏁版嵁灏佽鐨勭被 //#include <basic/db/ES/es/ManagerEsDB.h> #include <basic/db/Elasticsearch/EsDBTool.h> @@ -11,6 +12,7 @@ #include <QtCore/QJsonObject> #include <uuid/uuid.h> #include <jsoncpp/json/json.h> +#include <basic/util/app/AppConfig.h> #define state "state" @@ -25,7 +27,7 @@ } } -FaceExtractElement::FaceExtractElement(std::string shareMemoryName) : +FaceExtractElement::FaceExtractElement(std::string shareMemoryName, const SdkRule &rule) : TimerElement(1000), sharedMemory(nullptr), fdfsClient(nullptr), //#todo appPref.setStringData faceExtractRpcClient(appPref.getStringData("faceExte.proxy"), appPref.getStringData("faceExte.ip"), @@ -33,9 +35,10 @@ // faceExtractRpcClient(/*appPref.getStringData("face.extract.proxy")*/ // "faceExtractServer", "", 10008, "tcp"),//浜鸿劯鐗瑰緛鎻愬彇 淇敼鎴愮偣瀵圭偣閫氳 faceSearchRpcClient(appPref.getStringData("faceSear.proxy"), appPref.getStringData("faceSear.ip"), - appPref.getIntData("faceSear.port"), "tcp") + appPref.getIntData("faceSear.port"), "tcp"), // faceSearchRpcClient("faceCmServer", "", 10004, "tcp") -{ + m_sdkRule(rule), + m_rpcClient("RtspAnalysServer", "127.0.0.1", appPref.getIntData("RpcVTIMPort"), "tcp") { sharedMemory = new QSharedMemory(QString(shareMemoryName.c_str())); if (!sharedMemory->create(4608 * 2592 * 4)) { sharedMemory->attach(); @@ -58,20 +61,24 @@ } void FaceExtractElement::timerFunc() { +// INFO("MYH Run Here"); std::vector<FaceToExtract> faceExtractQueueTmp; { std::lock_guard<std::mutex> lg(imageQueueMutex); - if (faceExtractQueue.empty())return; + if (faceExtractQueue.empty()) { + ERR("faceExtractQueue.empty "); + return; + } faceExtractQueueTmp.swap(faceExtractQueue); faceExtractQueue.clear(); } try { string t_camIdex = getProperty("dev_id") + getProperty("ch_id"); - float t_com_sc = - appPref.getFloatData(t_camIdex + "face.cmp") == -1 ? 75 : appPref.getFloatData(t_camIdex + "face.cmp"); + float t_com_sc = m_sdkRule.nThreshold == 0 ? 75 : m_sdkRule.nThreshold; - DBG(" TESTCODE getValue" << t_camIdex << " " << t_com_sc << " " << t_com_sc / 100); + +// DBG(" TESTCODE getValue" << t_camIdex << " " << t_com_sc << " " << t_com_sc / 100); t_com_sc = t_com_sc / 100; @@ -85,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], @@ -97,12 +118,11 @@ // cv::imwrite(string1, image); // } if (feature.empty()) { - ERR("feature is empty"); +// INFO("No Face Find: " << getProperty("imgKey")); continue; } features.clear(); features.emplace_back(feature); - std::string strImgUrl = "http://"; if (fdfsClient != nullptr && fdfsClient->fastFds != nullptr) { fdfsClient->rwLock.rdlock(); @@ -110,112 +130,18 @@ CvUtil::cvMat2Buffer(faceExtractQueueTmp[i].faceImages[j], buffer); std::string strImgUrlTmp = ""; fdfsClient->fastFds->uploadFile(buffer, strImgUrlTmp, "jpg"); - strImgUrl.append(fdfsClient->fastFds->getIp() + "/" + strImgUrlTmp); + // strImgUrl.append(fdfsClient->fastFds->getIp() + "/" + strImgUrlTmp); +// DBG("strImgUrlTmp=" << strImgUrlTmp); strImgUrl.clear(); strImgUrl = strImgUrlTmp; // strImgUrl.append("/").append(strImgUrlTmp); fdfsClient->rwLock.unlock(); - } - - //鎷兼帴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; //涓婚敭 - - //#鍦ㄥ姣斾腑娣诲姞鐗瑰緛鍊� - t_json["FaceFeature"] = "base64"; - t_json["personId"] = "wait todo";//鍏宠仈搴曞簱浜哄憳id,浜鸿劯id - t_json["BaseName"] = "wait todo";//鍏宠仈搴曞簱琛ㄥ悕 - //#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["personPicUrl"] = "wait todo";//浜哄憳鍥剧墖 store - t_json["picAddress"] = getProperty("str_addr");//鎶撴媿鍦板潃 - t_json["picMaxUrl"] = "wait todo";//澶у浘璺緞 - t_json["picLocalUrl"] = "wait todo";//鏈湴璺緞 - t_json["picSmUrl"] = strImgUrl;//浜哄憳鎶撳皬鍥� - //#todo - t_json["picDate"] = faceExtractQueueTmp[i].scoredRects[j].properties["time"]; -// DBG("timeC ::::B" << t_json["picDate"].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["personIsHub"] = "4";//1: 鎶ヨ 2: 鍙枒 3: 瀹夊叏 4: 鏈煡 - - - //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鍦板潃 - - //#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"); - - 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); + strImgUrl = ""; + ERR("fdfsClient is nullptr ???"); } + InsertToESDB(faceExtractQueueTmp, t_com_sc, i, j, feature, strImgUrl, strBigImgUrl); + } } } catch (std::exception &e) { @@ -224,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; } + -- Gitblit v1.8.0