1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291 |
- #include "GlobalInfo.h"
- #include <QSettings>
- #include "spdlog/spdlog.h"
- /* ====================================================================================
- * ******************************* 全局变量定义 **********************************
- * ====================================================================================*/
- int g_eventTimeVaild = 600; /* 事件时间有效性,单位秒,超过这个时间就认为是无效数据 */
- ActionList g_actionList; /* 全局算法列表 */
- /* ====================================================================================
- * *************************** DeviceInfo成员函数 *******************************
- * ====================================================================================*/
- /* 对比是否相等 */
- bool DeviceInfo::operator==(const DeviceInfo& other)
- {
- if(DeviceID != other.DeviceID) {
- return false;
- }
- else if(DeviceName != other.DeviceName || DeviceIP != other.DeviceIP) {
- return false;
- }
- else if(DeviceSerial != other.DeviceSerial || DeviceType != other.DeviceType) {
- return false;
- }
- else if(DevicePort != other.DevicePort || UserAccount != other.UserAccount || UserPassword != other.UserPassword) {
- return false;
- }
- return true;
- }
- /* 对比设备关联的算法信息是否相等 */
- bool DeviceInfo::isEqualAlgorithmInfo(const std::vector<AlgorithmInfo>& other)
- {
- /* 算法数目不相等,直接返回false */
- if(vecAlgorithmInfo.size() != other.size()) {
- return false;
- }else {
- /* 算法数目相等,进一步对比算法信息 */
- bool isEquality = true;
- /* 逐步对比算法信息 */
- for(const auto& it0 : vecAlgorithmInfo) {
- bool isEq2 = true;
- for(const auto& it1 : other) {
- if(it0 == it1) {
- continue;
- }else {
- isEq2 = false;
- break;
- }
- }
- if(!isEq2) {
- isEquality = false;
- break;
- }
- }
- if(!isEquality) {
- return false;
- }
- }
- return true;
- }
- /* ====================================================================================
- * ******************************* 各种报警信息 **********************************
- * ====================================================================================*/
- AlarmInfo::AlarmInfo()
- {
- Is_Alarm = false;
- AlarmID = 0;
- DeviceID = 0;
- RoomID = 0;
- ChannelID = 0;
- State = 0;
- OnWork = 0;
- StartTime = "";
- EndTime = "";
- EventTime = "";
- PicUrl = "";
- ImageInfo = "";
- AppID = "";
- ActionID = "";
- ActionDes = "";
- FaceIDList = "";
- FaceNameList = "";
- listBbox.clear();
- }
- AlarmInfo::AlarmInfo(const AlarmInfo& other)
- {
- Is_Alarm = other.Is_Alarm;
- AlarmID = other.AlarmID;
- DeviceID = other.DeviceID;
- RoomID = other.RoomID;
- ChannelID = other.ChannelID;
- State = other.State;
- OnWork = other.OnWork;
- StartTime = other.StartTime;
- EndTime = other.EndTime;
- EventTime = other.EventTime;
- PicUrl = other.PicUrl;
- ImageInfo = other.ImageInfo;
- AppID = other.AppID;
- ActionID = other.ActionID;
- ActionDes = other.ActionDes;
- FaceIDList = other.FaceIDList;
- FaceNameList = other.FaceNameList;
- listBbox = other.listBbox;
- vecPersonInfo = other.vecPersonInfo;
- }
- AlarmInfo& AlarmInfo::operator=(AlarmInfo& other)
- {
- if(this != &other)
- {
- Is_Alarm = other.Is_Alarm;
- AlarmID = other.AlarmID;
- DeviceID = other.DeviceID;
- RoomID = other.RoomID;
- ChannelID = other.ChannelID;
- State = other.State;
- OnWork = other.OnWork;
- StartTime = other.StartTime;
- EndTime = other.EndTime;
- EventTime = other.EventTime;
- PicUrl = other.PicUrl;
- ImageInfo = other.ImageInfo;
- AppID = other.AppID;
- ActionID = other.ActionID;
- ActionDes = other.ActionDes;
- FaceIDList = other.FaceIDList;
- FaceNameList = other.FaceNameList;
- listBbox = other.listBbox;
- vecPersonInfo = other.vecPersonInfo;
- }
- return *this;
- }
- /* 清空内容 */
- void AlarmInfo::reInit()
- {
- Is_Alarm = false;
- AlarmID = 0;
- DeviceID = 0;
- RoomID = 0;
- ChannelID = 0;
- State = 0;
- OnWork = 0;
- StartTime = "";
- EndTime = "";
- EventTime = "";
- PicUrl = "";
- ImageInfo = "";
- AppID = "";
- ActionID = "";
- ActionDes = "";
- FaceIDList = "";
- FaceNameList = "";
- listBbox.clear();
- }
- /**
- * @brief 添加报警信息
- *
- * @param info
- * @return true
- * @return false
- */
- bool ListAlarmInfo::addAlarmInfo(AlarmInfo& info)
- {
- /* 先查找有没有重复的 */
- auto p = findAlarmInfo(info);
- if(p != nullptr)
- {
- return false;
- }
- listAlarmInfo.push_back(info);
- return true;
- }
- /**
- * @brief 检查列表中是是否有这个报警信息,这里只检查ChannelID、RoomID、CameraID、ActionID是否相等
- *
- * @param info
- * @return AlarmInfo*
- */
- AlarmInfo* ListAlarmInfo::findAlarmInfo(AlarmInfo& info)
- {
- for(auto& it0 : listAlarmInfo)
- {
- if(it0.ChannelID == info.ChannelID && it0.RoomID == info.RoomID && it0.DeviceID == info.DeviceID && it0.ActionID == info.ActionID)
- {
- return &it0;
- }
- }
- return nullptr;
- }
- /* 查找是否有相同的人脸信息 */
- bool RoomFaceInfo::findPersonInfo(const PersonInfo& info)
- {
- for(auto& it0 : listPersonInfo)
- {
- if(it0.PersonID == info.PersonID && it0.PersonName == info.PersonName)
- {
- return true;
- }
- }
- return false;
- }
- /* 添加房间人脸信息 */
- void ListRoomFaceInfo::addRoomFaceInfo(RoomFaceInfo& info)
- {
- /* 先查找有没有重复的 */
- auto p = findRoomFaceInfo(info);
- if(p != nullptr)
- {
- return;
- }
- listRoomFaceInfo.push_back(info);
- }
- /**
- * @brief 通过报警信息添加人脸信息
- *
- * @param info
- */
- void ListRoomFaceInfo::addRoomFaceInfo(AlarmInfo& info)
- {
- auto p = findRoomFaceInfo(info.ChannelID, info.RoomID, info.DeviceID);
- if(p == nullptr)
- {
- RoomFaceInfo rfi;
- rfi.ChannelID = info.ChannelID;
- rfi.RoomID = info.RoomID;
- rfi.CameraID = info.DeviceID;
- rfi.MaxNum = 0;
- rfi.MinNum = 0;
- rfi.StartTime = QDateTime::currentDateTime();
- listRoomFaceInfo.push_back(rfi);
- }
- /* 将人员信息加入到列表中,添加时会先查找有没有相同的信息 */
- for(auto& it0 : info.vecPersonInfo)
- {
- if(!p->findPersonInfo(it0))
- {
- p->listPersonInfo.push_back(it0);
- }
- }
- }
- RoomFaceInfo* ListRoomFaceInfo::findRoomFaceInfo(RoomFaceInfo& info)
- {
- for(auto& it0 : listRoomFaceInfo)
- {
- if(it0.ChannelID == info.ChannelID && it0.RoomID == info.RoomID && it0.CameraID == info.CameraID)
- {
- return &it0;
- }
- }
- return nullptr;
- }
- /* 查找有没有相同的结构 */
- RoomFaceInfo* ListRoomFaceInfo::findRoomFaceInfo(int ChannelID, int RoomID, int CameraID)
- {
- for(auto& it0 : listRoomFaceInfo)
- {
- if(it0.ChannelID == ChannelID && it0.RoomID == RoomID && it0.CameraID == CameraID)
- {
- return &it0;
- }
- }
- return nullptr;
- }
- IllegalInvasionInfo::IllegalInvasionInfo(IllegalInvasionInfo& other)
- {
- isInsertEQM = other.isInsertEQM;
- PKID = other.PKID;
- CameraID = other.CameraID;
- RoomID = other.RoomID;
- ChannelID = other.ChannelID;
- RoomType = other.RoomType;
- FirstTime = other.FirstTime;
- strActionDec = other.strActionDec;
- strImageInfo = other.strImageInfo;
- }
- IllegalInvasionInfo& IllegalInvasionInfo::operator=(IllegalInvasionInfo& other)
- {
- if(this != &other)
- {
- isInsertEQM = other.isInsertEQM;
- PKID = other.PKID;
- CameraID = other.CameraID;
- RoomID = other.RoomID;
- ChannelID = other.ChannelID;
- RoomType = other.RoomType;
- FirstTime = other.FirstTime;
- strActionDec = other.strActionDec;
- strImageInfo = other.strImageInfo;
- }
- return *this;
- }
- /* 添加信息 */
- void ListIllegalInvasionInfo::addIllInfo(IllegalInvasionInfo& info)
- {
- if(findIllInfo(info) == nullptr)
- {
- listIll.push_back(info);
- }
- }
- /* 查找相同的信息 */
- IllegalInvasionInfo* ListIllegalInvasionInfo::findIllInfo(IllegalInvasionInfo& info)
- {
- for(auto& it : listIll)
- {
- if(it.RoomID == info.RoomID && it.RoomType == info.RoomType)
- {
- return ⁢
- }
- }
- return nullptr;
- }
- IllegalInvasionInfo* ListIllegalInvasionInfo::findIllInfo(int roomID, int roomType)
- {
- for(auto& it : listIll)
- {
- if(it.RoomID == roomID && it.RoomType == roomType)
- {
- return ⁢
- }
- }
- return nullptr;
- }
- /* 删除报警信息 */
- void ListIllegalInvasionInfo::deleteIllInfo(IllegalInvasionInfo& info)
- {
- for(auto it = listIll.begin(); it != listIll.end();)
- {
- if(it->RoomID == info.RoomID && it->RoomType == info.RoomType)
- {
- it = listIll.erase(it);
- }else {
- ++it;
- }
- }
- }
- void ListIllegalInvasionInfo::deleteIllInfo(int roomID, int roomType)
- {
- for(auto it = listIll.begin(); it != listIll.end();)
- {
- if(it->RoomID == roomID && it->RoomType == roomType)
- {
- it = listIll.erase(it);
- }else {
- ++it;
- }
- }
- }
- RoomIllegalInvasionInfo::RoomIllegalInvasionInfo(RoomIllegalInvasionInfo& o)
- {
- isAlarm = o.isAlarm;
- RoomID = o.RoomID;
- RoomType = o.RoomType;
- numMaxFace = o.numMaxFace;
- numMaxPerson = o.numMaxPerson;
- strBoxList = o.strBoxList;
- strMessage = o.strMessage;
- strImage = o.strImage;
- CameraID = o.CameraID;
- }
- RoomIllegalInvasionInfo& RoomIllegalInvasionInfo::operator=(RoomIllegalInvasionInfo& o)
- {
- if(this != &o) {
- isAlarm = o.isAlarm;
- RoomID = o.RoomID;
- RoomType = o.RoomType;
- numMaxFace = o.numMaxFace;
- numMaxPerson = o.numMaxPerson;
- strBoxList = o.strBoxList;
- strMessage = o.strMessage;
- strImage = o.strImage;
- CameraID = o.CameraID;
- }
- return *this;
- }
- /* 添加房间 */
- void ListRoomIll::addRoom(int RoomID, int RoomType)
- {
- auto p = findRoom(RoomID, RoomType);
- if(p == nullptr)
- {
- RoomIllegalInvasionInfo ill;
- ill.RoomID = RoomID;
- ill.RoomType = RoomType;
- listRoomIll.push_back(ill);
- }
- }
- /* 查找是否有相同的房间 */
- RoomIllegalInvasionInfo* ListRoomIll::findRoom(int RoomID, int RoomType)
- {
- for(auto& it : listRoomIll)
- {
- if(it.RoomID == RoomID && it.RoomType == RoomType)
- {
- return ⁢
- }
- }
- return nullptr;
- }
- AlarmRuleInfo::AlarmRuleInfo()
- {
- LiveMinEnable = false;
- LiveMaxEnable = false;
- DicMinEnable = false;
- DicMaxEnable = false;
- LiveDicMinEnable = false;
- LiveDicMaxEnable = false;
- LiveMin = 0;
- LiveMax = 0;
- DicMin = 0;
- DicMax = 0;
- LiveDicMin = 0;
- LiveDicMax = 0;
- RuleName = "";
- }
- AlarmRuleInfo& AlarmRuleInfo::operator=(AlarmRuleInfo& other)
- {
- if(this != &other)
- {
- LiveMinEnable = other.LiveMinEnable;
- LiveMaxEnable = other.LiveMaxEnable;
- DicMinEnable = other.DicMinEnable;
- DicMaxEnable = other.DicMaxEnable;
- LiveDicMinEnable = other.LiveDicMinEnable;
- LiveDicMaxEnable = other.LiveDicMaxEnable;
- LiveMin = other.LiveMin;
- LiveMax = other.LiveMax;
- DicMin = other.DicMin;
- DicMax = other.DicMax;
- LiveDicMin = other.LiveDicMin;
- LiveDicMax = other.LiveDicMax;
- RuleName = other.RuleName;
- }
- return *this;
- }
- /* ====================================================================================
- * ************************** ListActionInfo成员函数 ****************************
- * ====================================================================================*/
- ActionInfo::ActionInfo()
- {
- RunState = RunTimeState::RUN_STATE_INIT;
- ChannelID = -1;
- RoomID = -1;
- CameraID = -1;
- RoomType = -1;
- ActionID = "";
- strRoomName = "";
- strActionName = "";
- }
- ActionInfo& ActionInfo::operator=(const ActionInfo& other)
- {
- if (this != &other)
- {
- ChannelID = other.ChannelID;
- RoomID = other.RoomID;
- CameraID = other.CameraID;
- ActionID = other.ActionID;
- strRoomName = other.strRoomName;
- RoomType = other.RoomType;
- }
- return *this;
- }
- bool ActionInfo::operator==(const ActionInfo& other)
- {
- if(ChannelID != other.ChannelID) {
- return false;
- }
- if(RoomID != other.RoomID) {
- return false;
- }
- if(CameraID != other.CameraID) {
- return false;
- }
- if(ActionID != other.ActionID) {
- return false;
- }
- if(RoomType != other.RoomType) {
- return false;
- }
- return true;
- }
- /* 对比除摄像机外的基础信息是否相等 */
- bool ActionInfo::isEqualBaseInfo(const ActionInfo& other)
- {
- if(ChannelID != other.ChannelID) {
- return false;
- }
- if(RoomID != other.RoomID) {
- return false;
- }
- if(ActionID != other.ActionID) {
- return false;
- }
- if(RoomType != other.RoomType) {
- return false;
- }
- return true;
- }
- /* 添加关联信息,会自动进行重复判断,如果已有相同的信息,则跳过 */
- bool ListActionInfo::insertActionInfo(ActionInfo* info)
- {
- /* 先判断是否已经在列表中了 */
- if(findActionInList(info) == nullptr)
- {
- ActionInfo* pActionInfo = new ActionInfo;
- *pActionInfo = *info;
- listActionInfo.push_back(pActionInfo);
- }
- return true;
-
- }
- /* 删除信息 */
- bool ListActionInfo::deleteActionInfo(ActionInfo* info)
- {
- if(info == nullptr)
- {
- return false;
- }
- if(findActionInList(info) != nullptr)
- {
- listActionInfo.remove(info);
- delete info;
- info = nullptr;
- }
- return true;
- }
- /* 给算法添加摄像机,原有的会被替换掉 */
- bool ListActionInfo::addActionCamera(ActionInfo* pInfo)
- {
- auto pActionInfo = findActionIDInListNoCamera(pInfo);
- if(pActionInfo != nullptr)
- {
- pActionInfo->CameraID = pInfo->CameraID;
- }
- return true;
- }
- /* 清空算法中的摄像机信息 */
- void ListActionInfo::clearCameraList()
- {
- for(auto& it0 : listActionInfo)
- {
- it0->CameraID = -1;
- }
- }
- /* 清空设置成STOP或ERROR的Action */
- void ListActionInfo::clearStopAction()
- {
- for(auto it0 = listActionInfo.begin(); it0 != listActionInfo.end();)
- {
- if(( (*it0)->RunState == RunTimeState::RUN_STATE_STOP) || ((*it0)->RunState == RunTimeState::RUN_STATE_ERROR))
- {
- delete *it0;
- it0 = listActionInfo.erase(it0);
- }else {
- ++it0;
- }
- }
- }
- /* 查找算法ID是否已在列表中 */
- ActionInfo* ListActionInfo::findActionInList(ActionInfo* pInfo)
- {
- for(const auto& it0 : listActionInfo)
- {
- if(*it0 == *pInfo)
- {
- return it0;
- }
- }
- return nullptr;
- }
- /* 查找算法ID是否在列表中,这里查找不会对比摄像机ID */
- ActionInfo* ListActionInfo::findActionIDInListNoCamera(ActionInfo* pInfo)
- {
- for(const auto& it0 : listActionInfo)
- {
- if(it0->isEqualBaseInfo(*pInfo))
- {
- return it0;
- }
- }
- return nullptr;
- }
- /* 清空容器 */
- void ListActionInfo::clear()
- {
- for(auto& it0 : listActionInfo)
- {
- delete it0;
- it0 = nullptr;
- }
- listActionInfo.clear();
- }
- /* ====================================================================================
- * *********************** ListRoomActionInfo成员函数 ***************************
- * ====================================================================================*/
- /* 对比频道信息、房间信息、算法ID是否相等 */
- bool RoomActionInfo::isEqualBaseInfo(const RoomActionInfo& other)
- {
- if(ChannelID != other.ChannelID) {
- return false;
- }
- if(RoomID != other.RoomID) {
- return false;
- }
- if(ActionID != other.ActionID) {
- return false;
- }
- if(RoomType != other.RoomType) {
- return false;
- }
- return true;
- }
- /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
- bool ListRoomActionInfo::insertRoomActionInfo(const RoomActionInfo& info)
- {
- /* 先判断是否已经在列表中了 */
- if(findActionIDInList(info.ChannelID, info.RoomID, info.ActionID) == nullptr)
- {
- RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
- *pRoomActionInfo = info;
- listRoomActionInfo.push_back(pRoomActionInfo);
- }
- return true;
- }
- /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
- bool ListRoomActionInfo::insertRoomActionInfo(const int ChannelID, const int RoomID, const std::string& strActionID)
- {
- /* 先判断是否已经在列表中了 */
- if(findActionIDInList(ChannelID, RoomID, strActionID) == nullptr)
- {
- RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
- pRoomActionInfo->RoomID = RoomID;
- pRoomActionInfo->ActionID = strActionID;
- listRoomActionInfo.push_back(pRoomActionInfo);
- }
- return true;
- }
- /* 删除一个容器,注意,这个不能在别的for循环中删除,只能单独删除 */
- bool ListRoomActionInfo::deleteRoomActionInfo(RoomActionInfo* pInfo)
- {
- if(pInfo == nullptr)
- {
- return false;
- }
- for(auto it0 = listRoomActionInfo.begin(); it0 != listRoomActionInfo.end(); ++it0)
- {
- if(*it0 == pInfo)
- {
- listRoomActionInfo.erase(it0);
- delete pInfo;
- pInfo = nullptr;
- return true;
- }
- }
- return false;
- }
- /* 清空容器 */
- void ListRoomActionInfo::clear()
- {
- for(auto& it0 : listRoomActionInfo)
- {
- delete it0;
- it0 = nullptr;
- }
- listRoomActionInfo.clear();
- }
- /* 添加算法信息,根据传入的算法信息,自动将其加入到对应的容器中 */
- void ListRoomActionInfo::addActionInfo(const ActionInfo& info)
- {
- auto pRAInfo = findActionIDInList(info.ChannelID, info.RoomID, info.ActionID);
- if(pRAInfo != nullptr)
- {
- pRAInfo->listCameraID.push_back(info.CameraID);
- }else {
- RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
- pRoomActionInfo->ChannelID = info.ChannelID;
- pRoomActionInfo->RoomID = info.RoomID;
- pRoomActionInfo->ActionID = info.ActionID;
- pRoomActionInfo->RoomType = info.RoomType;
- pRoomActionInfo->strRoomName = info.strRoomName;
- pRoomActionInfo->listCameraID.push_back(info.CameraID);
- listRoomActionInfo.push_back(pRoomActionInfo);
- }
- }
- /* 清空算法对应的摄像机列表 */
- void ListRoomActionInfo::clearCameraList()
- {
- for(auto& it0 : listRoomActionInfo)
- {
- it0->listCameraID.clear();
- }
- }
- /* 清理设置为STOP或者ERROR的RoomAction */
- // void ListRoomActionInfo::clearStopRoomAction()
- // {
- // for(auto it0 = listRoomActionInfo.begin(); it0 != listRoomActionInfo.end();)
- // {
- // if(( (*it0)->RunState == RunTimeState::RUN_STATE_STOP) || ((*it0)->RunState == RunTimeState::RUN_STATE_ERROR))
- // {
- // delete *it0;
- // it0 = listRoomActionInfo.erase(it0);
- // }else {
- // ++it0;
- // }
- // }
- // }
- /* 查找算法ID是否已在列表中 */
- RoomActionInfo* ListRoomActionInfo::findActionIDInList(const int chnID, const int RoomID, const std::string& strActionID)
- {
- for(const auto& it0 : listRoomActionInfo)
- {
- if((it0->RoomID == RoomID) && (it0->ActionID == strActionID) && (it0->ChannelID == chnID))
- {
- return it0;
- }
- }
- return nullptr;
- }
- FuncActionInfo::FuncActionInfo()
- {
- ChannelID = -1;
- appFunction = AppFunction::APP_NONE;
- RunState = RunTimeState::RUN_STATE_NONE;
- strFunctionName = "";
- StartTime = QDateTime::currentDateTime();
- EndTime = QDateTime::currentDateTime();
- listRoomCamActInfo.clear();
- }
- FuncActionInfo& FuncActionInfo::operator=(FuncActionInfo& other)
- {
- if(this != &other)
- {
- ChannelID = other.ChannelID;
- appFunction = other.appFunction;
- RunState = other.RunState;
- strFunctionName = other.strFunctionName;
- StartTime = other.StartTime;
- EndTime = other.EndTime;
- listRoomCamActInfo = other.listRoomCamActInfo;
- }
- return *this;
- }
- /* 添加算法信息 */
- bool FuncActionInfo::addActionInfo(const ActionInfo& info)
- {
- /* 根据此类的功能,添加算法信息 */
- if(appFunction == AppFunction::APP_NONE)
- {
- return false;
- }
- /* 将其添加到对应的房间 */
- bool isFind = false;
- for(auto& it0 : listRoomCamActInfo)
- {
- if((it0.RoomID == info.RoomID) && (it0.RoomType == info.RoomType))
- {
- isFind = true;
- it0.mapCameraAction.insert(std::make_pair(info.CameraID, info.ActionID));
- }
- }
- /* 没找到这个房间,就创建 */
- if(!isFind)
- {
- RoomCamActInfo roomCamActInfo;
- roomCamActInfo.RoomID = info.RoomID;
- roomCamActInfo.RoomType = info.RoomType;
- roomCamActInfo.mapCameraAction.insert(std::make_pair(info.CameraID, info.ActionID));
- listRoomCamActInfo.push_back(roomCamActInfo);
- }
- return true;
- }
- /* 清空算法信息 */
- void FuncActionInfo::clearActionList()
- {
- listRoomCamActInfo.clear();
- }
- /**
- * @brief 添加应用信息,一个应用功能在一个频道内只有一个实例
- * 这里是添加应用功能和时间段信息
- *
- * @param func
- * @return true
- * @return false
- */
- bool ListFuncActInfo::addFuncActionInfo(const AppAndTimeInfo& func)
- {
- if(func.AppType == 0)
- {
- return false;
- }
- /* 解出这条信息里包含几个App,AppType按位计算,总共8个应用信息 */
- for(int i = 0; i < 8; ++i)
- {
- if(func.AppType & 0x01)
- {
- /* 查找有没有这个应用 */
- auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_ONWORK);
- if(pFuncActionInfo != nullptr)
- {
- /* 更新时间信息 */
- pFuncActionInfo->StartTime = func.StartTime;
- pFuncActionInfo->EndTime = func.EndTime;
- continue;
- }
- FuncActionInfo* fa = new FuncActionInfo;
- fa->ChannelID = func.ChannelID;
- fa->appFunction = AppFunction::APP_ONWORK;
- fa->strFunctionName = "人员在岗识别";
- fa->StartTime = func.StartTime;
- fa->EndTime = func.EndTime;
- listFuncActionInfo.push_back(fa);
- }
- else if(func.AppType & 0x02)
- {
- auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_CONTRABAND);
- if(pFuncActionInfo != nullptr)
- {
- /* 更新时间信息 */
- pFuncActionInfo->StartTime = func.StartTime;
- pFuncActionInfo->EndTime = func.EndTime;
- continue;
- }
- FuncActionInfo* fa = new FuncActionInfo;
- fa->ChannelID = func.ChannelID;
- fa->appFunction = AppFunction::APP_CONTRABAND;
- fa->strFunctionName = "违禁品识别";
- fa->StartTime = func.StartTime;
- fa->EndTime = func.EndTime;
- listFuncActionInfo.push_back(fa);
- }
- else if (func.AppType & 0x04)
- {
- auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_ILLEGAL);
- if(pFuncActionInfo != nullptr)
- {
- /* 更新时间信息 */
- pFuncActionInfo->StartTime = func.StartTime;
- pFuncActionInfo->EndTime = func.EndTime;
- continue;
- }
- FuncActionInfo* fa = new FuncActionInfo;
- fa->ChannelID = func.ChannelID;
- fa->appFunction = AppFunction::APP_ILLEGAL;
- fa->strFunctionName = "非法入侵检测";
- fa->StartTime = func.StartTime;
- fa->EndTime = func.EndTime;
- listFuncActionInfo.push_back(fa);
- }
- else if (func.AppType & 0x08)
- {
- auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_FATIGUE);
- if(pFuncActionInfo != nullptr)
- {
- /* 更新时间信息 */
- pFuncActionInfo->StartTime = func.StartTime;
- pFuncActionInfo->EndTime = func.EndTime;
- continue;
- }
- FuncActionInfo* fa = new FuncActionInfo;
- fa->ChannelID = func.ChannelID;
- fa->appFunction = AppFunction::APP_FATIGUE;
- fa->strFunctionName = "疲劳检测";
- fa->StartTime = func.StartTime;
- fa->EndTime = func.EndTime;
- listFuncActionInfo.push_back(fa);
- }
- else if (func.AppType & 0x10)
- {
- auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_REGIONAL);
- if(pFuncActionInfo != nullptr)
- {
- /* 更新时间信息 */
- pFuncActionInfo->StartTime = func.StartTime;
- pFuncActionInfo->EndTime = func.EndTime;
- continue;
- }
- FuncActionInfo* fa = new FuncActionInfo;
- fa->ChannelID = func.ChannelID;
- fa->appFunction = AppFunction::APP_REGIONAL;
- fa->strFunctionName = "区域人员检测";
- fa->StartTime = func.StartTime;
- fa->EndTime = func.EndTime;
- listFuncActionInfo.push_back(fa);
- }
- else if (func.AppType & 0x20)
- {
- auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_MOUSE);
- if(pFuncActionInfo != nullptr)
- {
- /* 更新时间信息 */
- pFuncActionInfo->StartTime = func.StartTime;
- pFuncActionInfo->EndTime = func.EndTime;
- continue;
- }
- FuncActionInfo* fa = new FuncActionInfo;
- fa->ChannelID = func.ChannelID;
- fa->appFunction = AppFunction::APP_MOUSE;
- fa->strFunctionName = "老鼠识别";
- fa->StartTime = func.StartTime;
- fa->EndTime = func.EndTime;
- listFuncActionInfo.push_back(fa);
- }
- else if (func.AppType & 0x40)
- {
- auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_PLAYPHONE);
- if(pFuncActionInfo != nullptr)
- {
- /* 更新时间信息 */
- pFuncActionInfo->StartTime = func.StartTime;
- pFuncActionInfo->EndTime = func.EndTime;
- continue;
- }
- FuncActionInfo* fa = new FuncActionInfo;
- fa->ChannelID = func.ChannelID;
- fa->appFunction = AppFunction::APP_PLAYPHONE;
- fa->strFunctionName = "玩手机识别";
- fa->StartTime = func.StartTime;
- fa->EndTime = func.EndTime;
- listFuncActionInfo.push_back(fa);
- }
- else if (func.AppType & 0x80)
- {
- auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_NOMASK);
- if(pFuncActionInfo != nullptr)
- {
- /* 更新时间信息 */
- pFuncActionInfo->StartTime = func.StartTime;
- pFuncActionInfo->EndTime = func.EndTime;
- continue;
- }
- FuncActionInfo* fa = new FuncActionInfo;
- fa->ChannelID = func.ChannelID;
- fa->appFunction = AppFunction::APP_NOMASK;
- fa->strFunctionName = "未戴口罩识别";
- fa->StartTime = func.StartTime;
- fa->EndTime = func.EndTime;
- listFuncActionInfo.push_back(fa);
- }
- else if (func.AppType & 0x0100)
- {
- auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_ALLDOWN);
- if(pFuncActionInfo != nullptr)
- {
- /* 更新时间信息 */
- pFuncActionInfo->StartTime = func.StartTime;
- pFuncActionInfo->EndTime = func.EndTime;
- continue;
- }
- FuncActionInfo* fa = new FuncActionInfo;
- fa->ChannelID = func.ChannelID;
- fa->appFunction = AppFunction::APP_ALLDOWN;
- fa->strFunctionName = "摔倒识别";
- fa->StartTime = func.StartTime;
- fa->EndTime = func.EndTime;
- listFuncActionInfo.push_back(fa);
- }
- }
- return true;
- }
- /**
- * @brief 添加算法信息,根据传进来的算法ID,将其加入到对应的功能中
- *
- * @param info
- * @return true
- * @return false
- */
- bool ListFuncActInfo::addActionInfo(const ActionInfo& info)
- {
- if(info.ActionID.empty())
- {
- return false;
- }
- /* 人脸识别算法(人员在岗识别、非法入侵检测需要) */
- if(info.ActionID == g_actionList.ActFace)
- {
- /* 人员在岗识别 */
- auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_ONWORK);
- if(pFuncActionInfo != nullptr)
- {
- pFuncActionInfo->addActionInfo(info);
- }
- /* 非法入侵检测 */
- pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_ILLEGAL);
- if(pFuncActionInfo != nullptr)
- {
- pFuncActionInfo->addActionInfo(info);
- }
- }
- /* 人员计数 */
- else if (info.ActionID == g_actionList.ActPersonNumber)
- {
- auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_REGIONAL);
- if(pFuncActionInfo != nullptr)
- {
- pFuncActionInfo->addActionInfo(info);
- }
- }
- /* 违禁物品 */
- else if (info.ActionID == g_actionList.ActContraband)
- {
- auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_CONTRABAND);
- if(pFuncActionInfo != nullptr)
- {
- pFuncActionInfo->addActionInfo(info);
- }
- }
- /* 玩手机 */
- else if (info.ActionID == g_actionList.ActPlayPhone)
- {
- auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_PLAYPHONE);
- if(pFuncActionInfo != nullptr)
- {
- pFuncActionInfo->addActionInfo(info);
- }
- }
- /* 睡岗识别 */
- else if (info.ActionID == g_actionList.ActSleep)
- {
- auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_FATIGUE);
- if(pFuncActionInfo != nullptr)
- {
- pFuncActionInfo->addActionInfo(info);
- }
- }
- /* 疲劳检测 */
- else if(info.ActionID == g_actionList.ActFatigueDetection)
- {
- auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_FATIGUE);
- if(pFuncActionInfo != nullptr)
- {
- pFuncActionInfo->addActionInfo(info);
- }
- }
- /* 动物识别 */
- else if (info.ActionID == g_actionList.ActAnimalDetect)
- {
- auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_MOUSE);
- if(pFuncActionInfo != nullptr)
- {
- pFuncActionInfo->addActionInfo(info);
- }
- }
- /* 老鼠识别 */
- else if (info.ActionID == g_actionList.ActMouseDetect)
- {
- auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_MOUSE);
- if(pFuncActionInfo != nullptr)
- {
- pFuncActionInfo->addActionInfo(info);
- }
- }
- /* 口罩识别 */
- else if (info.ActionID == g_actionList.ActMask)
- {
- auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_NOMASK);
- if(pFuncActionInfo != nullptr)
- {
- pFuncActionInfo->addActionInfo(info);
- }
- }
- else {
- SPDLOG_WARN("未知的算法ID: {}", info.ActionID);
- return false;
- }
- return true;
- }
- /**
- * @brief 清空无用的功能信息
- * 摄像机和算法信息为空的,或者运行状态为STOP,都会被清理掉
- *
- */
- void ListFuncActInfo::clearNoneFuncActionInfo()
- {
- for(auto it0 = listFuncActionInfo.begin(); it0 != listFuncActionInfo.end();)
- {
- if((*it0)->listRoomCamActInfo.empty() || ((*it0)->RunState == RunTimeState::RUN_STATE_STOP))
- {
- delete *it0;
- it0 = listFuncActionInfo.erase(it0);
- }else {
- ++it0;
- }
- }
- }
- /* 清空算法列表 */
- void ListFuncActInfo::clearActionList()
- {
- for(auto& it0 : listFuncActionInfo)
- {
- it0->listRoomCamActInfo.clear();
- }
- }
- /* 查找应用信息 */
- bool ListFuncActInfo::findAppFunction(const AppFunction func)
- {
- for(const auto& it0 : listFuncActionInfo)
- {
- if(it0->appFunction == func)
- {
- return true;
- }
- }
- return false;
- }
- /* 根据频率和功能查找实例 */
- FuncActionInfo* ListFuncActInfo::findAppFunction(const int ChannelID, const AppFunction func)
- {
- for(const auto& it0 : listFuncActionInfo)
- {
- if( (it0->appFunction == func) && (it0->ChannelID == ChannelID) )
- {
- return it0;
- }
- }
- return nullptr;
- }
- /**
- * @brief 查找这个应用信息
- *
- * @param func
- * @return FuncActionInfo*
- */
- FuncActionInfo* ListFuncActInfo::findAppFunction(const FuncActionInfo& func)
- {
- for(const auto& it0 : listFuncActionInfo)
- {
- if(it0->ChannelID == func.ChannelID && it0->appFunction == func.appFunction)
- {
- return it0;
- }
- }
- return nullptr;
- }
- /* ====================================================================================
- * ************************** GlobalConfig成员函数 ******************************
- * ====================================================================================*/
- /* 创建实例 */
- GlobalConfig g_config;
- GlobalConfig::GlobalConfig()
- {
- ThreadSleepMS = 300;
- }
- /* 读取配置文件 */
- bool GlobalConfig::readConfig(const QString& strConfigFile)
- {
- if(strConfigFile.isEmpty())
- {
- SPDLOG_ERROR("读取配置文件失败! 配置文件名为空");
- return false;
- }
- SPDLOG_DEBUG("读取配置文件: {}", strConfigFile.toStdString());
- QSettings settings(strConfigFile, QSettings::IniFormat);
- settings.setIniCodec("UTF-8");
- settings.beginGroup("System");
- AppUpdateOnWorkTimeInterval = settings.value("WorkOnInfoSecond", 600).toInt(); /* 更新在岗信息的时间间隔 */
- AppPeopleOnWork = settings.value("APPPEPOLEONWORK", 300).toInt(); /* 离岗时间 */
- Contraband = settings.value("APPBADTHING", 50).toInt(); /* 违禁物品出现的时间 */
- AppBadMan = settings.value("APPBADMAN", 50).toInt(); /* 非法入侵 */
- AppTired = settings.value("APPTIRED", 50).toInt(); /* 疲劳检测时间 */
- AppPeopleCont = settings.value("APPPEPOLECONT", 50).toInt(); /* 人员聚集时间 */
- AppPlayPhone = settings.value("APPPLAYPHONE", 50).toInt(); /* 玩手机识别 */
- AppMouse = settings.value("APPMOUSE", 50).toInt(); /* 手势识别 */
- AppMask = settings.value("APPMASK", 5).toInt(); /* 戴口罩识别 */
- CheckSet = settings.value("CHECKSET", 300).toInt(); /* 服务端多久检测一次配置 */
- EventTimeValid = settings.value("EventTimeValid", 300).toInt(); /* 事件时间有效期 */
- Key = settings.value("Key").toString().toStdString(); /* Key */
- Secret = settings.value("Secret").toString().toStdString(); /* Secret */
- settings.endGroup();
- if(Key.empty() || Secret.empty())
- {
- SPDLOG_ERROR("读取配置文件失败! Key或Secret为空");
- return false;
- }
- return true;
- }
- /* 打印读取到的值 */
- void GlobalConfig::printValue()
- {
- SPDLOG_INFO("APPPEPOLEONWORK: {}", AppPeopleOnWork);
- SPDLOG_INFO("APPBADTHING: {}", Contraband);
- SPDLOG_INFO("APPBADMAN: {}", AppBadMan);
- SPDLOG_INFO("APPTIRED: {}", AppTired);
- SPDLOG_INFO("APPPEOPLECONT: {}", AppPeopleCont);
- SPDLOG_INFO("APPPLAYPHONE: {}", AppPlayPhone);
- SPDLOG_INFO("APPMOUSE: {}", AppMouse);
- SPDLOG_INFO("APPMASK: {}", AppMask);
- SPDLOG_INFO("CHECKSET: {}", CheckSet);
- SPDLOG_INFO("EventTimeValid: {}", EventTimeValid);
- }
|