12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271 |
- #include "GlobalVariable.h"
- #include "spdlog/spdlog.h"
- #include "FuncBase.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;
- Is_InsertEQM = 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();
- appFunction = AppFunction::APP_NONE;
- }
- AlarmInfo::AlarmInfo(const AlarmInfo& other)
- {
- Is_Alarm = other.Is_Alarm;
- Is_InsertEQM = other.Is_InsertEQM;
- 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;
- appFunction = other.appFunction;
- }
- AlarmInfo& AlarmInfo::operator=(AlarmInfo& other)
- {
- if(this != &other)
- {
- Is_Alarm = other.Is_Alarm;
- Is_InsertEQM = other.Is_InsertEQM;
- 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;
- appFunction = other.appFunction;
- }
- 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();
- appFunction = AppFunction::APP_NONE;
- }
- /**
- * @brief 添加报警信息
- *
- * @param info
- * @return true
- * @return false
- */
- bool ListAlarmInfo::addAlarmInfo(AlarmInfo& info)
- {
- /* 先查找有没有重复的 */
- auto p = findAlarmInfo(info);
- if(p != nullptr)
- {
- return false;
- }
- AlarmInfo* pNew = new AlarmInfo(info);
- listAlarmInfo.push_back(pNew);
- 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;
- }
- /* 删除报警记录 */
- void ListAlarmInfo::deleteAlarmInfo(AlarmInfo& info)
- {
- for(auto it = listAlarmInfo.begin(); it != listAlarmInfo.end();)
- {
- if((*it)->ChannelID == info.ChannelID && (*it)->RoomID == info.RoomID && (*it)->DeviceID == info.DeviceID && (*it)->ActionID == info.ActionID)
- {
- delete *it;
- it = listAlarmInfo.erase(it);
- }else {
- ++it;
- }
- }
- }
- /* 查找是否有相同的人脸信息 */
- 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(const 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=(const 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(const 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=(const 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;
- }
- PersonCountRuleInfo::PersonCountRuleInfo()
- {
- ChannelID = -1;
- week = 0;
- RuleType = 0;
- 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 = "";
- }
- PersonCountRuleInfo& PersonCountRuleInfo::operator=(PersonCountRuleInfo& other)
- {
- if(this != &other)
- {
- ChannelID = other.ChannelID;
- week = other.week;
- RuleType = other.RuleType;
- PeriodName = other.PeriodName;
- StartTime = other.StartTime;
- EndTime = other.EndTime;
- 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()
- {
-
- }
- 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;
- }
- /**
- * @brief 添加算法信息,这里不能直接创建房间,需要先判断有没有已有的房间,因为有的应用功能可能会包含多个房间
- * 已经提前被创建过了
- *
- * @param info
- * @return true
- * @return false
- */
- 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));
- break;
- }
- }
- /* 没找到这个房间,就创建 */
- 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;
- }
|