From 8ece1bcf75056d8006e2d56721d1a6498e7d273c Mon Sep 17 00:00:00 2001 From: admin <zzjincn@163.com> Date: 星期二, 29 四月 2025 15:09:55 +0800 Subject: [PATCH] 写入redis处理加上失效ttl --- PreProcessFn.cpp | 257 ++++++++++++++++++++++++-------------------------- 1 files changed, 124 insertions(+), 133 deletions(-) diff --git a/PreProcessFn.cpp b/PreProcessFn.cpp index 70a2ea9..3c40632 100644 --- a/PreProcessFn.cpp +++ b/PreProcessFn.cpp @@ -255,7 +255,7 @@ //cout << current_time << endl; // 濡傛灉褰曞埗鏃堕棿瓒呰繃 10 绉掞紝鍒欏仠姝㈠綍鍒� if (seconds >= _recordtime) { - cout << "宸插綍鍒� 10 绉掕棰戯紝鍋滄褰曞埗" << endl; + std::cout << "宸插綍鍒� 10 绉掕棰戯紝鍋滄褰曞埗" << endl; video_writer.release(); } else @@ -284,7 +284,7 @@ if (mysql_query(mysql, query.c_str())) { string err_string = mysql_error(mysql); - cout << err_string << endl; + std::cout << err_string << endl; } } } @@ -321,7 +321,7 @@ if (mysql_query(mysql, query.c_str())) { string err_string = mysql_error(mysql); - cout << err_string << endl; + std::cout << err_string << endl; } } } @@ -355,9 +355,9 @@ std::string value = "1"; //鍐欏叆redis - reply = (redisReply*)redisCommand(context, "SET %s %s", key.c_str(), value.c_str()); + reply = (redisReply*)redisCommand(context, "SET %s %s EX %d", key.c_str(), value.c_str(),3); if (reply == NULL) { - printf("淇℃伅鍐欏叆redis澶辫触\n"); + printf("淇℃伅鍐欏叆redis澶辫触: %s\n", context->errstr); redisFree(context); } freeReplyObject(reply); @@ -524,6 +524,7 @@ return true; } +//json杞崲瀛楃涓� std::string jsontostr(Json::Value& json) { string return_str; @@ -758,132 +759,125 @@ std::string modelAnalysis =""; color_result = modelNode["color_result"].asString();//棰滆壊鍙嶆鍊� - // std::string area = modelNode["threshold"].asString();//鍖哄煙涓� - // std::string area2 = modelNode.get("area2", "").asString();//鍖哄煙浜� Json::Value rects = modelNode["point_rects"];////妯″瀷鍒嗘瀽绫诲瀷缂栫爜 for (auto k = 0; k < rects.size(); ++k) + { + Json::Value pointNode = rects[k]; + lable_title=pointNode["title"].asString(); + std::string point_type=pointNode["type"].asString(); + Json::Value point_Arr= pointNode["points"]; + for (auto x = 0; x < point_Arr.size(); ++x) { - Json::Value pointNode = rects[k]; - lable_title=pointNode["title"].asString(); - std::string point_type=pointNode["type"].asString(); - Json::Value point_Arr= pointNode["points"]; - for (auto x = 0; x < point_Arr.size(); ++x) + int croodx = stoi(point_Arr[x]["x"].asString()); + int croody = stoi(point_Arr[x]["y"].asString()); + if(point_type=="detectarea") { - int croodx = stoi(point_Arr[x]["x"].asString()); - int croody = stoi(point_Arr[x]["y"].asString()); - if(point_type=="detectarea") - { - detectarea.push_back(cv::Point(croodx, croody)); - } - if (point_type=="flowarea") - { - flowarea.push_back(cv::Point(croodx, croody)); - } - if (point_type=="flowrelate") - { - flowrelate.push_back(cv::Point(croodx, croody)); - } - if (point_type=="leftroller") - { - leftarea.push_back(cv::Point(croodx, croody)); - } - if (point_type=="rightroller") - { - rightarea.push_back(cv::Point(croodx, croody)); - } - if (point_type=="beltarea") - { - beltarea.push_back(cv::Point(croodx, croody)); - } - if (point_type=="workarea") - { - workarea.push_back(cv::Point(croodx, croody)); - } - + detectarea.push_back(cv::Point(croodx, croody)); + } + if (point_type=="flowarea") + { + flowarea.push_back(cv::Point(croodx, croody)); + } + if (point_type=="flowrelate") + { + flowrelate.push_back(cv::Point(croodx, croody)); + } + if (point_type=="leftroller") + { + leftarea.push_back(cv::Point(croodx, croody)); + } + if (point_type=="rightroller") + { + rightarea.push_back(cv::Point(croodx, croody)); + } + if (point_type=="beltarea") + { + beltarea.push_back(cv::Point(croodx, croody)); } - } + } + } int* arr = new int[detectarea.size() * 2]; //鍔犺浇妯″瀷澶勭悊------ if(modelCode=="1") //鐨甫鐘舵�� { - if (!rBelt.initConfig(modelPath.c_str(),arr)) - { - printf("鐨甫杩愯妯″瀷鍒濆鍖栧け璐ャ�俓n"); - } - else - { - printf("鐨甫杩愯妯″瀷鍒濆鍖栨垚鍔熴�俓n"); - rBelt.isLoad = true; - } - areaBelt =detectarea; - videoPathBelt = coalCode + ipccode + modelType + modelAnalysis; - wfBelt.setCoalCode(coalCode); - wfBelt.setCameraCode(ipccode); - wfBelt.setCameraName(ipcname); - wfBelt.setRtspUrl(ipcrtsppath); - wfBelt.setAnalyse(modelType); - //wfBelt.setAnalyseResult(modelAnalysis); + if (!rBelt.initConfig(modelPath.c_str(),arr)) + { + printf("鐨甫杩愯妯″瀷鍒濆鍖栧け璐ャ�俓n"); + } + else + { + printf("鐨甫杩愯妯″瀷鍒濆鍖栨垚鍔熴�俓n"); + rBelt.isLoad = true; + } + areaBelt =detectarea; + videoPathBelt = coalCode + ipccode + modelType + modelAnalysis; + wfBelt.setCoalCode(coalCode); + wfBelt.setCameraCode(ipccode); + wfBelt.setCameraName(ipcname); + wfBelt.setRtspUrl(ipcrtsppath); + wfBelt.setAnalyse(modelType); + wfBelt.setAnalyseResult(modelAnalysis); } if(modelCode=="2") //鎻愬崌鏈鸿繍琛屾娴嬫ā鍨� { if (!rTSJ.initConfig(modelPath.c_str(), arr)) - { - printf("鎻愬崌鏈烘ā鍨嬪垵濮嬪寲澶辫触銆俓n"); - } - else - { - printf("鎻愬崌鏈烘ā鍨嬪垵濮嬪寲鎴愬姛銆俓n"); - rTSJ.isLoad = true; - } - areaTSJ = detectarea; - videoPathTSJ = coalCode + ipccode + modelType; - wfTSJ.setCoalCode(coalCode); - wfTSJ.setCameraCode(ipccode); - wfTSJ.setCameraName(ipcname); - wfTSJ.setRtspUrl(ipcrtsppath); - wfTSJ.setAnalyse(modelType); - wfTSJ.setAnalyseResult(modelAnalysis); - break; + { + printf("鎻愬崌鏈烘ā鍨嬪垵濮嬪寲澶辫触銆俓n"); + } + else + { + printf("鎻愬崌鏈烘ā鍨嬪垵濮嬪寲鎴愬姛銆俓n"); + rTSJ.isLoad = true; + } + areaTSJ = detectarea; + videoPathTSJ = coalCode + ipccode + modelType; + wfTSJ.setCoalCode(coalCode); + wfTSJ.setCameraCode(ipccode); + wfTSJ.setCameraName(ipcname); + wfTSJ.setRtspUrl(ipcrtsppath); + wfTSJ.setAnalyse(modelType); + wfTSJ.setAnalyseResult(modelAnalysis); + break; } if(modelCode=="3") //浜哄憳鍖哄煙闂叆妯″瀷 { if (!hatJC.initConfig(modelPath.c_str(), 0.5, 0.5)) - { - printf("鐩爣妫�娴嬫ā鍨嬪垵濮嬪寲澶辫触\n"); - } - else - { - printf("鐩爣妫�娴嬫ā鍨嬪垵濮嬪寲鎴愬姛銆俓n"); - hatJC.isLoad = true; - } - areaPerson = detectarea;//鍗遍櫓鍖哄煙 - workareaPerson = workarea;//宸ヤ綔鍖哄煙 - videoPathPerson = coalCode + ipccode + modelType + modelAnalysis; - wfPerson.setCoalCode(coalCode); - wfPerson.setCameraCode(ipccode); - wfPerson.setCameraName(ipcname); - wfPerson.setRtspUrl(ipcrtsppath); - wfPerson.setAnalyse(modelType); - wfPerson.setAnalyseResult(modelAnalysis); + { + printf("鐩爣妫�娴嬫ā鍨嬪垵濮嬪寲澶辫触\n"); + } + else + { + printf("鐩爣妫�娴嬫ā鍨嬪垵濮嬪寲鎴愬姛銆俓n"); + hatJC.isLoad = true; + } + areaPerson = detectarea;//鍗遍櫓鍖哄煙 + workareaPerson = workarea;//宸ヤ綔鍖哄煙 + videoPathPerson = coalCode + ipccode + modelType + modelAnalysis; + wfPerson.setCoalCode(coalCode); + wfPerson.setCameraCode(ipccode); + wfPerson.setCameraName(ipcname); + wfPerson.setRtspUrl(ipcrtsppath); + wfPerson.setAnalyse(modelType); + wfPerson.setAnalyseResult(modelAnalysis); } if(modelCode=="4") //鎽勫儚澶撮伄鎸$畻娉� { if (!cover.initConfig()) { - printf("鎽勫儚澶撮伄鎸$畻娉曞垵濮嬪寲澶辫触\n"); - } - else - { - std::cout << "鎽勫儚澶撮伄鎸$畻娉曞垵濮嬪寲鎴愬姛" << std::endl; - cover.isLoad = true; - } - videoPathCameraCover = coalCode + ipccode + modelType + modelAnalysis; - wfCameraCover.setCoalCode(coalCode); - wfCameraCover.setCameraCode(ipccode); - wfCameraCover.setCameraName(ipcname); - wfCameraCover.setRtspUrl(ipcrtsppath); - wfCameraCover.setAnalyse(modelType); - wfCameraCover.setAnalyseResult(modelAnalysis); + printf("鎽勫儚澶撮伄鎸$畻娉曞垵濮嬪寲澶辫触\n"); + } + else + { + std::cout << "鎽勫儚澶撮伄鎸$畻娉曞垵濮嬪寲鎴愬姛" << std::endl; + cover.isLoad = true; + } + videoPathCameraCover = coalCode + ipccode + modelType + modelAnalysis; + wfCameraCover.setCoalCode(coalCode); + wfCameraCover.setCameraCode(ipccode); + wfCameraCover.setCameraName(ipcname); + wfCameraCover.setRtspUrl(ipcrtsppath); + wfCameraCover.setAnalyse(modelType); + wfCameraCover.setAnalyseResult(modelAnalysis); } if(modelCode=="5") //鎽勫儚澶寸Щ鍔ㄧ畻娉� { @@ -906,24 +900,25 @@ } if(modelCode=="6") //鍫嗙叅妫�娴嬫ā鍨� { - if (!dm.initConfig(modelPath.c_str(), arr)) { - printf("鍫嗙叅妯″瀷鍒濆鍖栧け璐n"); - } - else - { - std::cout << "鍫嗙叅妯″瀷鍒濆鍖栨垚鍔�" << std::endl; - dm.isLoad = true; - } - videoPathDM = coalCode + ipccode + modelType + modelAnalysis; - areaDM = detectarea; - limitDM = modelLimit;//鍫嗙叅闄愬畾鐓ら噺鍗犳瘮 + if (!dm.initConfig(modelPath.c_str(), arr)) + { + printf("鍫嗙叅妯″瀷鍒濆鍖栧け璐n"); + } + else + { + std::cout << "鍫嗙叅妯″瀷鍒濆鍖栨垚鍔�" << std::endl; + dm.isLoad = true; + } + videoPathDM = coalCode + ipccode + modelType + modelAnalysis; + areaDM = detectarea; + limitDM = modelLimit;//鍫嗙叅闄愬畾鐓ら噺鍗犳瘮 - wfDM.setCoalCode(coalCode); - wfDM.setCameraCode(ipccode); - wfDM.setCameraName(ipcname); - wfDM.setRtspUrl(ipcrtsppath); - wfDM.setAnalyse(modelType); - wfDM.setAnalyseResult(modelAnalysis); + wfDM.setCoalCode(coalCode); + wfDM.setCameraCode(ipccode); + wfDM.setCameraName(ipcname); + wfDM.setRtspUrl(ipcrtsppath); + wfDM.setAnalyse(modelType); + wfDM.setAnalyseResult(modelAnalysis); } if(modelCode=="7") //鐨甫璺戝亸鍜屽紓鐗╂娴� { @@ -1039,11 +1034,7 @@ wfFire.setAnalyse(modelType); wfFire.setAnalyseResult(modelAnalysis); } - if (modelCode == "12")//浜哄憳璺屽�� - { - - } - } + } std::queue<int> quTSJ;//璁板綍鎻愬崌鏈鸿繍鍔ㄧ殑鍒ゆ柇缁撴灉 std::queue<int> quBelt;//璁板綍鐨甫杩愬姩鍒ゆ柇缁撴灉 @@ -2029,7 +2020,7 @@ /// @brief 鎺ㄦ祦鍒版祦濯掍綋鏈嶅姟鍣� /// @param queJC2 澶勭悊瀹岀殑瑙嗛娴佸抚闃熷垪 /// @param ipccode 鎽勫儚鏈虹紪鍙� -void PreProcessFn::fnPushVideoToUrl(queue<Mat>& queJC2,string toRtsp, string fps, string ipccode) +void PreProcessFn::fnPushVideoToUrl(queue<Mat>& queJC2,string toRtsp, string fps, string video_size,string ipccode) { //瀹氫箟鎺ュ彈甯� Mat frame; @@ -2042,7 +2033,7 @@ "-f", "rawvideo", "-vcodec", "rawvideo", "-pix_fmt", "bgr24", - "-s", "1280x720", + "-s", video_size, "-r", fps, "-i", "-", "-pix_fmt", "yuv420p", -- Gitblit v1.8.0