Quellcode durchsuchen

V0.2.5
1、完成了FuncAction的结构体
2、开始修改工作线程,目前还未修改完,还有错误

Apple vor 6 Monaten
Ursprung
Commit
4b6e11da8e

+ 143 - 3
SecurePlayAuxServer/GlobalInfo/GlobalInfo.cpp

@@ -573,6 +573,38 @@ bool ListFuncActInfo::addFuncActionInfo(AppFunction func)
     }
     FuncActionInfo* pFuncActionInfo = new FuncActionInfo;
     pFuncActionInfo->appFunction = func;
+    if(func == AppFunction::APP_ONWORK)
+    {
+        pFuncActionInfo->strFunctionName = "人员在岗识别";
+    }
+    else if(func == AppFunction::APP_ILLEGAL)
+    {
+        pFuncActionInfo->strFunctionName = "非法入侵检测";
+    }
+    else if(func == AppFunction::APP_REGIONAL)
+    {
+        pFuncActionInfo->strFunctionName = "人员计数";
+    }
+    else if(func == AppFunction::APP_CONTRABAND)
+    {
+        pFuncActionInfo->strFunctionName = "违禁物品";
+    }
+    else if(func == AppFunction::APP_PLAYPHONE)
+    {
+        pFuncActionInfo->strFunctionName = "玩手机";
+    }
+    else if(func == AppFunction::APP_FATIGUE)
+    {
+        pFuncActionInfo->strFunctionName = "疲劳检测";
+    }
+    else if(func == AppFunction::APP_MOUSE)
+    {
+        pFuncActionInfo->strFunctionName = "动物识别";
+    }
+    else if(func == AppFunction::APP_NOMASK)
+    {
+        pFuncActionInfo->strFunctionName = "口罩识别";
+    }
     listFuncActionInfo.push_back(pFuncActionInfo);
 
     return true;
@@ -591,16 +623,124 @@ bool ListFuncActInfo::addActionInfo(const ActionInfo& info)
     {
         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);
+    }
+    /* 人员计数 */
+    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)
 {

+ 4 - 3
SecurePlayAuxServer/GlobalInfo/GlobalInfo.h

@@ -455,7 +455,7 @@ public:
     std::string strFunctionName;    /* 功能名称 */
     std::chrono::system_clock::time_point StartTime;    /* 开始时间 */
     std::chrono::system_clock::time_point EndTime;      /* 结束时间 */
-    std::list<RoomCamActInfo> listRoomCamActInfo;    /* 房间内的摄像机和算法关联信息 */
+    std::list<RoomCamActInfo> listRoomCamActInfo;       /* 房间内的摄像机和算法关联信息 */
 
     FuncActionInfo();
     FuncActionInfo& operator=(FuncActionInfo& other);
@@ -478,8 +478,9 @@ public:
     bool addActionInfo(const ActionInfo& info);
     /* 清空无用的功能信息 */
     void clearNoneFuncActionInfo();
-    /* 查找功能信息 */
-    FuncActionInfo* findFuncActionInfo(const std::string& strFunctionName);
+    /* 清空房间和算法列表 */
+    void clearActionList();
+
     /* 获取容器 */
     std::list<FuncActionInfo*>& getData() {
         return listFuncActionInfo;

+ 7 - 7
SecurePlayAuxServer/SPAServer.cpp

@@ -901,9 +901,9 @@ bool SPAServer::updateRoomActionCameraCount(std::shared_ptr<RoomActionInfo> pRAI
 }
 
 /* 更新算法的摄像机ID,这里是从内存中的数组里获取 */
-bool SPAServer::updateActionCameraID(std::shared_ptr<ActionInfo> pInfo)
+bool SPAServer::updateActionCameraID(std::shared_ptr<FuncActionInfo> pInfo)
 {
-    pInfo->CameraID = -1;
+    pInfo->listRoomCamActInfo = -1;
     std::lock_guard<std::mutex> look(m_mutexRunAI);
     for(auto& it : m_runListActionInfo.getData())
     {
@@ -1067,23 +1067,23 @@ void SPAServer::threadActRegionalPersonnelDetection(RoomActionInfo* RAInfo)
  * 
  * @param info 线程信息
  */
-void SPAServer::threadActNormal(ActionInfo* info)
+void SPAServer::threadActNormal(FuncActionInfo* info)
 {
-    SPDLOG_LOGGER_INFO(m_logger, "开启 {} 线程,RoomID:{} ,Action:{}",info->strActionName, info->RoomID, info->ActionID);
+    SPDLOG_LOGGER_INFO(m_logger, "开启 {} 线程, ChannelID:{} ,Action:{}",info->strFunctionName, info->ChannelID, info->listRoomCamActInfo.front().mapCameraAction.begin()->second);
     /* 创建读取Redis的实例 */
     std::shared_ptr<FromRedis> fromRedis = std::make_shared<FromRedis>();
     /* 创建写入EQM数据库实例 */
     std::shared_ptr<ToEQMDataBase> toEQMDataBase = std::make_shared<ToEQMDataBase>();
     /* 局部变量,保存这个线程的信息 */
-    std::shared_ptr<ActionInfo> pActInfo = std::make_shared<ActionInfo>();
-    *pActInfo = *info;
+    std::shared_ptr<FuncActionInfo> pFuncAct = std::make_shared<FuncActionInfo>();
+    *pFuncAct = *info;
     /* 保存报警数据 */
     std::shared_ptr<AlarmInfo> pAlarmInfo = std::make_shared<AlarmInfo>();
 
     while (m_threadRunning)
     {
         /* 更新算法关联的摄像机ID */
-        updateActionCameraID(pActInfo);
+        updateActionCameraID(pFuncAct);
         /* 如果摄像机ID是小于0,那么这个算法就没有对应的摄像机了,线程就退出了 */
         if(pActInfo->CameraID < 0)
         {

+ 3 - 3
SecurePlayAuxServer/SPAServer.h

@@ -50,9 +50,9 @@ private:
     /* 更新房间、算法需要的摄像机个数 */
     bool updateRoomActionCameraCount(std::shared_ptr<RoomActionInfo> pRAInfo);
     /* 更新算法的摄像机ID */
-    bool updateActionCameraID(std::shared_ptr<ActionInfo> pInfo);
+    bool updateActionCameraID(std::shared_ptr<FuncActionInfo> pInfo);
     /* 设置线程状态 */
-    void setThreadState(std::shared_ptr<ActionInfo> pInfo, RunTimeState state);
+    void setThreadState(std::shared_ptr<FuncActionInfo> pInfo, RunTimeState state);
     void setThreadState(std::shared_ptr<RoomActionInfo> pInfo, RunTimeState state);
     
     /* 人员在岗识别线程,应该是人脸识别线程,这个需要房间内多个摄像机共同识别 */
@@ -60,7 +60,7 @@ private:
     /* 区域人员检测,检测这个区域内的人数,不能少于多少人,不能多余多少人 */
     void threadActRegionalPersonnelDetection(RoomActionInfo* RAInfo);
     /* 普通任务线程,一个算法值对应一个摄像机 */
-    void threadActNormal(ActionInfo* info);
+    void threadActNormal(FuncActionInfo* info);
     /* 非法入侵检测 */
     void threadActIllegalInvasion(ActionInfo* info);
     /* 人员计数 */