| | |
| | | t_live_ret = false; |
| | | } |
| | | |
| | | //#todo 优化 |
| | | /*** |
| | | * @dep |
| | | */ |
| | | ::FaceSearch::FaceResults |
| | | FaceFeatureSearchServerI::faceSearchMax(const ::FaceSearch::Data &feature, const ::std::string &info_json, |
| | | const ::Ice::Current &) { |
| | | thread::id key = std::this_thread::get_id(); |
| | | ClockTimer clockTimer("faceSearchMax"); |
| | | ::FaceSearch::FaceResults results; |
| | | FaceResults t_TableCompareResult; |
| | | AlarmData featureData; |
| | | featureData.num = 1; |
| | | featureData.feature.resize(feature.size()); |
| | | memcpy(featureData.feature.data(), feature.data(), feature.size()); |
| | | |
| | | for (auto &it : m_faceFCMAP) { |
| | | auto &t_FaceFC = it.second; |
| | | auto t_tableInfo = m_tableType[it.first]; |
| | | bool ret = getRet(t_tableInfo.startTime, t_tableInfo.endTime); |
| | | if (ret) { |
| | | bool alarmRet = atoi(t_tableInfo.bwType.c_str()); |
| | | //#todo 非同步库是否需要比较? |
| | | t_FaceFC->compare(key, &featureData, 1); |
| | | auto t_results = t_FaceFC->getTopResult(key); |
| | | for (auto &t_item : t_results) { |
| | | t_item.tableName = it.first; |
| | | //#todo baojing zhuangtai ? |
| | | t_item.alarmRet = ret; |
| | | t_TableCompareResult.push_back(t_item); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // DBG("t_TableCompareResult size" << t_TableCompareResult.size()); |
| | | for (auto itor = t_TableCompareResult.begin(); itor != t_TableCompareResult.end(); ++itor) { |
| | | float new_confidence = itor->confidence; |
| | | auto rtTR = results.rbegin(); |
| | | if (!results.empty()) { |
| | | auto temp = rtTR->confidence; |
| | | while (new_confidence > temp) { |
| | | ++rtTR; |
| | | if (rtTR == (results.rend() + 1)) { |
| | | rtTR--; |
| | | break; |
| | | } else { |
| | | // DBG(" sc is "<< new_confidence << " > " << temp); |
| | | } |
| | | temp = rtTR->confidence; |
| | | } |
| | | } else { |
| | | // INFO("topResult is null"); |
| | | } |
| | | auto itTR(rtTR.base()); |
| | | ::FaceSearch::FaceResult t_faceCR; |
| | | t_faceCR.id = itor->id; |
| | | t_faceCR.uuid = itor->uuid; |
| | | t_faceCR.tableName = itor->tableName; |
| | | t_faceCR.confidence = itor->confidence; |
| | | DBG("compare results tablename is " << t_faceCR.tableName << " id is " << t_faceCR.uuid << " sc is" |
| | | << t_faceCR.confidence); |
| | | results.insert(itTR, t_faceCR); |
| | | } |
| | | |
| | | |
| | | //#todo send message |
| | | |
| | | return results; |
| | | return ::FaceSearch::FaceResults(); |
| | | } |
| | | |
| | | //#todo 优化 |
| | | ::FaceSearch::FaceResults |
| | | FaceFeatureSearchServerI::faceSearchTopN(const ::FaceSearch::Data &feature, const ::std::string &info_json, |
| | | ::Ice::Int topN, ::Ice::Float score, const ::Ice::Current &) { |
| | | ClockTimer clockTimer("faceSearchTopN " + to_string(score) + " :"); |
| | | ClockTimer clockTimer("faceSearchTopN "); |
| | | INFO("faceSearchTopN start"); |
| | | // #获取线程id去找资源句柄 |
| | | thread::id key = std::this_thread::get_id(); |
| | | // 返回结果 |
| | | ::FaceSearch::FaceResults results; |
| | | // 对比结果的临时缓存 |
| | | FaceResults t_TableCompareResult; |
| | | // 需要对比的数据 |
| | | AlarmData featureData; |
| | | featureData.num = topN; |
| | | featureData.feature.resize(feature.size()); |
| | |
| | | if (reader.parse(info_json, value)) { |
| | | //#todo |
| | | m_rwLock.rdlock(); |
| | | std::string feature_base64; |
| | | feature_base64 = base64.Encode(feature.data(), feature.size()); |
| | | value["FaceFeature"] = feature_base64; |
| | | // 开始对比 |
| | | DBG("auto &it : m_faceFCMAP start " << m_faceFCMAP.size()); |
| | | //#todo lock |
| | | // 遍历不同的底库类#TODO是否要做一次大范围对比然后给出结果再筛选? |
| | | for (auto &it : m_faceFCMAP) { |
| | | auto &t_FaceFC = it.second; |
| | | // 表的信息#TODO待移出和业务解耦 |
| | | auto t_tableInfo = m_tableType[it.first]; |
| | | bool ret = getRet(t_tableInfo.startTime, t_tableInfo.endTime); |
| | | // 判断表的生效状态,决定是否进行对比/时间和启用状态 |
| | | bool ret = (t_tableInfo.enabled == "1" && getRet(t_tableInfo.startTime, t_tableInfo.endTime)); |
| | | if (ret) { |
| | | // 需要对比 |
| | | |
| | | // 表的类型/黑白名单 |
| | | string t_alarmRet = t_tableInfo.bwType; |
| | | // bool alarmRet = atoi(t_tableInfo.bwType.c_str()); |
| | | //#todo 非同步库是否需要比较? |
| | | |
| | | DBG("m_faceFCMAP compare start " << it.first); |
| | | t_FaceFC->compare(key, &featureData, topN); |
| | | // 对比分数,摄像机分数和布控库分数,谁低按谁?暂时不做 |
| | | // if(){ |
| | | // } |
| | | // score |
| | | // 对比函数 |
| | | float t_score = atoi(t_tableInfo.cmpThreshold.c_str()) / 100; |
| | | t_FaceFC->compare(key, &featureData, topN, t_score); |
| | | DBG("m_faceFCMAP compare end " << it.first); |
| | | |
| | | // 获取对比结果 |
| | | auto t_results = t_FaceFC->getTopResult(key); |
| | | // 遍历结果并添加补充字段 |
| | | for (auto &t_item : t_results) { |
| | | t_item.tableName = it.first; |
| | | t_item.alarmRet = t_alarmRet; |
| | | // 放入本次任务的对比缓存 |
| | | t_TableCompareResult.push_back(t_item); |
| | | // DBG("t_results item : uuid is " << t_item.uuid << " confidence " << t_item.confidence << it.first); |
| | | } |
| | | } else { |
| | | // 不需要对比 |
| | | INFO("m_faceFCMAP ret is false " << it.first); |
| | | } |
| | | } |
| | | m_rwLock.unlock(); |
| | | DBG("auto &it : m_faceFCMAP end"); |
| | | |
| | | // 本次任务的对比结果数量 |
| | | DBG("t_TableCompareResult size" << t_TableCompareResult.size()); |
| | | //sort_all_results |
| | | // 所有表对比结束后,排序及结果格式转换 |
| | | for (auto itor = t_TableCompareResult.begin(); itor != t_TableCompareResult.end(); ++itor) { |
| | | float new_confidence = itor->confidence; |
| | | auto rtTR = results.rbegin(); |
| | |
| | | results.insert(itTR, t_faceCR); |
| | | } |
| | | bool retface = true; |
| | | // cout << __FUNCTION__ << " -> " << __LINE__ << " -> " << results.size() << endl; |
| | | |
| | | //#todo send message |
| | | // 拼接需要发送的消息 |
| | | // 特征编码为base64用于上传,#todo 拆解到外面去做 |
| | | std::string feature_base64; |
| | | feature_base64 = base64.Encode(feature.data(), feature.size()); |
| | | if (results.size() > 0) { |
| | | // 找到相似人 可能对比分数不满足条件 |
| | | // #TODO多条对比结果拼接成一个标签 |
| | | for (auto &item : results) { |
| | | //#todo 得分比较,应该在compare中进行 |
| | | // 小于指定的阈值则认为没有找到是陌生人 |
| | | if (item.confidence < score) { |
| | | //#todo test |
| | | auto str_uuid = value["Id"].asString(); |
| | | value["personIsHub"] = "4"; |
| | | value["likePer"] = 0.0; |
| | | // DBG(value.toStyledString()); |
| | | cout << __FUNCTION__ << " -> " << __LINE__ << " -> " << "value.toStyledString() " |
| | | << value.toStyledString() << endl; |
| | | DBG("value.toStyledString() " << value.toStyledString()); |
| | | value["FaceFeature"] = feature_base64; |
| | | |
| | | retface = pManagerEsDB.insertData("videopersons", "perVideoPicture", value.toStyledString(), |
| | | str_uuid); |
| | | break; |
| | |
| | | |
| | | value["likePer"] = item.confidence > 0 ? item.confidence : 0.0; |
| | | value["personPicUrl"] = item.imgUrl.size() > 0 ? item.imgUrl : "";//diku tupian |
| | | |
| | | // string strC = item.idcard+ item. |
| | | value["idcard"] = item.idcard.size() > 0 ? item.idcard : "";//diku tupian |
| | | //如果 alarmRet 不为空把 他的值 放入 personIsHub,否则为4 |
| | | // #TODO 如果启用则正常判断,未布控则认为是未知? |
| | | // if () { |
| | | // |
| | | // } |
| | | value["personIsHub"] = item.alarmRet.size() > 0 ? item.alarmRet : "4"; |
| | | |
| | | auto str_uuid = value["Id"].asString(); |
| | | // DBG(value.toStyledString()); |
| | | DBG("value.toStyledString() " << value.toStyledString()); |
| | | value["FaceFeature"] = feature_base64; |
| | | |
| | | cout << __FUNCTION__ << " -> " << __LINE__ << " -> " << "value.toStyledString() " |
| | | << value.toStyledString() << "\n score " << score << endl; |
| | | // DBG("score " << score); |
| | | retface = pManagerEsDB.insertData("videopersons", "perVideoPicture", value.toStyledString(), |
| | | str_uuid); |
| | | break; |
| | |
| | | value["personIsHub"] = "4"; |
| | | value["likePer"] = 0.0; |
| | | DBG(value.toStyledString()); |
| | | value["FaceFeature"] = feature_base64; |
| | | // cout << __FUNCTION__ << " -> " << __LINE__ << " -> " << "value.toStyledString() " |
| | | // << value.toStyledString() << endl; |
| | | retface = pManagerEsDB.insertData("videopersons", "perVideoPicture", value.toStyledString(), |
| | |
| | | } else { |
| | | ERR("json is error" << info_json); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | // for (auto &item : t_tables) { |
| | | // DBG(item); |
| | | // } |
| | | return results; |
| | | } |
| | | |
| | |
| | | std::thread thd(dataUpdate, faceFea); |
| | | thd.detach(); |
| | | } |
| | | auto typeInfoCache = faceFea->m_erlangDbTool.findAllTypeInfo(); |
| | | // auto typeInfoCache = faceFea->m_erlangDbTool.findAllTypeInfo(); |
| | | faceFea->m_tableType.clear(); |
| | | string str_config = faceFea->m_erlangDbTool.getConfigJsonString(); |
| | | |
| | |
| | | // tabInfo.bwType = item.second.bwType = typeInfoCache.find(item.first)->second.bwType; |
| | | tabInfo.bwType = item.second.bwType;//= typeInfoCache.find(item.first)->second.bwType; |
| | | tabInfo.createBy = item.second.create_by; |
| | | tabInfo.enabled = item.second.enabled; |
| | | tabInfo.cmpThreshold = item.second.cmpThreshold; |
| | | |
| | | if ((tabInfo.tableName.find("lt_") == 0) && (tabInfo.createBy != appConfig.getStringProperty("erlNode"))) { |
| | | continue; |