Merge remote-tracking branch 'origin/1.3nsq' into 1.3nsq
| | |
| | | std::string publish_basepath = "rtmp://localhost:1934/live/cam" + std::to_string(554); |
| | | appPref.setIntData("gpu.index", 0); |
| | | appPref.setStringData("publish.basepath", publish_basepath); |
| | | appPref.setIntData("pulish.width", 640); |
| | | appPref.setIntData("pulish.height", 360); |
| | | // appPref.setIntData("pulish.width", 640); |
| | | // appPref.setIntData("pulish.height", 360); |
| | | |
| | | AppPipeController a(0, json); |
| | | a.start(); |
| | |
| | | VssDomainUnitTblController::instance()->registerHttpServices(_HttpSrvRetRecieve); |
| | | VssLocalSettingTblController::instance()->registerHttpServices(_HttpSrvRetRecieve); |
| | | CamDevController::instance()->registerHttpServices(_HttpSrvRetRecieve); |
| | | //todo |
| | | CamDevController::instance()->nsqMsgProducerSet(nsqMsgProducer); |
| | | VssUpperSvrTblController::instance()->registerHttpServices(_HttpSrvRetRecieve); |
| | | |
| | | |
| | |
| | | std::string brand) const { |
| | | |
| | | if (brand == "haikang") { |
| | | bool ret = getHKDevSerialNumber(ip.c_str(), port, username.c_str(), passwd.c_str()); |
| | | if (!ret) { |
| | | ERR("getHKDevSerialNumber ERR"); |
| | | return false; |
| | | } |
| | | // bool ret = getHKDevSerialNumber(ip.c_str(), port, username.c_str(), passwd.c_str()); |
| | | // if (!ret) { |
| | | // ERR("getHKDevSerialNumber ERR"); |
| | | // return false; |
| | | // } |
| | | //调用rtsp流rtsp://admin:a1234567@192.168.1.215:554/h264/ch1/main/av_stream |
| | | port = 554;//TODO |
| | | // std::string rtsp_url = "rtsp://" + username + ":" + passwd + "@" + ip + ":" + std::to_string(port) + |
| | |
| | | return false;//TODO |
| | | } else if (brand == "yushi") { |
| | | // rtsp://admin:admin@192.168.8.8:554/video1 |
| | | bool ret = getUVDevSerialNumber(ip.c_str(), username.c_str(), passwd.c_str()); |
| | | if (!ret) { |
| | | ERR("getUVDevSerialNumber ERR"); |
| | | return false; |
| | | } |
| | | // bool ret = getUVDevSerialNumber(ip.c_str(), username.c_str(), passwd.c_str()); |
| | | // if (!ret) { |
| | | // ERR("getUVDevSerialNumber ERR"); |
| | | // return false; |
| | | // } |
| | | |
| | | port = 554; |
| | | // std::string rtsp_url = "rtsp://" + username + ":" + passwd + "@" + ip + ":" + std::to_string(port) + |
| | |
| | | // auto resType = erlangDbTool->findAllTypeInfo(); |
| | | string json = "["; |
| | | for (auto &item : resDB) { |
| | | //-------------------maybe delete ?------------------------ |
| | | if (item.second.tableName.find("lt_") == 0) { |
| | | continue; |
| | | } |
| | | //-------------------maybe delete end---------------------- |
| | | |
| | | string subJson = "{ "; |
| | | subJson.append("\"uuid\":\"" + item.second.uuid + "\","); |
| | | subJson.append("\"tableName\":\"" + item.second.tableName + "\","); |
| | |
| | | } |
| | | } |
| | | |
| | | if (videoStVec.size() >= 1) { |
| | | std::string strVideoName = strPath + videoStVec[0].ToVideoName(); |
| | | std::vector<VideoName_s_t> videoStVec_; |
| | | auto imgTm_ = AppUtil::ParseFromHypenTimeStr(imgSt.m_timeStamp); |
| | | for (auto &item : videoStVec) { |
| | | auto resTime_ = AppUtil::ParseFromHypenTimeStr(item.m_timeStamp); |
| | | auto timeRes = difftime(mktime(&resTime_), mktime(&imgTm_)); |
| | | if ((timeRes < 0 && difftime(mktime(&imgTm_), mktime(&resTime_)) >= 30) || (timeRes / 60 >= 3)) { |
| | | continue; |
| | | } |
| | | videoStVec_.emplace_back(item); |
| | | } |
| | | |
| | | if (videoStVec_.size() >= 1) { |
| | | std::string strVideoName = strPath + videoStVec_[0].ToVideoName(); |
| | | INFO("ImageName: " << imgKey << " SingleMatchVideo: " << strVideoName); |
| | | return strVideoName; |
| | | } else { |
| | |
| | | rule.strExAreas = value["strExAreas"].asCString(); |
| | | rule.strLine = value["strLine"].asCString(); |
| | | rule.strExLine = value["strExLine"].asCString(); |
| | | |
| | | if (!value["strPerimeterObjType"].empty()) { |
| | | rule.strPerimeterObjType = value["strPerimeterObjType"].asCString(); |
| | | } |
| | | if (rule.strCamId.isEmpty()) { |
| | | return "{\"ret_status\":\"内容有误,请检查!\"}"; |
| | | } |
| | |
| | | obj["strExAreas"] = rule.second.strExAreas.toStdString(); |
| | | obj["strLine"] = rule.second.strLine.toStdString(); |
| | | obj["strExLine"] = rule.second.strExLine.toStdString(); |
| | | obj["strPerimeterObjType"] = rule.second.strPerimeterObjType.toStdString(); |
| | | Json::Value weekRuleArray; |
| | | |
| | | |
| | |
| | | std::string createDatabase(std::string ip, unsigned int port, std::string content, PResponse &response); |
| | | |
| | | /** |
| | | * |
| | | * 删除数据 底库 |
| | | * @param ip |
| | | * @param port |
| | | * @param content |
| | |
| | | */ |
| | | std::string deleteDatabase(std::string ip, unsigned int port, std::string content, PResponse &response); |
| | | |
| | | /*** |
| | | * 更新数据 底库 |
| | | * @param ip |
| | | * @param port |
| | | * @param content |
| | | * @param response |
| | | * @return |
| | | */ |
| | | std::string updateDatabase(std::string ip, unsigned int port, std::string content, PResponse &response); |
| | | |
| | | /** |
| | | * 查询所有同步库 |
| | | * @param ip |
| | | * @param port |
| | | * @param content |
| | | * @param response |
| | | * @return |
| | | */ |
| | | std::string findAllDatabase(std::string ip, unsigned int port, std::string content, PResponse &response); |
| | | |
| | | /** |
| | | * 查询所有本地库 |
| | | * @param ip |
| | | * @param port |
| | | * @param content |
| | | * @param response |
| | | * @return |
| | | */ |
| | | std::string findLocalDatabase(std::string ip, unsigned int port, std::string content, PResponse &response); |
| | | |
| | | /*** |
| | | * 上传人员 |
| | | * @param ip |
| | | * @param port |
| | | * @param content |
| | | * @param response |
| | | * @return |
| | | */ |
| | | std::string addPerson(std::string ip, unsigned int port, std::string content, PResponse &response); |
| | | |
| | | //#todo 批量添加人员借口 |
| | | |
| | | /*** |
| | | * 向同步库批量添加人员及更新人员 |
| | | * feature_addPersonTracking 分支中更新功能分离为新借口 |
| | | * @param ip |
| | | * @param port |
| | | * @param content |
| | | * @param response |
| | | * @return |
| | | */ |
| | | std::string addPersons(std::string ip, unsigned int port, std::string content, PResponse &response); |
| | | |
| | | /*** |
| | | * 判断同步库中人员是否存在 |
| | | * @param ip |
| | | * @param port |
| | | * @param content |
| | | * @param response |
| | | * @return |
| | | */ |
| | | std::string personIsExists(std::string ip, unsigned int port, std::string content, PResponse &response); |
| | | |
| | | /** |
| | | * 更新同步库中的人员 |
| | | * @param ip |
| | | * @param port |
| | | * @param content |
| | | * @param response |
| | | * @return |
| | | */ |
| | | std::string updatePersonByOldId(std::string ip, unsigned int port, std::string content, PResponse &response); |
| | | |
| | | |
| | | /** |
| | | * 删除人员 |
| | | * @param ip |
| | | * @param port |
| | | * @param content |
| | | * @param response |
| | | * @return |
| | | */ |
| | | std::string delPerson(std::string ip, unsigned int port, std::string content, PResponse &response); |
| | | |
| | | /** |
| | | * 加载特征 |
| | | * @param ip |
| | | * @param port |
| | | * @param content |
| | | * @param response |
| | | * @return |
| | | */ |
| | | std::string loadFaceFeaData(std::string ip, unsigned int port, std::string content, PResponse &response); |
| | | |
| | | |
| | |
| | | #include "vss/model/CamDev.h" |
| | | #include "VssBaseController.h" |
| | | #include <mysql++.h> |
| | | #include <NsqMsgTool.hpp> |
| | | |
| | | using namespace std; |
| | | |
| | |
| | | static CamDevController *instance() { |
| | | static CamDevController instance; |
| | | return &instance; |
| | | } |
| | | |
| | | private: |
| | | //shared_ptr |
| | | BasicMsg::Nsq::NsqMsgProducer *_nsqMsgProducer; |
| | | public: |
| | | void nsqMsgProducerSet(BasicMsg::Nsq::NsqMsgProducer *nsqMsgProducer){ |
| | | _nsqMsgProducer = nsqMsgProducer; |
| | | } |
| | | |
| | | public: |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | { |
| | | std::string topic = "VideoToImageMulth"; |
| | | std::string topic1 = "VideoAnalysFromHC"; |
| | | Json::Value json_cfg; |
| | | json_cfg["cam_del"] = content; |
| | | std::string msg = json_cfg.toStyledString(); |
| | | DBG("msg:" << msg); |
| | | _nsqMsgProducer->Publish(topic, (void *) (&msg)); |
| | | _nsqMsgProducer->Publish(topic1, (void *) (&msg)); |
| | | } |
| | | |
| | | return responseJsonValue.toStyledString(); |
| | | } |
| | | |
| | |
| | | idJsonValue.asString()); |
| | | } |
| | | } |
| | | |
| | | { |
| | | std::string topic = "VideoToImageMulth"; |
| | | std::string topic1 = "VideoAnalysFromHC"; |
| | | Json::Value json_cfg; |
| | | json_cfg["cam_edit"] = content; |
| | | std::string msg = json_cfg.toStyledString(); |
| | | DBG("msg:" << msg); |
| | | _nsqMsgProducer->Publish(topic, (void *) (&msg)); |
| | | _nsqMsgProducer->Publish(topic1, (void *) (&msg)); |
| | | } |
| | | |
| | | return responseJsonValue.toStyledString(); |
| | | } |
| | | |
| | |
| | | ~FaceDetectServerI(); |
| | | // FaceDetectServer interface |
| | | public: |
| | | /** |
| | | * 人脸检测 |
| | | * @return |
| | | */ |
| | | virtual FaceDetect::Faces faceDetect(Ice::Int, Ice::Int, const std::string &, const Ice::Current &) override; |
| | | |
| | | private: |
| | |
| | | |
| | | // FaceDetectServer interface |
| | | public: |
| | | /** |
| | | * 人脸二次属性提取 |
| | | * @return |
| | | */ |
| | | virtual FaceDetect::ThftResult faceProperty(Ice::Int, Ice::Int, const FaceDetect::FacePos &, const std::string &, const Ice::Current &) override; |
| | | |
| | | private: |
| | |
| | | ERR("shareMemory attach faild"); |
| | | // throw std::runtime_error("shareMemory attach faild"); |
| | | } |
| | | return feature; |
| | | |
| | | } |
| | |
| | | IceRpcServer<FaceDetectServerI> server("faceServer", appPref.getIntData("RpcFDPort"), "tcp"); |
| | | server.setMessageSizeMax(1024 * 1024 * 50); |
| | | server.setPoolInitSize(appPref.getIntData("thread.max")); |
| | | server.setPoolMaxSize(appPref.getIntData("thread.max")); |
| | | DBG("MaxPoolSize: " << std::max(appPref.getIntData("thread.max")*2, 32)); |
| | | server.setPoolMaxSize(std::max(appPref.getIntData("thread.max")*2, 32)); |
| | | server.runWaitShutDown(); |
| | | return 0; |
| | | } |
| | |
| | | IceRpcServer<FaceExtractServerI> server("faceExtractServer", appPref.getIntData("RpcFEPort"), "tcp"); |
| | | server.setMessageSizeMax(1024 * 1024 * 50); |
| | | server.setPoolInitSize(appPref.getIntData("thread.max")); |
| | | server.setPoolMaxSize(appPref.getIntData("thread.max")); |
| | | DBG("MaxPoolSize: " << std::max(appPref.getIntData("thread.max")*2, 32)); |
| | | server.setPoolMaxSize(std::max(appPref.getIntData("thread.max")*2, 32)); |
| | | server.runWaitShutDown(); |
| | | return 0; |
| | | } |
| | |
| | | DBG("m_dbRWLocks ok"); |
| | | m_dbRWLocks_Lock.unlock(); |
| | | // ClockTimer clockTimer("compare "); |
| | | //保护 t_compareResults |
| | | RWLock t_rwLock; |
| | | |
| | | m_rwLock.rdlock(); |
| | |
| | | FaceResult tface{0, data.uuid, alarmData->tableName, sc, data.faceUrl, data.idcard, ""}; |
| | | t_rwLock.wrlock(); |
| | | //#todo |
| | | // 对比结果保存 |
| | | if (sc < t_compareResults.end()->second.confidence) { |
| | | t_rwLock.unlock(); |
| | | return; |
| | | } |
| | | // 保存对比结果 |
| | | t_compareResults.insert(make_pair(tface.confidence, tface)); |
| | | //#todo 10 |
| | | // 只保留最高的n个对比结果 |
| | | if (t_compareResults.size() > topN) { |
| | | t_compareResults.erase((--t_compareResults.end()), t_compareResults.end()); |
| | | } |
| | |
| | | auto &t_topResult = topResult[key]; |
| | | DBG("topResult[key] ok"); |
| | | t_topResult.clear(); |
| | | // 对比结果转换 |
| | | for (auto &item : t_compareResults) { |
| | | auto &it = item.second; |
| | | //#todo |
| | |
| | | m_tableName = str_tab.substr(1, str_tab.length() - 2);//.append("_fea"); |
| | | DBG("m_tableName is " << m_tableName); |
| | | |
| | | // string tet = "./syncDBClient "; |
| | | // string str_json = writer.write(t_json); |
| | | // tet.append("\"" + str_json.substr(0, str_json.length() - 1) + "\" "); |
| | | // INFO(tet); |
| | | // system(tet.c_str()); |
| | | dataMap.clear(); |
| | | try { |
| | | // init |
| | | // BISTL::BiMapFeaData biMapFeaData(m_tableName); |
| | | // auto mymap = biMapFeaData.getMap(); |
| | | |
| | | auto mymap = m_erlangDbTool->loadFaceFeaData(m_tableName); |
| | | DBG(m_tableName << " db size is " << mymap.size()); |
| | |
| | | test.enabled = it.enable; |
| | | test.monLevel = it.monLevel; |
| | | } |
| | | // //#todo |
| | | // for (auto it = mymap->begin(); it != mymap->end(); it++) { |
| | | // string str_uuid(it->second.m_id.data()); |
| | | // string ft(it->second.m_feature.data()); |
| | | // string imgUrl(it->second.m_imgUrl.data()); |
| | | // string strIdCard(it->second.m_idcard.data()); |
| | | // string str2; |
| | | // str2 = base64.Decode(ft.data(), ft.length()); |
| | | // std::vector<unsigned char> t_fea; |
| | | // t_fea.resize(str2.size()); |
| | | // memcpy(t_fea.data(), str2.data(), str2.size()); |
| | | // auto &test = dataMap[str_uuid]; |
| | | // test.uuid = str_uuid; |
| | | // test.features.push_back(t_fea); |
| | | // test.faceUrl = imgUrl; |
| | | // test.idcard = strIdCard; |
| | | // } |
| | | } catch (const std::exception &e) { |
| | | printf("Exception:%s\n", e.what()); |
| | | // BISTL::shared_memory_object::remove(m_tableName.c_str()); |
| | | } |
| | | appPref.setIntData(m_tableName, 1); |
| | | // BISTL::shared_memory_object::remove(m_tableName.c_str()); |
| | | } else { |
| | | //#todo get sqlite3 data |
| | | m_tableName = t_json["tableName"].asCString(); |
| | |
| | | public: |
| | | FaceDBCompareServer(); |
| | | |
| | | /** |
| | | * 本地库构造 |
| | | */ |
| | | FaceDBCompareServer(SqliteFaceEncap *); |
| | | |
| | | /*** |
| | | * 同步库构造 |
| | | */ |
| | | FaceDBCompareServer(ErlangTool::ErlangDbTool *); |
| | | |
| | | ~FaceDBCompareServer(); |
| | | |
| | | virtual bool compare(std::thread::id key, AlarmData *alarmData, int topN); |
| | | |
| | | /*** |
| | | * @deprecated |
| | | * @param key |
| | | * @param alarmData |
| | | * @return |
| | | */ |
| | | bool compare(std::thread::id key, AlarmData *alarmData); |
| | | |
| | | FaceResults getTopResult(std::thread::id key); |
| | | |
| | | private: |
| | | /** |
| | | * 加载特征 |
| | | * @param str_config |
| | | */ |
| | | virtual void loadDBData(std::string str_config); |
| | | |
| | | protected: |
| | |
| | | std::string m_tableName; |
| | | |
| | | int fea_size; |
| | | // 保护父类的dataMap |
| | | RWLock m_rwLock; |
| | | std::mutex topResultMtx; |
| | | std::map<std::thread::id, FaceResults> topResult; |
| | | |
| | | // 保护m_dbRWLocks |
| | | RWLock m_dbRWLocks_Lock; |
| | | // 保护 topResult |
| | | std::map<std::thread::id, RWLock> m_dbRWLocks; |
| | | |
| | | ErlangTool::ErlangDbTool *m_erlangDbTool; |
| | |
| | | |
| | | static bool getRet(std::string startTime, std::string endTime) { |
| | | auto crrentTime = AppUtil::getTimeSecString(); |
| | | |
| | | if (crrentTime.compare(startTime) > 0 && (crrentTime.compare(endTime) < 0 || endTime == "0000-00-00 00:00:00")) { |
| | | // 根据当前时间是否在设置的时间内或永久生效 |
| | | if (crrentTime.compare(startTime) > 0 && (crrentTime.compare(endTime) < 0 |
| | | || endTime == "0000-00-00 00:00:00")) { |
| | | return true; |
| | | } |
| | | return false; |
| | |
| | | } |
| | | |
| | | //#todo 优化 |
| | | /** |
| | | * |
| | | * @param feature 需要对比的特征 |
| | | * @param info_json 需要插入数据库的json字段 |
| | | * @param topN 获取前几位 |
| | | * @param score 对比的阈值 |
| | | * @return |
| | | */ |
| | | ::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) + " :"); |
| | | 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(); |
| | | // 特征转化为base64存入到json中 |
| | | 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 |
| | | // 遍历不同的底库进行比对 |
| | | 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) { |
| | | string t_alarmRet = t_tableInfo.bwType; |
| | |
| | | //#todo 非同步库是否需要比较? |
| | | |
| | | DBG("m_faceFCMAP compare start " << it.first); |
| | | // 对比 |
| | | t_FaceFC->compare(key, &featureData, topN); |
| | | DBG("m_faceFCMAP compare end " << it.first); |
| | | |
| | | // 根据当前线程id获取对比结果 |
| | | auto t_results = t_FaceFC->getTopResult(key); |
| | | // 对比结果转换 |
| | | for (auto &t_item : t_results) { |
| | | t_item.tableName = it.first; |
| | | t_item.alarmRet = t_alarmRet; |
| | |
| | | |
| | | 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(); |
| | |
| | | ERR("topResult is null"); |
| | | } |
| | | auto itTR(rtTR.base()); |
| | | // 数据转化 |
| | | ::FaceSearch::FaceResult t_faceCR; |
| | | t_faceCR.id = itor->id; |
| | | t_faceCR.uuid = itor->uuid; |
| | |
| | | results.insert(itTR, t_faceCR); |
| | | } |
| | | bool retface = true; |
| | | // cout << __FUNCTION__ << " -> " << __LINE__ << " -> " << results.size() << endl; |
| | | //#todo send message |
| | | if (results.size() > 0) { |
| | | // 根据传入的对比阈值做筛选 |
| | | // 本分支只保存了第一个对比结果 |
| | | for (auto &item : results) { |
| | | //#todo 得分比较,应该在compare中进行 |
| | | if (item.confidence < score) { |
| | |
| | | break; |
| | | } |
| | | value["personId"] = item.uuid.size() > 0 ? item.uuid : "";//关联底库人员id,人脸id |
| | | |
| | | // string tmp_tableName = item.tableName; |
| | | // if (tmp_tableName.find("lt_") == 0) { |
| | | // tmp_tableName = tmp_tableName.insert(tmp_tableName.find("lt_") + 3, "::"); |
| | | // value["BaseName"] = tmp_tableName;//关联底库表名 |
| | | // } else { |
| | | // value["BaseName"] = item.tableName.size() > 0 ? item.tableName : "";//关联底库表名 |
| | | // } |
| | | |
| | | value["BaseName"] = item.tableName.size() > 0 ? item.tableName : "";//关联底库表名 |
| | | |
| | | value["likePer"] = item.confidence > 0 ? item.confidence : 0.0; |
| | |
| | | value["personIsHub"] = item.alarmRet.size() > 0 ? item.alarmRet : "4"; |
| | | |
| | | auto str_uuid = value["Id"].asString(); |
| | | // DBG(value.toStyledString()); |
| | | |
| | | cout << __FUNCTION__ << " -> " << __LINE__ << " -> " << "value.toStyledString() " |
| | | << value.toStyledString() << "\n score " << score << endl; |
| | | DBG("value.toStyledString() " << value.toStyledString() << "\n score " << score); |
| | | // DBG("score " << score); |
| | | retface = pManagerEsDB.insertData("videopersons", "perVideoPicture", value.toStyledString(), |
| | | str_uuid); |
| | |
| | | value["personIsHub"] = "4"; |
| | | value["likePer"] = 0.0; |
| | | DBG(value.toStyledString()); |
| | | // cout << __FUNCTION__ << " -> " << __LINE__ << " -> " << "value.toStyledString() " |
| | | // << value.toStyledString() << endl; |
| | | retface = pManagerEsDB.insertData("videopersons", "perVideoPicture", value.toStyledString(), |
| | | str_uuid); |
| | | } |
| | | if (!retface) { |
| | | ERR("insert error"); |
| | | } else { |
| | | cout << __FUNCTION__ << " -> " << __LINE__ << " -> " << "retface " << retface << endl; |
| | | ERR("retface " << retface); |
| | | }; |
| | | } else { |
| | | ERR("json is error" << info_json); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | // for (auto &item : t_tables) { |
| | | // DBG(item); |
| | | // } |
| | | return results; |
| | | } |
| | | |
| | | bool FaceFeatureSearchServerI::loadFeatureData(FaceFeatureSearchServerI *faceFea) { |
| | | // 加载底库数据 |
| | | ErlangTool::map_TabDataCache dataBaseCache = faceFea->m_erlangDbTool.findAllDatabase(); |
| | | if (dataBaseCache.size() < 0 && faceFea->m_retUpdatePthread) { |
| | | // 这里进不来吧? |
| | | faceFea->m_retUpdatePthread = false; |
| | | //控制下方线程只启动一次 |
| | | std::thread thd(dataUpdate, faceFea); |
| | | thd.detach(); |
| | | } |
| | | // 获取表信息 |
| | | auto typeInfoCache = faceFea->m_erlangDbTool.findAllTypeInfo(); |
| | | //清除旧数据 |
| | | faceFea->m_tableType.clear(); |
| | | string str_config = faceFea->m_erlangDbTool.getConfigJsonString(); |
| | | |
| | |
| | | faceFea->m_inTime = getTimeLong(); |
| | | if (faceFea->m_retUpdatePthread) { |
| | | faceFea->m_retUpdatePthread = false; |
| | | //控制下方线程只启动一次 |
| | | std::thread thd(dataUpdate, faceFea); |
| | | |
| | | // faceFea->m_erlangDbTool.test(faceFea, erlangCallBackFunc); |
| | |
| | | // pthread_mutex_unlock(&(func_cond_mutex)); |
| | | //} |
| | | |
| | | /** |
| | | * 等待底库加载完成,并等待信号触发新的数据刷新 |
| | | * @param faceFea |
| | | */ |
| | | void FaceFeatureSearchServerI::dataUpdate(FaceFeatureSearchServerI *faceFea) { |
| | | long inTime = faceFea->m_inTime; |
| | | // modify all db ready start update, <10s |
| | |
| | | //}; |
| | | |
| | | static bool t_live_ret = true; |
| | | |
| | | //全局的信号量,如果数据刷新延迟过高可以改为使用nsq消息队列。 |
| | | static pthread_cond_t func_cond(PTHREAD_COND_INITIALIZER); |
| | | static pthread_mutex_t func_cond_mutex(PTHREAD_MUTEX_INITIALIZER); |
| | | |
| | |
| | | virtual ~FaceFeatureSearchServerI(); |
| | | |
| | | public: |
| | | /** |
| | | * @deprecated |
| | | * @return |
| | | */ |
| | | virtual ::FaceSearch::FaceResults faceSearchMax(const ::FaceSearch::Data &, const ::std::string &, |
| | | const ::Ice::Current & = ::Ice::emptyCurrent); |
| | | |
| | | /*** |
| | | * 对比获取第n大的人员 |
| | | * @return |
| | | */ |
| | | virtual ::FaceSearch::FaceResults |
| | | faceSearchTopN(const ::FaceSearch::Data &, const ::std::string &, ::Ice::Int, ::Ice::Float, |
| | | const ::Ice::Current & = ::Ice::emptyCurrent); |
| | | |
| | | private: |
| | | /** |
| | | * @deprecated |
| | | * @param nodeName |
| | | * @param cookie |
| | | * @return |
| | | */ |
| | | bool initErlang(std::string nodeName, std::string cookie); |
| | | |
| | | //#todo delete cache |
| | | |
| | | //#todo loadData |
| | | /** |
| | | * 加载人脸属性 |
| | | * @param faceFea |
| | | * @return |
| | | */ |
| | | static bool loadFeatureData(FaceFeatureSearchServerI *faceFea); |
| | | |
| | | /** |
| | | * 数据更新线程,有信号触发才会更新 |
| | | * @param faceFea |
| | | */ |
| | | static void dataUpdate(FaceFeatureSearchServerI *faceFea); |
| | | |
| | | /*** |
| | | * 等待底库表加载成功 |
| | | * @param faceFea |
| | | * @param loop |
| | | */ |
| | | static void waitTables(FaceFeatureSearchServerI *faceFea, int loop = -1); |
| | | |
| | | // void erlangCallBackFunc(std::string); |
| | | |
| | | private: |
| | | long m_inTime; |
| | | // 特征对比类 |
| | | std::map<std::string, FaceDBCompareServer *> m_faceFCMAP; |
| | | // 底库类型,生效时间等 |
| | | std::map<std::string, TableInfo> m_tableType; |
| | | |
| | | // 对 m_faceFCMAP 加读写锁 |
| | | // 当对比时,数据刷新会等待 |
| | | RWLock m_rwLock; |
| | | |
| | | ErlangTool::ErlangDbTool m_erlangDbTool; |
| | | |
| | | SqliteFaceEncap m_sqliteFaceEncap; |
| | | |
| | | std::mutex m_mutex; |
| | | bool m_retUpdatePthread; |
| | | |
| | | Base64 base64; |
| | | // Ice::ObjectPrx base_FaceMemoryData; |
| | | // IceRpcClient<::FaceSearch::FaceMemoryDataPrx> m_faceMemoryClient; |
| | | // ::FaceSearch::FaceMemoryDataPrx serverFaceMemoryData; |
| | | |
| | | // func_cond_mutex(PTHREAD_MUTEX_INITIALIZER), func_cond(PTHREAD_COND_INITIALIZER) |
| | | |
| | | EsDBTool pManagerEsDB;//(appPref.getStringData("ipAdd"), appPref.getIntData("ipPort")); |
| | | }; |
| | |
| | | #include <zconf.h> |
| | | #include <opencv2/opencv.hpp> |
| | | #include "FFmpegDecoderJPG.h" |
| | | #include <cstring> |
| | | |
| | | void BASICGB28181::initFFmpeg() { |
| | | av_register_all(); |
| | |
| | | // BASICGB28181::avframe_to_cvmat(frame).copyTo(p_this->m_image); |
| | | p_this->m_image = std::move(BASICGB28181::avframe_to_cvmat(p_this->frame)); |
| | | if(p_this->m_image.empty()) { |
| | | ERR("camID:" << p_this->m_camIdx << " frameW:" << p_this->frame->width << "frame.data.len" << strlen(p_this->frame->data[0])); |
| | | ERR("camID:" << p_this->m_camIdx << " frameW:" << p_this->frame->width); |
| | | continue; |
| | | } |
| | | // else { |
| | | // static int count =0; |
| | | // count ++; |
| | | // if(count > 100){ |
| | | // ERR("camID:" << p_this->m_camIdx << " cols:" << p_this->m_image.cols <<\ |
| | | // " rows:" << p_this->m_image.rows << " channels:" << p_this->m_image.channels()); |
| | | // count = 0; |
| | | // } |
| | | // |
| | | // } |
| | | // 将i帧保存为快照 |
| | | if (p_this->m_SnapshotNotSaveRet && (p_this->pkt.flags & AV_PKT_FLAG_KEY)) { |
| | | try { |
| | |
| | | #endif |
| | | //触发上层信号 |
| | | gSignalLock.emitSigal(p_this->m_camIdx + "DecoderImageOK"); |
| | | // DBG("emitSigal: " << p_this->m_camIdx); |
| | | //#ifdef TestCode |
| | | // DBG("emitSigal(\"DecoderImageOK\") after"); |
| | | //#endif |
| | |
| | | |
| | | bool BASICGB28181::FFmpegDecoderJPG::stopThd() { |
| | | TryCath( |
| | | DBG(m_camIdx << " FFmpegDecoderJPG stopThd ... " << m_camIdx); |
| | | DBG("FFmpegDecoderJPG stopThd ... " << m_camIdx); |
| | | m_running = false; |
| | | ); |
| | | return true; |
| | |
| | | if (!m_packetsVec.empty()) { |
| | | auto iter = m_packetsVec.begin(); |
| | | while (iter->m_frameId < lastFrameId) { |
| | | INFO("DropFrame: " << iter->m_frameId); |
| | | // INFO("DropFrame: " << iter->m_frameId); |
| | | delete iter->m_packet.data; |
| | | iter = m_packetsVec.erase(iter); |
| | | } |
| | |
| | | |
| | | bool BASICGB28181::FFmpegDecoderJPG::SaveVideo(std::string path, int64_t lastFrameId) { |
| | | std::lock_guard<std::mutex> lock(g_mutex); |
| | | INFO("SaveVideo: " << path << "m_packetsVec.size : " << m_packetsVec.size()); |
| | | // INFO("SaveVideo: " << path << "m_packetsVec.size : " << m_packetsVec.size()); |
| | | if (!m_packetsVec.empty()) { |
| | | startWrite(path.c_str()); |
| | | int64_t firstKeyFramePts = m_packetsVec[0].m_packet.pts; |
| | |
| | | unsigned long int frame_index = 0; |
| | | for (const auto &item:m_packetsVec) { |
| | | if (item.m_frameId < lastFrameId) { |
| | | DBG("item.m_frameId < lastFrameId " << item.m_frameId << " " << lastFrameId); |
| | | // DBG("item.m_frameId < lastFrameId " << item.m_frameId << " " << lastFrameId); |
| | | conversion(const_cast<AVPacket *> (&item.m_packet), firstKeyFramePts, firstKeyFrameDts, video_st, |
| | | frame_index); |
| | | frame_index++; |
| | |
| | | AVPacket *pkg = static_cast<AVPacket *>(packet); |
| | | |
| | | |
| | | DBG("frame_index==%d\n" << frame_index); |
| | | // DBG("frame_index==\n" << frame_index); |
| | | //Write PTS |
| | | AVRational time_base1 = inStream->time_base; |
| | | //Duration between 2 frames (us) |
| | |
| | | DBG("waitSignal(\"DecoderImageOK\") begin"); |
| | | #endif |
| | | //等待信号触发 |
| | | // DBG("waitSignal before: " << p_this->m_chanPubID); |
| | | gSignalLock.waitSignal(p_this->m_chanPubID + "DecoderImageOK"); |
| | | // DBG("waitSignal: " << p_this->m_chanPubID); |
| | | #ifdef TestCode |
| | | DBG("waitSignal(\"DecoderImageOK\") after"); |
| | | #endif |
| | | { |
| | | if (p_this->m_publishVideoRet) { |
| | | if (p_this->videoPublishElement == nullptr) { |
| | | string path = appConfig.getStringProperty("srsAddr") + "cam" + p_this->m_chanPubID + ".flv"; |
| | | cv::Size size_(appConfig.getIntProperty("pulish.width"), appConfig.getIntProperty("pulish.height")); |
| | | int gupIdx = appPref.getIntData("gpu.index"); |
| | | DBG("videoPublishpath: " << p_this->m_chanPubID << path << " h:" << size_.height); |
| | | p_this->videoPublishElement = new ffmpeg::VideoPublishElement(path, size_, "flv", 25, gupIdx); |
| | | p_this->videoPublishElement->start(); |
| | | } else { |
| | | // DBG("videoPublishElement->setImage() : " << p_this->m_chanPubID); |
| | | if (!p_this->m_image.empty()) { |
| | | p_this->videoPublishElement->setImage(p_this->m_image); |
| | | } else { |
| | | ERR("m_image.empty()"); |
| | | } |
| | | } |
| | | } else { |
| | | if (p_this->videoPublishElement != nullptr) { |
| | | DBG("videoPublishElement->stop() :" << p_this->m_chanPubID); |
| | | p_this->videoPublishElement->stop(); |
| | | p_this->videoPublishElement->wait(); |
| | | delete p_this->videoPublishElement; |
| | | p_this->videoPublishElement = nullptr; |
| | | }else{ |
| | | // DBG("videoPublishElement null :" << p_this->m_chanPubID); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /****录像模块代码*****/ |
| | | p_this->m_picCount++; |
| | | //几张选一张放入Redis |
| | | if (p_this->m_picCount % m_nPicsPickOne != 0) { |
| | | continue; |
| | | } else { |
| | | p_this->m_picCount.store(0); |
| | | } |
| | | |
| | | // 从ffmpeg解码类中获取图片 |
| | | p_this->m_fFmpegDecoderJPG.getImage().copyTo(p_this->m_image); |
| | | /****debug*****///todo |
| | | if (p_this->m_image.empty()) { |
| | | ERR("camID:" << p_this->m_chanPubID); |
| | | continue; |
| | | } |
| | | // else { |
| | | // static int count =0; |
| | | // count ++; |
| | | // if(count > 100){ |
| | | // ERR("camID:" << p_this->m_chanPubID << " cols:" << p_this->m_image.cols <<\ |
| | | // " rows:" << p_this->m_image.rows << " channels:" << p_this->m_image.channels()); |
| | | // count = 0; |
| | | // } |
| | | // } |
| | | |
| | | { |
| | | /****录像模块代码*****/ |
| | | p_this->m_picCount++; |
| | | //几张选一张放入Redis |
| | | if (p_this->m_picCount % m_nPicsPickOne != 0) { |
| | | continue; |
| | | } else { |
| | | p_this->m_picCount.store(0); |
| | | } |
| | | cv::Mat copyMat; |
| | | std::string imageName = p_this->m_fFmpegDecoderJPG.GetImageName(); |
| | | p_this->m_image.copyTo(copyMat); |
| | |
| | | } else { |
| | | |
| | | // 根据reopenTime判断是否需要重启 |
| | | if (reopenTime < 0) { |
| | | if (p_this->reopenTime < 0) { |
| | | p_this->m_running = false; |
| | | stop(); |
| | | INFO("grabFrame faild, element stopping"); |
| | | break; |
| | | } else { |
| | | //todo 业务死锁 |
| | | usleep((6 - reopenTime--) * 1000000); |
| | | INFO("grabFrame faild, try reopen video: "); |
| | | usleep((6 - p_this->reopenTime--) * 1000000); |
| | | INFO("grabFrame faild, try reopen video, reopenTime:" << p_this->reopenTime); |
| | | |
| | | //关闭ffmpeg解码模块 |
| | | p_this->m_fFmpegDecoderJPG.stopThd(); |
| | | //启动ffmpeg解码模块 |
| | | DBG("m_chanPubID:"<<p_this->m_chanPubID << " m_fps:" << p_this->m_fps); |
| | | p_this->m_fFmpegDecoderJPG.startThd(p_this->m_chanPubID, p_this->m_fps, p_this->m_gpuIdx); |
| | | continue; |
| | | } |
| | |
| | | |
| | | void BASICGB28181::VideoCaptureElementWithRtp::threadFunc() { |
| | | |
| | | if (m_publishVideoRet) { |
| | | if (videoPublishElement == nullptr) { |
| | | string path = appConfig.getStringProperty("srsAddr") + "cam" + m_chanPubID + ".flv"; |
| | | cv::Size size_(appConfig.getIntProperty("pulish.width"), appConfig.getIntProperty("pulish.height")); |
| | | int gupIdx = appPref.getIntData("gpu.index"); |
| | | videoPublishElement = new ffmpeg::VideoPublishElement(path, size_, "flv", 25, gupIdx); |
| | | } else { |
| | | videoPublishElement->stop(); |
| | | videoPublishElement->wait(); |
| | | delete videoPublishElement; |
| | | videoPublishElement = nullptr; |
| | | } |
| | | } |
| | | |
| | | fireConnectors(); |
| | | } |
| | | |
| | |
| | | |
| | | void BASICGB28181::VideoCaptureElementWithRtp::SaveVideo(const std::string &strImageName) { |
| | | |
| | | INFO("SaveVideo: " << strImageName); |
| | | // INFO("SaveVideo: " << strImageName); |
| | | std::string strTimeStamp = AppUtil::getTimeUSecString(); |
| | | std::string strPath = MakeDir(strTimeStamp); |
| | | m_fFmpegDecoderJPG.SaveVideoByImageName(strPath, strImageName); |
| | |
| | | //用来保存录像视频的路径 |
| | | std::string m_cutPath; |
| | | std::atomic<bool> m_publishVideoRet{false}; |
| | | ffmpeg::VideoPublishElement * videoPublishElement; |
| | | ffmpeg::VideoPublishElement * videoPublishElement{nullptr}; |
| | | private: |
| | | /*** |
| | | * 启动实时流接收数据线程 |
| | |
| | | return "tableName is NULL"; |
| | | } |
| | | // 人员信息表 |
| | | //ALTER TABLE '0cd82a8b-5285-5737-ab19-8c07247c797e' ADD COLUMN uploadFlag varchar(255) DEFAULT 0; |
| | | //ALTER TABLE '0cd82a8b-5285-5737-ab19-8c07247c797e' ADD COLUMN cmpThreshold varchar(255) DEFAULT 60; |
| | | //ALTER TABLE '0cd82a8b-5285-5737-ab19-8c07247c797e' ADD COLUMN enabled varchar(255) DEFAULT 1; |
| | | //ALTER TABLE '0cd82a8b-5285-5737-ab19-8c07247c797e' ADD COLUMN monitorLevel varchar(255) DEFAULT 0; |
| | | std::string sql = "CREATE TABLE " + g_dbName + ".'"; |
| | | sql.append(tableName); |
| | | sql.append("' ( uuid varchar(255) PRIMARY KEY,"); |
| | |
| | | sql.append("create_by varchar(255) DEFAULT NULL,"); |
| | | sql.append("del_flag INTEGER DEFAULT 0,"); |
| | | sql.append("monitorLevel varchar(255) DEFAULT 0,"); |
| | | sql.append("uploadFlag varchar(255) DEFAULT 0,"); |
| | | sql.append("cmpThreshold varchar(255) DEFAULT 60,"); |
| | | sql.append("enabled varchar(255) DEFAULT 1"); |
| | | sql.append(");"); |
| | | // 人脸特征表 |
| | |
| | | // TimerElement(1), |
| | | triggerState(false), |
| | | tolerance(tolerance), delay(delay), |
| | | triggerType(DOWN), triggerTimes(0),lastDown(0),lastUp(0) { |
| | | triggerType(DOWN), triggerTimes(0), lastDown(0), lastUp(0) { |
| | | |
| | | } |
| | | |
| | |
| | | lastDown = 0; |
| | | triggerType = DOWN; |
| | | } |
| | | void TriggerElement::resetTriggerState() |
| | | { |
| | | |
| | | void TriggerElement::resetTriggerState() { |
| | | |
| | | //state=false; |
| | | triggerState=false; |
| | | triggerTimes=0; |
| | | triggerState = false; |
| | | triggerTimes = 0; |
| | | } |
| | | |
| | | void TriggerElement::timerFunc() { |
| | |
| | | perHubElement(ruleMap[PerHubSdk]), |
| | | leftJudgment(ruleMap[KeepRightSdk]), |
| | | rightJudgment(ruleMap[KeepRightSdk]), |
| | | bRecordVideoEnable(RecordVideoEnable), |
| | | // bRecordVideoEnable(RecordVideoEnable), |
| | | m_sdkRuleMap(ruleMap), |
| | | m_bSetWH(false) { |
| | | DBG("camId" << camId); |
| | |
| | | //#todo |
| | | faceRpcElement.setProperty("time", strNewTime); |
| | | faceRpcElement.setProperty("imgKey", imgKey); |
| | | INFO("Write To FaceRPC ES time:" << strNewTime << " ImgKey: " << imgKey); |
| | | // INFO("Write To FaceRPC ES time:" << strNewTime << " ImgKey: " << imgKey); |
| | | faceRpcElement.setImage(imageTemp); |
| | | faceRpcElement.submit(); |
| | | } |
| | |
| | | //#todo |
| | | yoloRpcElement.setProperty("time", strNewTime); |
| | | yoloRpcElement.setProperty("imgKey", imgKey); |
| | | INFO("Write To YoloES time:" << strNewTime << " ImgKey: " << imgKey); |
| | | // INFO("Write To YoloES time:" << strNewTime << " ImgKey: " << imgKey); |
| | | yoloRpcElement.setImage(imageTemp); |
| | | yoloRpcElement.submit(); |
| | | } |
| | |
| | | #else |
| | | vptRpcElement.registerConnector([&] { |
| | | if (!perimeterElement.isBusy()) { |
| | | perimeterElement.setYoloObjects(vptRpcElement.getLastHpRects()); |
| | | perimeterElement.setYoloObjects(vptRpcElement.getLastScoreRects()); |
| | | perimeterElement.setImage(vptRpcElement.getImage()); |
| | | perimeterElement.submit(); |
| | | } |
| | |
| | | ../../../BasicPlatForm/basic/util/curl/HttpRequestWithCrul.hpp |
| | | ../../../BasicPlatForm/basic/util/net_config/net_config.cpp |
| | | ../../../BasicPlatForm/basic/timer_counter/Clocktimer.cpp |
| | | |
| | | ) |
| | | |
| | | SET(LIBS |
| | |
| | | } |
| | | |
| | | void FaceExtractElement::timerFunc() { |
| | | INFO("MYH Run Here"); |
| | | // INFO("MYH Run Here"); |
| | | std::vector<FaceToExtract> faceExtractQueueTmp; |
| | | { |
| | | std::lock_guard<std::mutex> lg(imageQueueMutex); |
| | | if (faceExtractQueue.empty()) { |
| | | ERR("faceExtractQueue.empty "); |
| | | // ERR("faceExtractQueue.empty "); |
| | | return; |
| | | } |
| | | faceExtractQueueTmp.swap(faceExtractQueue); |
| | |
| | | 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; |
| | | |
| | |
| | | |
| | | 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], |
| | | auto feature = extractServer->faceExtract(image.cols, image.rows, faceExtractQueueTmp[i].facesPos[j], |
| | | sharedMemory->key().toStdString()); |
| | | // { |
| | | // //#todo |
| | |
| | | // cv::imwrite(string1, image); |
| | | // } |
| | | if (feature.empty()) { |
| | | INFO("No Face Find: " << getProperty("imgKey")); |
| | | // INFO("No Face Find: " << getProperty("imgKey")); |
| | | continue; |
| | | } |
| | | features.clear(); |
| | |
| | | std::string strImgUrlTmp = ""; |
| | | fdfsClient->fastFds->uploadFile(buffer, strImgUrlTmp, "jpg"); |
| | | // strImgUrl.append(fdfsClient->fastFds->getIp() + "/" + strImgUrlTmp); |
| | | DBG("strImgUrlTmp=" << strImgUrlTmp); |
| | | // DBG("strImgUrlTmp=" << strImgUrlTmp); |
| | | strImgUrl.clear(); |
| | | strImgUrl = strImgUrlTmp; |
| | | // strImgUrl.append("/").append(strImgUrlTmp); |
| | |
| | | } |
| | | |
| | | void FaceRpcElement::threadFunc() { |
| | | INFO("MYH Run Here"); |
| | | // INFO("MYH Run Here"); |
| | | // ClockTimer ct("FaceRpcElement::threadFunc"); |
| | | // { |
| | | // |
| | |
| | | CvUtil::zoomRectEqual(scoredRect.rect, 1.5, 1.5) & cv::Rect(0, 0, image.cols, image.rows)).clone()); |
| | | triggerScoredRects.push_back(trackingTrigger->getLastRect()); |
| | | } else { |
| | | INFO("No Face Find: " << getProperty("imgKey")); |
| | | // INFO("No Face Find: " << getProperty("imgKey")); |
| | | // DBG("trackingTrigger->triggerOnce(scoredRect) is false "); |
| | | } |
| | | } |
| | | if (faces.empty()) { |
| | | INFO("No Face Find: " << getProperty("imgKey")); |
| | | // INFO("No Face Find: " << getProperty("imgKey")); |
| | | } |
| | | trackingTrigger->triggerLine(); |
| | | // DBG("faces.size " << faces.size()); |
| | |
| | | #include <jsoncpp/json/json.h> |
| | | |
| | | #define ALARM_PERCENT (25) //25% |
| | | |
| | | PerimeterElement::PerimeterElement(const SdkRule &rule) : |
| | | m_sdkRule(rule), |
| | | PipeElement(true), |
| | | trackingTrigger(nullptr), |
| | | mRealNum(0), |
| | | //每秒几张,就乘以几 |
| | | m_triggerElement(rule.nTriggerDelay*3,0), |
| | | m_triggerElement(rule.nTriggerDelay * 3, 0), |
| | | pManagerEsDB(nullptr), |
| | | m_bIsMask(true), |
| | | m_bSetWH(false), |
| | | pointArray(nullptr), |
| | | m_rpcClient("RtspAnalysServer", "127.0.0.1",appPref.getIntData("RpcVTIMPort"),"tcp") |
| | | { |
| | | m_rpcClient("RtspAnalysServer", "127.0.0.1", appPref.getIntData("RpcVTIMPort"), "tcp") { |
| | | |
| | | pManagerEsDB = new EsDBTool(appPref.getStringData("ipAdd"), appPref.getIntData("ipPort")); |
| | | } |
| | |
| | | delete pManagerEsDB; |
| | | pManagerEsDB = nullptr; |
| | | } |
| | | if(pointArray) |
| | | { |
| | | if (pointArray) { |
| | | // delete[] pointArray[0]; |
| | | delete[] pointArray; |
| | | } |
| | |
| | | bool state = false; |
| | | |
| | | m_recVec.clear(); |
| | | //todo debug |
| | | m_scoreVec.clear(); |
| | | m_objTypeVec.clear(); |
| | | |
| | | // DBG("Objs="<<mObjs.size()<<" fSensitivity="<<m_sdkRule.fSensitivity<<" nThreshold"<<m_sdkRule.nThreshold); |
| | | |
| | | for (auto obj:mObjs) { |
| | | for (auto &obj:mObjs) { |
| | | |
| | | if (obj.score < m_sdkRule.fSensitivity)continue; |
| | | DBG("objArea:" << obj.rect.width * obj.rect.height); |
| | | DBG("alarmObjType:" << obj.properties["type"]); |
| | | |
| | | QRect rect(obj.rect.x, obj.rect.y, obj.rect.width, obj.rect.height); |
| | | QPoint center = rect.center(); |
| | |
| | | // DBG("picDate="<<picDate); |
| | | |
| | | } |
| | | if(imgKey.empty()) |
| | | { |
| | | imgKey =obj.properties["imgKey"]; |
| | | if (imgKey.empty()) { |
| | | imgKey = obj.properties["imgKey"]; |
| | | } |
| | | if (m_sdkRule.nSdkType == PerimeterSdk) |
| | | { |
| | | |
| | | if(m_bIsMask) |
| | | if (m_sdkRule.nSdkType == PerimeterSdk) { |
| | | //todo 解析sdkrule 并和检测结果对比 |
| | | if (m_sdkRule.strPerimeterObjType.toStdString().find(obj.properties["type"]) == |
| | | m_sdkRule.strPerimeterObjType.toStdString().npos)//页面没有配置了该算法 |
| | | { |
| | | 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); |
| | | continue; |
| | | } |
| | | |
| | | if(ALARM_PERCENT <= per) |
| | | { |
| | | //DBG("per 1="<<per1<<" per2="<<per2<<" per="<<per); |
| | | m_recVec.push_back(obj.rect); |
| | | num++; |
| | | } |
| | | 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); |
| | | m_scoreVec.push_back(obj.score); |
| | | m_objTypeVec.push_back(obj.properties["type"]); |
| | | num++; |
| | | DBG("============alarmObjType:" << obj.properties["type"] << " score:" << obj.score); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | else if (mPolygon.containsPoint(center, Qt::OddEvenFill) || !m_bIsMask) |
| | | { |
| | | } else if (mPolygon.containsPoint(center, Qt::OddEvenFill) || !m_bIsMask) { |
| | | m_recVec.push_back(obj.rect); |
| | | |
| | | |
| | | num++; |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | switch (m_sdkRule.nSdkType) { |
| | | case PerimeterSdk: |
| | | //state = num > 0 ; |
| | | state =( num !=mRealNum); |
| | | // DBG("num="<<num<< "time="<< picDate); |
| | | INFO("SDK Type: PerimeterSdk"); |
| | | state = (num != mRealNum); |
| | | // DBG("num="<<num<< "time="<< picDate); |
| | | // INFO("SDK Type: PerimeterSdk"); |
| | | |
| | | break; |
| | | case CrowdSdk: |
| | | state = num > m_sdkRule.nAlarmNumLowerLimit && num !=mRealNum; |
| | | INFO("SDK Type: CrowdSdk"); |
| | | state = num > m_sdkRule.nAlarmNumLowerLimit && num != mRealNum; |
| | | // INFO("SDK Type: CrowdSdk"); |
| | | |
| | | break; |
| | | case PerHubSdk: |
| | | state = num > m_sdkRule.nAlarmNumLowerLimit && num < m_sdkRule.nAlarmNumUpperLimit && num !=mRealNum; |
| | | INFO("SDK Type: PerHubSdk"); |
| | | state = num > m_sdkRule.nAlarmNumLowerLimit && num < m_sdkRule.nAlarmNumUpperLimit && num != mRealNum; |
| | | // INFO("SDK Type: PerHubSdk"); |
| | | |
| | | // if(m_sdkRule.nAlarmNumLowerLimit>=0) |
| | | // { |
| | |
| | | default: |
| | | break; |
| | | } |
| | | INFO("State:"<<state<<" Num:"<<num<<" mRealNum:"<<mRealNum<<" LowerLimit :"<<m_sdkRule.nAlarmNumLowerLimit<<" HightLimit: "<<m_sdkRule.nAlarmNumUpperLimit); |
| | | INFO("State:" << state << " Num:" << num << " mRealNum:" << mRealNum << " LowerLimit :" |
| | | << m_sdkRule.nAlarmNumLowerLimit << " HightLimit: " << m_sdkRule.nAlarmNumUpperLimit |
| | | << " m_triggerElement.getTriggerState() :" << m_triggerElement.getTriggerState()); |
| | | m_triggerElement.setState(state); |
| | | m_triggerElement.triggerOnce(); |
| | | if (m_triggerElement.getTriggerState()) |
| | | { |
| | | if(num > 0) { |
| | | if(pointArray!=nullptr) |
| | | { |
| | | const cv::Point2i* ppt[1] = { pointArray }; |
| | | DBG("m_triggerElement.getTriggerState():" << m_triggerElement.getTriggerState()); |
| | | if (m_triggerElement.getTriggerState()) { |
| | | if (num > 0) { |
| | | if (pointArray != nullptr) { |
| | | const cv::Point2i *ppt[1] = {pointArray}; |
| | | |
| | | int npt[]={npts}; |
| | | int npt[] = {npts}; |
| | | |
| | | cv::polylines(image, ppt,npt, 1, true,cv::Scalar(255,255,0), 2); |
| | | cv::polylines(image, ppt, npt, 1, true, cv::Scalar(255, 255, 0), 2); |
| | | } |
| | | |
| | | for(auto rect:m_recVec) |
| | | { |
| | | cv::rectangle(image, rect, cv::Scalar(0, 0, 255), 2); |
| | | // for(auto rect:m_recVec) |
| | | // { |
| | | // cv::rectangle(image, rect, cv::Scalar(0, 0, 255), 2); |
| | | // } |
| | | for (int i = 0; i < m_recVec.size(); i++) { |
| | | cv::rectangle(image, m_recVec[i], cv::Scalar(0, 0, 255), 2); |
| | | cv::putText(image, to_string(m_scoreVec[i]), cv::Point(m_recVec[i].x, m_recVec[i].y + 12), |
| | | cv::HersheyFonts::FONT_HERSHEY_PLAIN, 1.5, cv::Scalar(255, 255, 0)); |
| | | cv::putText(image, m_objTypeVec[i], cv::Point(m_recVec[i].x, m_recVec[i].y + 24), |
| | | cv::HersheyFonts::FONT_HERSHEY_PLAIN, 1.5, cv::Scalar(255, 255, 0)); |
| | | } |
| | | // cv::Mat t_image = image(CutMask()).clone(); |
| | | // if(t_image.empty()) |
| | |
| | | // return; |
| | | // } |
| | | std::string imgUrl = uploadImgToFdfs(image); |
| | | saveInfoToEs(imgUrl, picDate,imgKey); |
| | | saveInfoToEs(imgUrl, picDate, imgKey); |
| | | } |
| | | DBG("num=" << num << " lastnum=" << mRealNum); |
| | | mRealNum = num; |
| | |
| | | void PerimeterElement::setMask(std::string mask) { |
| | | QJsonArray arrayAreas = getJsonArrayFromQString(QString::fromStdString(mask)); |
| | | if (arrayAreas.isEmpty() && m_sdkRule.nSdkType != PerimeterSdk) { |
| | | m_bIsMask=false; |
| | | m_bIsMask = false; |
| | | return;//do not detect |
| | | } |
| | | int size = arrayAreas.size(); |
| | | npts = size; |
| | | float sizeW=(float)appPref.getIntData(m_sdkRule.strCamId.toStdString()+"width")/480; |
| | | float sizeH=(float)appPref.getIntData(m_sdkRule.strCamId.toStdString()+"height")/270; |
| | | pointArray=new cv::Point2i[npts]; |
| | | float sizeW = (float) appPref.getIntData(m_sdkRule.strCamId.toStdString() + "width") / 480; |
| | | float sizeH = (float) appPref.getIntData(m_sdkRule.strCamId.toStdString() + "height") / 270; |
| | | pointArray = new cv::Point2i[npts]; |
| | | for (int i = 0; i < size; ++i) { |
| | | |
| | | QJsonValue jsonValue = arrayAreas[i]; |
| | | QJsonObject obj = jsonValue.toObject(); |
| | | int x = obj.value("x").toDouble() *sizeW; |
| | | int y = obj.value("y").toDouble() *sizeH; |
| | | pointArray[i]={x,y}; |
| | | if(m_sdkRule.nSdkType == PerimeterSdk) |
| | | { |
| | | poly1.push_back(Point(x,y)); |
| | | int x = obj.value("x").toDouble() * sizeW; |
| | | int y = obj.value("y").toDouble() * sizeH; |
| | | pointArray[i] = {x, y}; |
| | | if (m_sdkRule.nSdkType == PerimeterSdk) { |
| | | poly1.push_back(Point(x, y)); |
| | | } else { |
| | | mPolygon << (QPoint(x, y)); |
| | | } |
| | | else |
| | | { |
| | | mPolygon << (QPoint(x, y)); |
| | | } |
| | | DBG("width="<<sizeW); |
| | | DBG("height="<<sizeH); |
| | | // DBG("width="<<sizeW); |
| | | // DBG("height="<<sizeH); |
| | | |
| | | |
| | | } |
| | |
| | | QJsonArray PerimeterElement::getJsonArrayFromQString(const QString &strJson) { |
| | | QJsonDocument jsonDocument = QJsonDocument::fromJson(strJson.toLocal8Bit()); |
| | | if (jsonDocument.isNull()) { |
| | | DBG("please check the string" << strJson.toStdString()); |
| | | ERR("please check the string" << strJson.toStdString()); |
| | | return QJsonArray(); |
| | | } |
| | | QJsonArray jsonArray = jsonDocument.array(); |
| | |
| | | // image = cv::Mat(value.rows, value.cols, CV_8UC3, sharedMemory->data()); |
| | | // } |
| | | value.copyTo(image); |
| | | if(!m_bSetWH) |
| | | { |
| | | if (!m_bSetWH) { |
| | | setMask(m_sdkRule.strAreas.toStdString()); |
| | | m_bSetWH=true; |
| | | m_bSetWH = true; |
| | | } |
| | | |
| | | } |
| | |
| | | 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); |
| | |
| | | return strImgUrl; |
| | | } |
| | | |
| | | bool PerimeterElement::saveInfoToEs(const std::string &imgUrl, const std::string &time,const std::string& imgKey) { |
| | | bool PerimeterElement::saveInfoToEs(const std::string &imgUrl, const std::string &time, const std::string &imgKey) { |
| | | |
| | | string str_uuid; |
| | | uuid_t t_uuid; |
| | |
| | | t_json["ChannlId"] = getProperty("ch_id"); // 通道id |
| | | t_json["likeDate"] = AppUtil::getTimeSecString(); // 比对时间 |
| | | t_json["picAddress"] = m_sdkRule.strAddr.toStdString();// 抓拍地址 |
| | | DBG("picAddress="<<m_sdkRule.strAddr.toStdString()); |
| | | DBG("picAddress=" << m_sdkRule.strAddr.toStdString()); |
| | | t_json["picMaxUrl"] = ""; // 大图路径 |
| | | |
| | | |
| | | // t_json["Age"] ="wait todo"; |
| | | t_json["picDate"] = time; // 抓拍时间,必须有 |
| | | DBG("picDate="<<time); |
| | | DBG("picDate=" << time); |
| | | t_json["picLocalUrl"] = ""; // 本地路径 |
| | | t_json["isDelete"] = "1";//默认1 ,0无效 1有效 |
| | | |
| | |
| | | t_json["imgKey"] = imgKey; |
| | | try { |
| | | auto server = m_rpcClient.getServer(); |
| | | if (!server) |
| | | { |
| | | if (!server) { |
| | | ERR("server is null"); |
| | | //return false; |
| | | } |
| | | INFO("Record Video "<<imgKey); |
| | | INFO("Record Video " << imgKey); |
| | | server->recordVideo(imgKey); |
| | | } |
| | | catch (std::exception &e) |
| | | { |
| | | ERR("Record Video Err: "<<imgKey <<" Message: "<<e.what()); |
| | | catch (std::exception &e) { |
| | | ERR("Record Video Err: " << imgKey << " Message: " << e.what()); |
| | | //return false; |
| | | } |
| | | INFO("SaveImgKeyToES: "<<imgKey); |
| | | INFO("SaveImgKeyToES: " << imgKey); |
| | | bool retface = false; |
| | | if (pManagerEsDB) |
| | | retface = pManagerEsDB->insertData("personaction", "perVideoAction", t_json.toStyledString(), str_uuid); |
| | |
| | | |
| | | |
| | | int npts; |
| | | std::vector<cv::Rect> m_recVec; |
| | | std::vector<cv::Rect> m_recVec; |
| | | |
| | | //todo debug |
| | | std::vector<float> m_scoreVec; |
| | | std::vector<std::string> m_objTypeVec; |
| | | |
| | | |
| | | bool m_bIsMask; |
| | | std::vector<Point> poly1; |
| | |
| | | appPref.getStringData("vpt.ip"), |
| | | appPref.getIntData("vpt.port"), "tcp"), |
| | | m_sharedMemory(nullptr), m_trackingTrigger(nullptr) { |
| | | init(); |
| | | |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | for (auto &obj: m_objs) { |
| | | //#todo 人/人骑车/车 |
| | | if (obj.sdkDetectType != 0) |
| | | continue; |
| | | // //#todo 人/人骑车/车 |
| | | // if (obj.sdkDetectType != 0) |
| | | // continue; |
| | | |
| | | ScoredRect scoredRect; |
| | | |
| | |
| | | m_trackingTrigger->getLastRect().properties["time"] = getProperty("time"); |
| | | m_trackingTrigger->getLastRect().properties["imgKey"] = getProperty("imgKey"); |
| | | m_triggerScoredRects.push_back(m_trackingTrigger->getLastRect()); |
| | | switch (obj.sdkDetectType) { |
| | | case 0 : |
| | | m_HPScoredRects.push_back(m_trackingTrigger->getLastRect()); |
| | | break; |
| | | case 1: |
| | | case 2 : |
| | | m_HCPScoredRects.push_back(m_trackingTrigger->getLastRect()); |
| | | break; |
| | | case 4 : |
| | | case 5 : |
| | | case 6 : |
| | | case 8 : |
| | | m_CarScoredRects.push_back(m_trackingTrigger->getLastRect()); |
| | | break; |
| | | } |
| | | |
| | | } |
| | | } |
| | | m_trackingTrigger->triggerLine(); |
| | | auto res_ = m_trackingTrigger->getLastScoreRects(); |
| | | for (auto &obj: res_) { |
| | | if(obj.properties["type"] == "person") { |
| | | m_HPScoredRects.push_back(obj); |
| | | DBG("person:" << obj.score); |
| | | }else if((obj.properties["type"] == "bike") || |
| | | (obj.properties["type"] == "motor")){ |
| | | m_HCPScoredRects.push_back(obj); |
| | | DBG("bike or moto:" << obj.score); |
| | | }else{ |
| | | m_CarScoredRects.push_back(obj); |
| | | DBG("car:" << obj.score); |
| | | } |
| | | } |
| | | |
| | | fireConnectors(); |
| | | } |
| | | |
| | |
| | | |
| | | try { |
| | | auto server = m_rpcClient.getServer(); |
| | | m_HpResStr = server->getStr(0); // 检测种类 case 0 |
| | | m_HcpResStr = server->getStr(1); // 检测种类 case 1 |
| | | m_TypeStr = server->getStr(2)[0]; // 检测种类 case 2 |
| | | m_HpResStr = server->getStr(0); // 行人二次属性 case 0 |
| | | m_HcpResStr = server->getStr(1); // 人骑车二次属性 case 1 |
| | | m_TypeStr = server->getStr(2)[0]; // VPT检测种类 case 2 |
| | | m_colorLabelStr = server->getStr(3)[0]; // 车牌颜色 case 3 |
| | | } |
| | | catch (std::exception &e) { |
| | |
| | | appPref.setIntData("gpu.index", 0); |
| | | appPref.setIntData("show.image", 0); |
| | | |
| | | //yolo server |
| | | appPref.setStringData("yolo.proxy", "yoloServer"); |
| | | //#todo |
| | | appPref.setStringData("yolo.ip", ""); |
| | | appPref.setIntData("yolo.port", 10003); |
| | | // rpcClient(appPref.getStringData("yolo.proxy"), appPref.getStringData("yolo.ip"), appPref.getLongData("yolo.port"),"tcp"), |
| | | // //yolo server |
| | | // appPref.setStringData("yolo.proxy", "yoloServer"); |
| | | // //#todo |
| | | // appPref.setStringData("yolo.ip", ""); |
| | | // appPref.setIntData("yolo.port", 10003); |
| | | //// rpcClient(appPref.getStringData("yolo.proxy"), appPref.getStringData("yolo.ip"), appPref.getLongData("yolo.port"),"tcp"), |
| | | |
| | | //vpt server |
| | | appPref.setStringData("vpt.proxy", "VptServer"); |
| | | //#todo |
| | | appPref.setStringData("vpt.ip", ""); |
| | | appPref.setIntData("vpt.port", appPref.getIntData("RpcVptPort")); |
| | | |
| | | //face detect server |
| | | appPref.setStringData("faceDete.proxy", "faceServer"); |
| | |
| | | //#todo 使用策略模式?发送端多个指令累积后发送? |
| | | if (itor_json->isString() && reader.parse(itor_json->asString(), cfg_val)) { |
| | | if (itor_json.name() == "cam_edit" || itor_json.name() == "editSdkRule") { |
| | | string cam_idx = cfg_val["str_cam_dev_id"].asString(); |
| | | string cam_idx = ""; |
| | | if(itor_json.name() == "cam_edit"){ |
| | | if (pthis->m_GB28181_Enable){ |
| | | cam_idx = cfg_val["equipCode"].asString(); |
| | | }else{ |
| | | cam_idx = cfg_val["str_cam_dev_id"].asString(); |
| | | } |
| | | } else { |
| | | cam_idx = cfg_val["strCamId"].asString(); |
| | | } |
| | | |
| | | if (pthis->controllers.find(cam_idx) != pthis->controllers.end()) { |
| | | if (pthis->m_GB28181_Enable) { |
| | | auto lst = pthis->m_lDBTool->searchCamDevTableByType(1); |
| | |
| | | } |
| | | } |
| | | } else if (itor_json.name() == "cam_del") { |
| | | string cam_idx = cfg_val["str_cam_dev_id"].asString(); |
| | | // string cam_idx = cfg_val["str_cam_dev_id"].asString(); |
| | | string cam_idx = ""; |
| | | if(cfg_val["equipCode"].asString().size()){ |
| | | cam_idx = cfg_val["equipCode"].asString(); |
| | | }else if(cfg_val["str_cam_dev_id"].asString().size()){ |
| | | cam_idx = cfg_val["str_cam_dev_id"].asString(); |
| | | } |
| | | pthis->removeCamera(cam_idx); |
| | | } |
| | | } else { |
| | |
| | | rule.second.strAddr = item.str_addr; |
| | | rule.second.weekRuleVec = m_lDBTool->searchCameraWeekRuleByCamId(item.str_cam_dev_id, rule.first); |
| | | |
| | | if (rule.second.nSdkType == PerStaticSdk) { |
| | | float temp = 1 - (float) (rule.second.nThreshold) / 100; |
| | | rule.second.fSensitivity = (75 + 25 * temp) / 100; |
| | | // if (rule.second.nSdkType == PerStaticSdk || rule.second.nSdkType == PerimeterSdk |
| | | // || rule.second.nSdkType == KeepRightSdk || rule.second.nSdkType == KeepRightSdk) { |
| | | float temp = (float)1 - (float) (rule.second.nThreshold) / 100; |
| | | rule.second.fSensitivity = (temp * 50 + 50) / 100; |
| | | // rule.second.fSensitivity = (temp * 25 + 75) / 100; |
| | | |
| | | } else if (rule.second.nSdkType != FaceSdk) { |
| | | float temp = 1 - (float) (rule.second.nThreshold) / 100; |
| | | rule.second.fSensitivity = (5 + 90 * temp) / 100; |
| | | } |
| | | // } else if (rule.second.nSdkType != FaceSdk) { |
| | | // float temp = (float)1 - (float) (rule.second.nThreshold) / 100; |
| | | // rule.second.fSensitivity = (temp * 90 + 5) / 100; |
| | | // } |
| | | DBG("fSensitivity" << rule.second.fSensitivity); |
| | | } |
| | | appPref.setStringData(t_camIdex + "rtsp", rtsp_url); |
| | |
| | | appPref.setIntData("gpu.index", atoi(argv[2])); |
| | | appPref.setIntData("CamStartNO", atoi(argv[3])); |
| | | appPref.setIntData("CamEndNO", atoi(argv[4])); |
| | | appPref.setIntData("RpcYOLOPort", atoi(argv[5])); |
| | | appPref.setIntData("RpcVptPort", atoi(argv[5])); |
| | | appPref.setIntData("RpcFDPort", atoi(argv[6])); |
| | | appPref.setIntData("RpcFEPort", atoi(argv[7])); |
| | | appPref.setIntData("RpcFSPort", atoi(argv[8])); |
| | |
| | | appPref.setIntData("ipPort", appConfig.getIntProperty("ES_PORT")); |
| | | |
| | | //yolo server |
| | | appPref.setStringData("yolo.proxy", "yoloServer"); |
| | | //#todo |
| | | appPref.setStringData("yolo.ip", ""); |
| | | appPref.setIntData("yolo.port", appPref.getIntData("RpcYOLOPort")); |
| | | // rpcClient(appPref.getStringData("yolo.proxy"), appPref.getStringData("yolo.ip"), appPref.getLongData("yolo.port"),"tcp"), |
| | | // appPref.setStringData("yolo.proxy", "yoloServer"); |
| | | // //#todo |
| | | // appPref.setStringData("yolo.ip", ""); |
| | | // appPref.setIntData("yolo.port", appPref.getIntData("RpcYOLOPort")); |
| | | //// rpcClient(appPref.getStringData("yolo.proxy"), appPref.getStringData("yolo.ip"), appPref.getLongData("yolo.port"),"tcp"), |
| | | |
| | | //vpt server |
| | | appPref.setStringData("vpt.proxy", "vptServer"); |
| | | //#todo |
| | | appPref.setStringData("vpt.ip", ""); |
| | | appPref.setIntData("vpt.port", appPref.getIntData("RpcVptPort")); |
| | | |
| | | //face detect server |
| | | appPref.setStringData("faceDete.proxy", "faceServer"); |
| | |
| | | strExAreas = ""; |
| | | strLine = ""; |
| | | strAddr = ""; |
| | | strPerimeterObjType = ""; |
| | | } |
| | | |
| | | int nSdkType; |
| | |
| | | int nAlarmNumUpperLimit; //报警人数(人员拥挤) |
| | | int nAlarmNumLowerLimit; |
| | | int nIsRun; |
| | | QString strPerimeterObjType;//入侵类型 |
| | | |
| | | std::vector<LActRuleWeekRecord> weekRuleVec; |
| | | }; |
| | |
| | | rec.setValue("is_run", sdkRule.nIsRun); |
| | | rec.setValue("img_threshold", sdkRule.nThreshold); |
| | | rec.setValue("img_quality", sdkRule.nQuality); |
| | | rec.setValue("perimeter_obj_type", sdkRule.strPerimeterObjType); |
| | | |
| | | int rowCount = pModel.rowCount(); |
| | | if (rowCount == 0) { |
| | |
| | | rule.nAlarmNumUpperLimit = rec.value("alarm_num_upper").toInt(); |
| | | rule.nAlarmNumLowerLimit = rec.value("alarm_num_lower").toInt(); |
| | | rule.strBroadcast = rec.value("broadcast_area").toString(); |
| | | rule.strPerimeterObjType = rec.value("perimeter_obj_type").toString(); |
| | | rule.nIsRun = rec.value("is_run").toInt(); |
| | | rule.nSdkType = rec.value("sdk_type").toInt(); |
| | | ruleMap[rule.nSdkType] = rule; |
| | |
| | | } |
| | | } |
| | | } else if (itor_json.name() == "cam_edit") { |
| | | string cam_idx = cfg_val["str_cam_dev_id"].asString(); |
| | | string cam_idx = ""; |
| | | if(pthis->m_GB28181_Enable){ |
| | | cam_idx = cfg_val["equipCode"].asString(); |
| | | }else{ |
| | | cam_idx = cfg_val["str_cam_dev_id"].asString(); |
| | | } |
| | | |
| | | if (pthis->m_GB28181_Enable) { |
| | | if (pthis->m_controllers_videoCapElem.find(cam_idx) != |
| | | pthis->m_controllers_videoCapElem.end()) { |
| | |
| | | } |
| | | } |
| | | } else if (itor_json.name() == "cam_del") { |
| | | string cam_idx = cfg_val["str_cam_dev_id"].asString(); |
| | | string cam_idx = ""; |
| | | if(pthis->m_GB28181_Enable){ |
| | | cam_idx = cfg_val["equipCode"].asString(); |
| | | }else{ |
| | | cam_idx = cfg_val["str_cam_dev_id"].asString(); |
| | | } |
| | | pthis->removeCamera(cam_idx); |
| | | } else if (itor_json.name() == "cam_startPublish") { |
| | | string cam_idx = cfg_val["id"].asString(); |
| | | if (pthis->m_GB28181_Enable) { |
| | | if (pthis->m_controllers_videoCapElem.find(cam_idx) != |
| | | pthis->m_controllers_videoCapElem.end()) { |
| | | INFO("cam add is " << cfg_val["str_addr"].asString()); |
| | | INFO("cam add is " << cam_idx); |
| | | pthis->m_controllers_videoCapElem[cam_idx]->startPublishVideo(); |
| | | } |
| | | } else { |
| | | if (pthis->m_controllers.find(cam_idx) != pthis->m_controllers.end()) { |
| | | INFO("cam add is " << cfg_val["str_addr"].asString()); |
| | | INFO("cam add is " << cam_idx); |
| | | pthis->m_controllers[cam_idx]->startPublishVideo(); |
| | | } |
| | | } |
| | |
| | | // auto lst = m_lDBTool->searchCamDevTableAll(); |
| | | Record_Config lst_dev = m_lDBTool->searchConfigTableWithinServerInfo(); |
| | | if (m_controllers.find(index) == m_controllers.end()) { |
| | | INFO("MYH DEBUG HERE"); |
| | | // INFO("MYH DEBUG HERE"); |
| | | if (m_currentCount >= m_maxCount) { |
| | | ERR("addCamera faild, camera's num is full!") |
| | | return -1; |
| | |
| | | * @return 总是0 |
| | | */ |
| | | int RtspAnalysManager::removeCamera(const std::string &index) { |
| | | INFO("MYH DEBUG HERE"); |
| | | // INFO("MYH DEBUG HERE"); |
| | | if (m_GB28181_Enable) { |
| | | if (m_controllers_videoCapElem.find(index) == m_controllers_videoCapElem.end())return -1; |
| | | auto controller = m_controllers_videoCapElem[index]; |
| | |
| | | delete imgRedis; |
| | | m_imgRedisControllers.erase(index); |
| | | m_imgRedisCRwLock.unlock(); |
| | | INFO("MYH DEBUG HERE"); |
| | | // INFO("MYH DEBUG HERE"); |
| | | return 0; |
| | | } |
| | | |
| | |
| | | |
| | | //录取视频的RPC的接口函数 |
| | | ::std::string RtspAnalysManager::recordVideo(const ::std::string &name, const ::Ice::Current &) { |
| | | INFO("Record Video For: " << name); |
| | | // INFO("Record Video For: " << name); |
| | | ImageName_s_t nameSt = ImageName_s_t::fromString(name); |
| | | if (nameSt.Valid()) { |
| | | if (m_GB28181_Enable) { |
| | |
| | | } |
| | | } |
| | | |
| | | m_picCount++; |
| | | //几张选一张放入Redis |
| | | if (m_picCount % m_nPicsPickOne != 0) { |
| | | return; |
| | | } else { |
| | | m_picCount.store(0); |
| | | } |
| | | u_char *data; |
| | | int width = 0, height = 0, step = 0, cn = 0; |
| | | cv::Mat copyMat; |
| | | |
| | | { |
| | | u_char *data; |
| | | int width = 0, height = 0, step = 0, cn = 0; |
| | | m_capture->retrieveFrame(0, &data, &step, &width, &height, &cn); |
| | | |
| | | cv::Mat img(height, width, CV_8UC3, data, step); |
| | | cv::Mat copyMat; |
| | | img.copyTo(copyMat); |
| | | std::string imageName = m_capture->GetImageName(); |
| | | m_pManager->SaveImageToRedis(m_camId, imageName, copyMat); |
| | | } |
| | | //#todo publish Video |
| | | //#publish Video |
| | | if (m_publishVideoRet) { |
| | | if (videoPublishElement == nullptr) { |
| | | string path = appConfig.getStringProperty("srsAddr") + "cam" + m_camId + ".flv"; |
| | | cv::Size size_(appConfig.getIntProperty("pulish.width"), appConfig.getIntProperty("pulish.height")); |
| | | int gupIdx = appPref.getIntData("gpu.index"); |
| | | videoPublishElement = new ffmpeg::VideoPublishElement(path, size_, "flv", 25, gupIdx); |
| | | videoPublishElement->start(); |
| | | } else { |
| | | // DBG("videoPublishElement->setImage()"); |
| | | m_capture->retrieveFrame(0, &data, &step, &width, &height, &cn); |
| | | cv::Mat img(height, width, CV_8UC3, data, step); |
| | | img.copyTo(copyMat); |
| | | |
| | | if (!copyMat.empty()) { |
| | | videoPublishElement->setImage(copyMat); |
| | | } else { |
| | | DBG("copyMat.empty()"); |
| | | } |
| | | } |
| | | } else { |
| | | if (videoPublishElement != nullptr) { |
| | | DBG("videoPublishElement->stop()"); |
| | | videoPublishElement->stop(); |
| | | videoPublishElement->wait(); |
| | | delete videoPublishElement; |
| | | videoPublishElement = nullptr; |
| | | } |
| | | } |
| | | |
| | | //几张选一张放入Redis |
| | | m_picCount++; |
| | | if (m_picCount % m_nPicsPickOne != 0) { |
| | | // return; |
| | | } else { |
| | | m_picCount.store(0); |
| | | |
| | | if (copyMat.empty()) { |
| | | // ERR("copyMat.empty()"); |
| | | m_capture->retrieveFrame(0, &data, &step, &width, &height, &cn); |
| | | cv::Mat img(height, width, CV_8UC3, data, step); |
| | | img.copyTo(copyMat); |
| | | } |
| | | std::string imageName = m_capture->GetImageName(); |
| | | m_pManager->SaveImageToRedis(m_camId, imageName, copyMat); |
| | | } |
| | | |
| | | fireConnectors(); |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | std::atomic<bool> m_publishVideoRet{false}; |
| | | ffmpeg::VideoPublishElement *videoPublishElement; |
| | | ffmpeg::VideoPublishElement *videoPublishElement{nullptr}; |
| | | // Redis的工具类 |
| | | // HiredisTool m_redisTool; |
| | | |
| | |
| | | //继承自父类,线程初始化的一些工作 |
| | | void RtspImageRedisElement::threadInitial() |
| | | { |
| | | INFO("MYH DEBUG HERE"); |
| | | // INFO("MYH DEBUG HERE"); |
| | | } |
| | | |
| | | //继承自父类,线程结束的时候调用 |
| | | void RtspImageRedisElement::threadClosing() |
| | | { |
| | | INFO("MYH DEBUG HERE"); |
| | | // INFO("MYH DEBUG HERE"); |
| | | } |
| | | |
| | | //保存图片到队列中, |
| | |
| | | m_imageQueue.push(NameImagePair_s_t(imageName,img)); |
| | | } |
| | | else{ |
| | | ERR("SaveImage Failed ImgName:"<<imageName); |
| | | // ERR("SaveImage Failed ImgName:"<<imageName); |
| | | } |
| | | return true; |
| | | } |
| | |
| | | VptServerI.cpp |
| | | VptDetectWrapper.cpp |
| | | ./rpc/VptServer.cpp |
| | | |
| | | ../../../BasicPlatForm/basic/timer_counter/Clocktimer.h |
| | | ../../../BasicPlatForm/basic/timer_counter/Clocktimer.cpp |
| | | # GlobalSignalWaitLock.hpp |
| | | ) |
| | | |
| | |
| | | |
| | | #include <basic/debug/Debug.h> |
| | | #include "VptDetectWrapper.h" |
| | | #include <basic/timer_counter/Clocktimer.h> |
| | | |
| | | VptDetectWrapper::VptDetectWrapper() { |
| | | init(); |
| | |
| | | } |
| | | |
| | | list<VptDetectResults> VptDetectWrapper::process_image(cv::Mat &_img) { |
| | | ClockTimer ct("VptDetectWrapper::process_image"); |
| | | m_results.clear(); |
| | | |
| | | sy_img img; |
| | |
| | | int colorIndex = result.info[i].obj_index; |
| | | |
| | | if (colorIndex < 0 || colorIndex >= 9)continue; |
| | | if(colorIndex==4) DBG("detect a car, score =" << result.info[i].obj_score); |
| | | if(colorIndex==1) DBG("detect a bike, score =" << result.info[i].obj_score); |
| | | if(colorIndex==2) DBG("detect a moto, score =" << result.info[i].obj_score); |
| | | // sprintf(str_i, "%s:%.2f", type[colorIndex].c_str(), result.info[i].obj_score); |
| | | |
| | | // rectangle(process_image, |
| | |
| | | delete[] result.info; |
| | | result.info = NULL; |
| | | } |
| | | DBG(m_results.size()); |
| | | // DBG(m_results.size()); |
| | | return m_results; |
| | | } |
| | | |
| | |
| | | auto &carRes = vptDetectResults.vptDetectRes.carDetectRes; |
| | | |
| | | // 车颜色 |
| | | carRes.colorLabel = static_cast<ColorLabel>(cur_res->vc_res.res_index); |
| | | carRes.colorLabelProb = cur_res->vc_res.res_prob; |
| | | if(m_param.vehicle_color_config == SY_CONFIG_OPEN) { |
| | | carRes.colorLabel = static_cast<ColorLabel>(cur_res->vc_res.res_index); |
| | | carRes.colorLabelProb = cur_res->vc_res.res_prob; |
| | | } |
| | | |
| | | // 车型识别 |
| | | if (cur_res->vr_res.vehicle_brand != NULL) { |
| | | cout << " 车辆品牌 - " << cur_res->vr_res.vehicle_brand << endl; |
| | | carRes.vehicle_brand = cur_res->vr_res.vehicle_brand; |
| | | if(m_param.vehicle_recg_config == SY_CONFIG_OPEN) { |
| | | if (cur_res->vr_res.vehicle_brand != NULL) { |
| | | cout << " 车辆品牌 - " << cur_res->vr_res.vehicle_brand << endl; |
| | | carRes.vehicle_brand = cur_res->vr_res.vehicle_brand; |
| | | // carRes.vehicle_brand = string(cur_res->vr_res.vehicle_brand); |
| | | // carRes.vehicle_brand = "发"; |
| | | delete[] cur_res->vr_res.vehicle_brand; |
| | | cur_res->vr_res.vehicle_brand = NULL; |
| | | } |
| | | if (cur_res->vr_res.vehicle_subbrand != NULL) { |
| | | cout << " 车辆子品牌 - " << cur_res->vr_res.vehicle_subbrand << endl; |
| | | carRes.vehicle_subbrand = cur_res->vr_res.vehicle_subbrand; |
| | | // carRes.vehicle_subbrand = cur_res->vr_res.vehicle_subbrand; |
| | | delete[] cur_res->vr_res.vehicle_subbrand; |
| | | cur_res->vr_res.vehicle_subbrand = NULL; |
| | | } |
| | | if (cur_res->vr_res.vehicle_issue_year != NULL) { |
| | | cout << " 车辆年款 - " << cur_res->vr_res.vehicle_issue_year << endl; |
| | | carRes.vehicle_issue_year = cur_res->vr_res.vehicle_issue_year; |
| | | delete[] cur_res->vr_res.vehicle_issue_year; |
| | | cur_res->vr_res.vehicle_issue_year = NULL; |
| | | } |
| | | if (cur_res->vr_res.vehicle_type != NULL) { |
| | | cout << " 车辆类型 - " << cur_res->vr_res.vehicle_type << endl; |
| | | carRes.vehicle_type = cur_res->vr_res.vehicle_type; |
| | | delete[] cur_res->vr_res.vehicle_type; |
| | | cur_res->vr_res.vehicle_type = NULL; |
| | | } |
| | | if (cur_res->vr_res.freight_ton != NULL) { |
| | | cout << " 货车吨级 - " << cur_res->vr_res.freight_ton << endl; |
| | | carRes.freight_ton = cur_res->vr_res.freight_ton; |
| | | delete[] cur_res->vr_res.freight_ton; |
| | | cur_res->vr_res.freight_ton = NULL; |
| | | } |
| | | // cout << " " << cur_res->vr_res.name_score << endl; |
| | | carRes.vehicle_score = cur_res->vr_res.name_score; |
| | | |
| | | // 车牌 |
| | | if (cur_res->vp_res.rect.height_ != 0 && cur_res->vp_res.rect.width_ != 0) { |
| | | cout << "车牌位置: " << cur_res->vp_res.rect.left_ << " " << cur_res->vp_res.rect.top_ << " " |
| | | << cur_res->vp_res.rect.width_ << " " << cur_res->vp_res.rect.height_ << endl; |
| | | carRes.carPlateRect.setRect(cur_res->vp_res.rect.left_, cur_res->vp_res.rect.top_, |
| | | cur_res->vp_res.rect.width_, cur_res->vp_res.rect.height_); |
| | | carRes.carPlateRectScore = cur_res->vp_res.detectScore; |
| | | std::string _carPlate; |
| | | for (int m = 0; m < 7; m++) { |
| | | printf("%s", cur_res->vp_res.recg[m].character); |
| | | _carPlate.append(cur_res->vp_res.recg[m].character); |
| | | delete[] cur_res->vr_res.vehicle_brand; |
| | | cur_res->vr_res.vehicle_brand = NULL; |
| | | } |
| | | carRes.carPlate = const_cast<char *>(_carPlate.c_str()); |
| | | carRes.carPlateRectScore = cur_res->vp_res.numScore; |
| | | carRes.carPlatetype = cur_res->vp_res.type; |
| | | if (cur_res->vr_res.vehicle_subbrand != NULL) { |
| | | cout << " 车辆子品牌 - " << cur_res->vr_res.vehicle_subbrand << endl; |
| | | carRes.vehicle_subbrand = cur_res->vr_res.vehicle_subbrand; |
| | | // carRes.vehicle_subbrand = cur_res->vr_res.vehicle_subbrand; |
| | | delete[] cur_res->vr_res.vehicle_subbrand; |
| | | cur_res->vr_res.vehicle_subbrand = NULL; |
| | | } |
| | | if (cur_res->vr_res.vehicle_issue_year != NULL) { |
| | | cout << " 车辆年款 - " << cur_res->vr_res.vehicle_issue_year << endl; |
| | | carRes.vehicle_issue_year = cur_res->vr_res.vehicle_issue_year; |
| | | delete[] cur_res->vr_res.vehicle_issue_year; |
| | | cur_res->vr_res.vehicle_issue_year = NULL; |
| | | } |
| | | if (cur_res->vr_res.vehicle_type != NULL) { |
| | | cout << " 车辆类型 - " << cur_res->vr_res.vehicle_type << endl; |
| | | carRes.vehicle_type = cur_res->vr_res.vehicle_type; |
| | | delete[] cur_res->vr_res.vehicle_type; |
| | | cur_res->vr_res.vehicle_type = NULL; |
| | | } |
| | | if (cur_res->vr_res.freight_ton != NULL) { |
| | | cout << " 货车吨级 - " << cur_res->vr_res.freight_ton << endl; |
| | | carRes.freight_ton = cur_res->vr_res.freight_ton; |
| | | delete[] cur_res->vr_res.freight_ton; |
| | | cur_res->vr_res.freight_ton = NULL; |
| | | } |
| | | // cout << " " << cur_res->vr_res.name_score << endl; |
| | | carRes.vehicle_score = cur_res->vr_res.name_score; |
| | | } |
| | | |
| | | if(m_param.vehicle_pendant_det_recg_config == SY_CONFIG_OPEN) { |
| | | // 车牌 |
| | | if (cur_res->vp_res.rect.height_ != 0 && cur_res->vp_res.rect.width_ != 0) { |
| | | cout << "车牌位置: " << cur_res->vp_res.rect.left_ << " " << cur_res->vp_res.rect.top_ << " " |
| | | << cur_res->vp_res.rect.width_ << " " << cur_res->vp_res.rect.height_ << endl; |
| | | carRes.carPlateRect.setRect(cur_res->vp_res.rect.left_, cur_res->vp_res.rect.top_, |
| | | cur_res->vp_res.rect.width_, cur_res->vp_res.rect.height_); |
| | | carRes.carPlateRectScore = cur_res->vp_res.detectScore; |
| | | std::string _carPlate; |
| | | for (int m = 0; m < 7; m++) { |
| | | printf("%s", cur_res->vp_res.recg[m].character); |
| | | _carPlate.append(cur_res->vp_res.recg[m].character); |
| | | } |
| | | carRes.carPlate = const_cast<char *>(_carPlate.c_str()); |
| | | carRes.carPlateRectScore = cur_res->vp_res.numScore; |
| | | carRes.carPlatetype = cur_res->vp_res.type; |
| | | // printf(" numScore = %.2f, detectScore = %.2f\n", cur_res->vp_res.numScore, cur_res->vp_res.detectScore); |
| | | } |
| | | } |
| | | }; |
| | | break; |
| | |
| | | { |
| | | "mainServerIp": "192.168.1.182", |
| | | "mainServerPort": "3697", |
| | | "logPath": "/home/basic/work/log/", |
| | | "DEV_ID": "DSVAD010120181119", |
| | | "ES_IP": "192.168.1.182", |
| | | "ES_PORT": 9200, |
| | | "FaceSeachSleepTime": 60, |
| | | "TotalLoadSize": "500", |
| | | "buildAddr": "/home/basic/Apps/QiaoJiaSystem/build/", |
| | | "cutPath": "/home/basic/work/qiaojia/cut", |
| | | "erlCookie": "", |
| | | "erlFatherNode": "", |
| | | "erlNode": "", |
| | | "erlPath": "", |
| | | "loadPath": "/home/basic/work/qiaojia/load", |
| | | "localPasswd": "123456", |
| | | "netIfName": "enp3s0", |
| | | "srsAddr": "rtmp://192.168.1.122:1934/live/", |
| | | "webPort": 11111, |
| | | "redis_ip": "127.0.0.1", |
| | | "redis_buf_len": 750, |
| | | "encode_thread_num": 2, |
| | | "FaceDetectionSampleSize": 720, |
| | | "clusterID" : "sssss" |
| | | "DEV_ID" : "DSVAD010120181119", |
| | | "ES_IP" : "192.168.1.182", |
| | | "ES_PORT" : 9200, |
| | | "FaceDetectionSampleSize" : 720, |
| | | "FaceSeachSleepTime" : 60, |
| | | "TotalLoadSize" : "500", |
| | | "buildAddr" : "/home/basic/Apps/QiaoJiaSystem/build/", |
| | | "clusterID" : "sssss", |
| | | "cutPath" : "/home/basic/work/qiaojia/cut", |
| | | "encode_thread_num" : 2, |
| | | "erlCookie" : "", |
| | | "erlFatherNode" : "", |
| | | "erlNode" : "", |
| | | "erlPath" : "", |
| | | "loadPath" : "/home/basic/work/qiaojia/load", |
| | | "localPasswd" : "123456", |
| | | "logPath" : "/home/basic/work/log/", |
| | | "mainServerIp" : "192.168.1.182", |
| | | "mainServerPort" : "3697", |
| | | "netIfName" : "enp3s0", |
| | | "redis_buf_len" : 750, |
| | | "redis_ip" : "127.0.0.1", |
| | | "srsAddr" : "rtmp://192.168.1.122:1934/live/", |
| | | "webPort" : 11111 |
| | | } |
old mode 100644
new mode 100755
| | |
| | | |
| | | // c erlang init |
| | | erl_init(NULL, 0); |
| | | |
| | | struct in_addr addr; |
| | | addr.s_addr = inet_addr("127.0.0.1"); |
| | | |
| | |
| | | std::cout << m_ret << std::endl; |
| | | // 判断节点是否启动成功 |
| | | m_ret = waitNode(); |
| | | // erl_close_connection(m_fd); |
| | | resetConn(); |
| | | return m_ret; |
| | | } else { |
| | |
| | | "Select a.uuid as id ,a.faceUrl as img,a.feature,b.idCard as idcard,b.enabled,b.monitorLevel from '" + |
| | | str_tableUuid + |
| | | "_fea' as a ,'" + str_tableUuid + "' as b where a.uuid = b.uuid and ( a.del_flag=0 AND b.del_flag=0);"); |
| | | //Select a.uuid as id ,a.faceUrl as img,a.feature,b.idCard as idcard,b.enabled,b.monitorLevel from '0cd82a8b-5285-5737-ab19-8c07247c797e_fea' as a ,'0cd82a8b-5285-5737-ab19-8c07247c797e' as b where a.uuid = b.uuid and ( a.del_flag=0 AND b.del_flag=0); |
| | | QSqlQuery query(g_syncDbFile); |
| | | query.prepare(sql); |
| | | if (!query.exec()) { |