From 9280d221d473730e81738628d1b247131f500a64 Mon Sep 17 00:00:00 2001
From: admin <zzjincn@163.com>
Date: 星期日, 27 四月 2025 17:56:44 +0800
Subject: [PATCH] 读写redis处理,未完工

---
 main.cpp |   87 +++++++++++++++++++++++++++----------------
 1 files changed, 55 insertions(+), 32 deletions(-)

diff --git a/main.cpp b/main.cpp
index dcf3838..da50a32 100644
--- a/main.cpp
+++ b/main.cpp
@@ -9,6 +9,7 @@
 #include <future>
 #include <json/json.h>
 #include "affine.h"
+#include <hiredis.h>
 #include "PreProcessFn.h"
 
 using namespace std;
@@ -16,8 +17,8 @@
 // 寮傛鍒濆鍖栫嚎绋嬫睜锛堟敼涓哄紓姝ヤ换鍔★級
 void AsyncInitThreadPool(PreProcessFn& ppf, const Json::Value& ipcsNode)
 { 
-    std::vector<std::queue<Mat>> queMatVec(ipcsNode["ipc"].size());//瑙嗛闃熷垪1
-    std::vector<std::queue<Mat>> queMatVec2(ipcsNode["ipc"].size());//瑙嗛闃熷垪2
+    std::vector<std::queue<Mat>> queMatVec(ipcsNode["cameras"].size());//瑙嗛闃熷垪1
+    std::vector<std::queue<Mat>> queMatVec2(ipcsNode["cameras"].size());//瑙嗛闃熷垪2
 
     std::vector<std::future<void>> getVideoTasks;//瑙嗛鍙栨祦浠诲姟闃熷垪
     std::vector<std::future<void>> recognitionTasks;//瑙嗛澶勭悊浠诲姟闃熷垪
@@ -27,22 +28,31 @@
     {
         ppf.asyncStop = false;
 
-        for (auto i = 0; i < ipcsNode["ipc"].size(); ++i) {
-            Json::Value ipcNode = ipcsNode["ipc"][i];
+        for (auto i = 0; i < ipcsNode["cameras"].size(); ++i) {
+            Json::Value ipcNode = ipcsNode["cameras"][i];
             std::string id = ipcNode["id"].asString();
-            std::string ipccode = ipcNode["ipccode"].asString();        
+            std::string ipccode = ipcNode["code"].asString();     
+            std::string name = ipcNode["name"].asString();       
             std::string video = ipcNode["video"].asString();
-            std::string pushflow = ipcNode["pushflow"].asString();
-            Json::Value modelsNode = ipcNode["models"];//妯″瀷鑺傜偣
+            long skipN = stol(ipcNode["skipN"].asString()); 
+            ppf.skipN = skipN;
+            std::string push_type = ipcNode["push_type"].asString();
+            std::string fps = ipcNode["fps"].asString();
+            std::string toRtmp = ipcNode["toRtmp"].asString();
+            std::string interval = ipcNode["interval"].asString();
+            Json::Value modelArray = ipcNode["model"];//妯″瀷鑺傜偣    
 
-            if (!modelsNode.isNull()) {
-                Json::Value modelArray = modelsNode["model"];        
-
-                // 鍒涘缓骞跺惎鍔ㄥ紓姝ヤ换鍔�
+               
+            if (!modelArray.isNull()) {
+                 // 鍒涘缓骞跺惎鍔ㄥ紓姝ヤ换鍔�
                 getVideoTasks.push_back(std::async(std::launch::async, &PreProcessFn::fnGetVideoMatToQueue, &ppf,video, std::ref(queMatVec[i])));
                 recognitionTasks.push_back(std::async(std::launch::async, &PreProcessFn::fnImRecognitionPro, &ppf, ipcNode,modelArray, std::ref(queMatVec[i]), std::ref(queMatVec2[i])));
-                pushVideoTasks.push_back(std::async(std::launch::async, &PreProcessFn::fnPushVideoInRabbitMQ, &ppf, std::ref(queMatVec2[i]), ipccode));
-                //pushVideoTasks.push_back(std::async(std::launch::async, &PreProcessFn::fnPushVideo, &ppf, std::ref(queMatVec2[i]), ipccode));
+               if (push_type == "rabbitmq") {
+                    pushVideoTasks.push_back(std::async(std::launch::async, &PreProcessFn::fnPushVideoInRabbitMQ, &ppf, std::ref(queMatVec2[i]), ipccode));
+               }
+               else if (push_type == "stream") {
+                   pushVideoTasks.push_back(std::async(std::launch::async, &PreProcessFn::fnPushVideoToUrl, &ppf, std::ref(queMatVec2[i]),toRtmp,fps, ipccode));
+               }
             }  
 
             //鍒濆鍖栨椂鍔犱釜寤惰繜
@@ -101,28 +111,41 @@
         
         Json::Value root;
         config_file >> root; 
-
+        
         // 鍒濆鍖栫嚎绋嬫睜锛堟敼涓哄紓姝ヤ换鍔★級
         PreProcessFn ppf;
-        ppf.coalCode= root["ipcs"]["coalCode"].asString();//鐓ょ熆缂栧彿;
-        ppf.warningFilePath = root["ipcs"]["warningFilePath"].asString();//褰曞儚淇濆瓨璺緞
-        ppf.redispath = root["ipcs"]["redispath"].asString();
-        ppf.redisport = root["ipcs"]["redisport"].asString();
-        ppf.redispass = root["ipcs"]["redispass"].asString();
-        ppf.mysqlpath = root["ipcs"]["mysqlpath"].asString();
-        ppf.mysqlport = root["ipcs"]["mysqlport"].asString();
-        ppf.mysqluser = root["ipcs"]["mysqluser"].asString();
-        ppf.mysqlpass = root["ipcs"]["mysqlpass"].asString();
-        ppf.mysqldatabase = root["ipcs"]["mysqldatabase"].asString();
-        ppf.rabbitpath = root["ipcs"]["rabbitpath"].asString();
-        ppf.rabbitport = root["ipcs"]["rabbitport"].asString();
-        ppf.rabbituser = root["ipcs"]["rabbituser"].asString();
-        ppf.rabbitpass = root["ipcs"]["rabbitpass"].asString();
-        ppf.deley = stol(root["ipcs"]["deley"].asString());//璺冲抚 
-        ppf.recordtime = stoi(root["ipcs"]["recordtime"].asString());//褰曞儚鏃堕棿
-        ppf.RecIntervalime = stoi(root["ipcs"]["RecIntervalime"].asString());//褰曞儚闂撮殧鏃堕棿 
+        ppf.coalCode= root["ipcs"]["coal_code"].asString();//鐓ょ熆缂栧彿;
+        ppf.warningFilePath = root["ipcs"]["warning_path"].asString();//褰曞儚淇濆瓨璺緞
+        ppf.redispath = root["redis"]["ip"].asString();
+        ppf.redisport = root["redis"]["port"].asString();  
+        ppf.redispass = root["redis"]["pwd"].asString();
+        ppf.mysqlpath = root["mysql"]["ip"].asString();
+        ppf.mysqlport = root["mysql"]["port"].asString();
+        ppf.mysqluser = root["mysql"]["user"].asString();
+        ppf.mysqlpass = root["mysql"]["pwd"].asString();
+        ppf.mysqldatabase = root["mysql"]["dbname"].asString();
+        ppf.rabbitpath = root["rabbit"]["ip"].asString();
+        ppf.rabbitport = root["rabbit"]["port"].asString();
+        ppf.rabbituser = root["rabbit"]["user"].asString();
+        ppf.rabbitpass = root["rabbit"]["pwd"].asString();
+        //ppf.deley = stol(root["ipcs"]["deley"].asString());//璺冲抚 
+        ppf.recordtime = stoi(root["ipcs"]["record_time"].asString());//褰曞儚鏃堕棿
+        //ppf.RecIntervalime = stoi(root["ipcs"]["RecIntervalime"].asString());//褰曞儚闂撮殧鏃堕棿 
+//鍔犺浇妯″瀷鏍囩棰滆壊
+				for (int i = 0; i < root["label_colors"].size(); i++)
+				{
+					Json::Value members = root["label_colors"][i];
 
-        AsyncInitThreadPool(ppf, root["ipcs"]); 
+					int nsize = members.size();
+					std::vector<int> numbers;
+					for (int j = 0; j < nsize; j++)
+					{
+						int crood = members[j].asInt();
+						numbers.push_back(crood);
+					}
+					ppf.c_list.push_back(numbers);
+				}
+        AsyncInitThreadPool(ppf, root); 
 
     }
     catch(const std::exception& e)

--
Gitblit v1.8.0