From a01457b5471049edc3d8302c0d978cb8b53e79c9 Mon Sep 17 00:00:00 2001 From: admin <zzjincn@163.com> Date: 星期五, 25 四月 2025 14:54:15 +0800 Subject: [PATCH] 提交忽略文件 --- PreProcessFn.cpp | 477 ++++++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 306 insertions(+), 171 deletions(-) diff --git a/PreProcessFn.cpp b/PreProcessFn.cpp index 04e3fb7..86c2dce 100644 --- a/PreProcessFn.cpp +++ b/PreProcessFn.cpp @@ -342,7 +342,7 @@ int count = 0; long currentFrame = 1; - long skip_frame_num = deley;//璺冲抚闂撮殧璁剧疆锛堟瘡1甯э級 + long skip_frame_num = skipN;//璺冲抚闂撮殧璁剧疆锛堟瘡1甯э級 while (!asyncStop) { @@ -455,6 +455,27 @@ rtspStream.release(); } +std::string jsontostr(Json::Value& json) +{ + string return_str; + if(!json.isNull()&&!json.empty()) + { + for (int i = 0; i < json.size(); i++) + { + return_str += json[i].asString()+","; + } + if (!return_str.empty() && return_str.back() == ',') { + return_str.pop_back(); + } + + } + else + { + return_str = ""; + } + return return_str; +} + /// @brief 瑙嗛甯у鐞嗗嚱鏁� /// @param ipcsNode 鎽勫儚鏈鸿妭鐐� /// @param modelArray 妯″瀷鍒楄〃 @@ -462,10 +483,11 @@ /// @param queJC2 澶勭悊瀹岀殑瑙嗛娴佸抚闃熷垪 void PreProcessFn::fnImRecognitionPro(const Json::Value& ipcsNode, Json::Value modelArray, queue<Mat>& queJC, queue<Mat>& queJC2) { - std::string ipccode = ipcsNode["ipccode"].asString();//鎽勫儚鏈虹紪鐮� + std::string ipccode = ipcsNode["code"].asString();//鎽勫儚鏈虹紪鐮� std::string ipcname = ipcsNode["name"].asString();//鎽勫儚鏈哄悕绉� std::string ipcrtsppath = ipcsNode["video"].asString();//瑙嗛rtsp婧� - + // std::string skipN = ipcsNode["skipN"].asString();//璺冲抚 + // int skipN = ipcsNode["skipN"].asString();//璺冲抚 //mysql杩炴帴鍒濆鍖� MYSQL* mysql = mysql_init(nullptr); if (!mysql_real_connect(mysql, mysqlpath.c_str(), mysqluser.c_str(), mysqlpass.c_str(), mysqldatabase.c_str(), stoi(mysqlport), NULL, 0)) @@ -497,6 +519,14 @@ std::vector<Point> areaDM;//鍫嗙叅妫�娴嬪尯鍩� std::vector<Point> areaWear;//绌挎埓妫�娴嬪尯鍩� std::vector<Point> areaFire;//鐑熺伀妫�娴嬪尯鍩� + std::vector<Point> detectarea;//妫�娴嬪尯鍩� + std::vector<Point> flowarea;//鐨甫澶栧洿鍖哄煙 + std::vector<Point> flowrelate;//鐨甫鐩稿鍖哄煙 + std::vector<Point> leftarea;//宸︿晶鍖哄煙 + std::vector<Point> rightarea;//鍙充晶鍖哄煙 + std::vector<Point> beltarea;//涓棿鍖哄煙 + std::vector<Point> workarea;//宸ヤ綔鍖哄煙 + //妯″瀷澶勭悊 ------绗�2姝� RUN rBelt;//鐨甫杩愯妯″瀷 @@ -626,152 +656,201 @@ //鎻愬崌鏈哄拰鐨甫鍒ゆ柇鏃讹紝闇�瑕佺疮璁′笁寮犲浘鐗囨墠鑳借繘琛屽垽鏂� std::vector<cv::Mat> imagesTsj; std::vector<cv::Mat> imagesBelt; - + std::string color_result; + std::string lable_title; cout <<modelArray.size()<<endl; //寰幆姣忎釜鎽勫儚澶寸殑妯″瀷锛屽姞杞芥ā鍨� for (int j = 0; j < modelArray.size(); ++j) { Json::Value modelNode = modelArray[j]; - std::string modelPath = modelNode["modelpath"].asString(); - std::string modelPath2 = modelNode["modelpath2"].asString();//妯″瀷2璺緞 - std::string imagePath = modelNode["imagepath"].asString(); + std::string modelCode = modelNode["code"].asString();//妯″瀷缂栫爜 鍖哄垎鍔犺浇涓嶅悓鐨勬ā鍨� + std::string modelPath = modelNode["path"].asString(); + std::string modelPath2 = modelNode["path2"].asString();//妯″瀷2璺緞 + std::string imagePath = modelNode["img_path"].asString(); + std::string modelName = modelNode["name"].asString(); - std::string modelType = modelNode["type"].asString();//妯″瀷鍒嗘瀽绫诲瀷缂栫爜 - std::string modelAnalysis = modelNode["analysis"].asString();//妯″瀷鍒嗘瀽缁撴灉缂栫爜 - std::string leftarea = modelNode.get("leftarea", "").asString();//鐨甫宸︿晶鍖哄煙 - std::string rightarea = modelNode.get("rightarea", "").asString();//鐨甫鍙充晶鍖哄煙 - std::string area = modelNode.get("area", "").asString();//鍖哄煙涓� - std::string area2 = modelNode.get("area2", "").asString();//鍖哄煙浜� - std::string modelLimit = modelNode["limit"].asString(); - std::string modelLimit2 = modelNode.get("limit2", "").asString();//鐨甫绌鸿浇闄愬畾鍊� - std::string modelId = modelNode["modelid"].asString();//妯″瀷id锛屽尯鍒嗗姞杞戒笉鍚岀殑妯″瀷 + Json::Value modelTypeArr = modelNode["type"];////妯″瀷鍒嗘瀽绫诲瀷缂栫爜 + std::string modelType = jsontostr(modelTypeArr); + double threshold = stod(modelNode["threshold"].asString());//闃堝�� + float modelLimit = stof(modelNode["limit"].asString());//闄愬畾鍊� + 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) + { + 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)); + } + + } + } + + int* arr = new int[detectarea.size() * 2]; //鍔犺浇妯″瀷澶勭悊------ - switch (stoi(modelId)) + if(modelCode=="1") //鐨甫鐘舵�� { - case 1://鐨甫鐘舵�� - if (!rBelt.initConfig(modelPath.c_str(), stringToIntArray(area))) - { - printf("鐨甫杩愯妯″瀷鍒濆鍖栧け璐ャ�俓n"); - } - else - { - printf("鐨甫杩愯妯″瀷鍒濆鍖栨垚鍔熴�俓n"); - rBelt.isLoad = true; - } - areaBelt = stringToPoints(area); - videoPathBelt = coalCode + ipccode + modelType + modelAnalysis; - wfBelt.setCoalCode(coalCode); - wfBelt.setCameraCode(ipccode); - wfBelt.setCameraName(ipcname); - wfBelt.setRtspUrl(ipcrtsppath); - wfBelt.setAnalyse(modelType); - wfBelt.setAnalyseResult(modelAnalysis); - break; - - case 2://鎻愬崌鏈鸿繍琛屾娴嬫ā鍨� - if (!rTSJ.initConfig(modelPath.c_str(), stringToIntArray(area))) - { - printf("鎻愬崌鏈烘ā鍨嬪垵濮嬪寲澶辫触銆俓n"); - } - else - { - printf("鎻愬崌鏈烘ā鍨嬪垵濮嬪寲鎴愬姛銆俓n"); - rTSJ.isLoad = true; - } - areaTSJ = stringToPoints(area); - videoPathTSJ = coalCode + ipccode + modelType; - wfTSJ.setCoalCode(coalCode); - wfTSJ.setCameraCode(ipccode); - wfTSJ.setCameraName(ipcname); - wfTSJ.setRtspUrl(ipcrtsppath); - wfTSJ.setAnalyse(modelType); - wfTSJ.setAnalyseResult(modelAnalysis); - break; - - case 3://鍖哄煙闂叆妯″瀷 - + 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; + } + if(modelCode=="3") //浜哄憳鍖哄煙闂叆妯″瀷 + { if (!hatJC.initConfig(modelPath.c_str(), 0.5, 0.5)) - { - printf("鐩爣妫�娴嬫ā鍨嬪垵濮嬪寲澶辫触\n"); - } - else - { - printf("鐩爣妫�娴嬫ā鍨嬪垵濮嬪寲鎴愬姛銆俓n"); - hatJC.isLoad = true; - } - areaPerson = stringToPoints(area);//鍗遍櫓鍖哄煙 - workareaPerson = stringToPoints(area2);//宸ヤ綔鍖哄煙 - videoPathPerson = coalCode + ipccode + modelType + modelAnalysis; - wfPerson.setCoalCode(coalCode); - wfPerson.setCameraCode(ipccode); - wfPerson.setCameraName(ipcname); - wfPerson.setRtspUrl(ipcrtsppath); - wfPerson.setAnalyse(modelType); - wfPerson.setAnalyseResult(modelAnalysis); - - break; - - case 4://鎽勫儚澶撮伄鎸$畻娉� + { + 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); - break; - - case 5://鎽勫儚澶寸Щ鍔ㄧ畻娉� + 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") //鎽勫儚澶寸Щ鍔ㄧ畻娉� + { if (!camera.initConfig()) { - printf("鎽勫儚澶寸Щ鍔ㄧ畻娉曞垵濮嬪寲澶辫触\n"); - } - else - { - std::cout << "鎽勫儚澶寸Щ鍔ㄧ畻娉曞垵濮嬪寲鎴愬姛" << std::endl; - camera.isLoad = true; - camera.stdMat = cv::imread(imagePath); - } - videoPathCameraMove = coalCode + ipccode + modelType + modelAnalysis; - wfCameraMove.setCoalCode(coalCode); - wfCameraMove.setCameraCode(ipccode); - wfCameraMove.setCameraName(ipcname); - wfCameraMove.setRtspUrl(ipcrtsppath); - wfCameraMove.setAnalyse(modelType); - wfCameraMove.setAnalyseResult(modelAnalysis); - break; + printf("鎽勫儚澶寸Щ鍔ㄧ畻娉曞垵濮嬪寲澶辫触\n"); + } + else + { + std::cout << "鎽勫儚澶寸Щ鍔ㄧ畻娉曞垵濮嬪寲鎴愬姛" << std::endl; + camera.isLoad = true; + camera.stdMat = cv::imread(imagePath); + } + videoPathCameraMove = coalCode + ipccode + modelType + modelAnalysis; + wfCameraMove.setCoalCode(coalCode); + wfCameraMove.setCameraCode(ipccode); + wfCameraMove.setCameraName(ipcname); + wfCameraMove.setRtspUrl(ipcrtsppath); + wfCameraMove.setAnalyse(modelType); + wfCameraMove.setAnalyseResult(modelAnalysis); + } + 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;//鍫嗙叅闄愬畾鐓ら噺鍗犳瘮 - case 6://鍫嗙叅妫�娴嬫ā鍨� - if (!dm.initConfig(modelPath.c_str(), stringToIntArray(area))) { - printf("鍫嗙叅妯″瀷鍒濆鍖栧け璐n"); - } - else - { - std::cout << "鍫嗙叅妯″瀷鍒濆鍖栨垚鍔�" << std::endl; - dm.isLoad = true; - } - videoPathDM = coalCode + ipccode + modelType + modelAnalysis; - areaDM = stringToPoints(area2); - limitDM = modelLimit;//鍫嗙叅闄愬畾鐓ら噺鍗犳瘮 + wfDM.setCoalCode(coalCode); + wfDM.setCameraCode(ipccode); + wfDM.setCameraName(ipcname); + wfDM.setRtspUrl(ipcrtsppath); + wfDM.setAnalyse(modelType); + wfDM.setAnalyseResult(modelAnalysis); + } + if(modelCode=="7") //鐨甫璺戝亸鍜屽紓鐗╂娴� + { + int* leftarr = new int[leftarea.size() * 2]; + int* rightarr = new int[rightarea.size() * 2]; + int* midd_arr = new int[beltarea.size() * 2]; - wfDM.setCoalCode(coalCode); - wfDM.setCameraCode(ipccode); - wfDM.setCameraName(ipcname); - wfDM.setRtspUrl(ipcrtsppath); - wfDM.setAnalyse(modelType); - wfDM.setAnalyseResult(modelAnalysis); - break; - - case 7://鐨甫璺戝亸鍜屽紓鐗╂娴� - if (!beltJC.initConfig(modelPath.c_str(), stringToIntArray(leftarea), stringToIntArray(rightarea), stringToIntArray(area),stof(modelLimit))) + if (!beltJC.initConfig(modelPath.c_str(), leftarr, rightarr, midd_arr, modelLimit)) { printf("鐨甫璺戝亸鍜屽紓鐗╂娴嬫ā鍨嬪垵濮嬪寲澶辫触\n"); } @@ -780,9 +859,9 @@ printf("鐨甫璺戝亸鍜屽紓鐗╂娴嬫ā鍨嬪垵濮嬪寲鎴愬姛銆俓n"); beltJC.isLoad = true; } - leftareaBeltJC = stringToPoints(leftarea); - rightareaBeltJC = stringToPoints(rightarea); - areaBeltJC = stringToPoints(area); + leftareaBeltJC = leftarea; + rightareaBeltJC = rightarea; + areaBeltJC = beltarea; videoPathBeltJC = coalCode + ipccode + modelType + modelAnalysis; wfBeltJC.setCoalCode(coalCode); wfBeltJC.setCameraCode(ipccode); @@ -790,8 +869,9 @@ wfBeltJC.setRtspUrl(ipcrtsppath); wfBeltJC.setAnalyse(modelType); wfBeltJC.setAnalyseResult(modelAnalysis); - break; - case 8://鐚磋溅澶х墿浠� + } + if(modelCode=="8") //鐚磋溅澶х墿浠� + { if (!hatHC.initConfig(modelPath.c_str(), 0.5, 0.5)) { printf("涔樼尨杞︽惡甯﹀ぇ浠舵ā鍨嬪垵濮嬪寲澶辫触\n"); @@ -801,7 +881,7 @@ printf("涔樼尨杞︽惡甯﹀ぇ浠舵ā鍨嬪垵濮嬪寲鎴愬姛銆俓n"); hatHC.isLoad = true; } - areaHC = stringToPoints(area); + areaHC = detectarea; videoPathHC = coalCode + ipccode + modelType + modelAnalysis; wfHC.setCoalCode(coalCode); wfHC.setCameraCode(ipccode); @@ -809,9 +889,10 @@ wfHC.setRtspUrl(ipcrtsppath); wfHC.setAnalyse(modelType); wfHC.setAnalyseResult(modelAnalysis); - break; + } - case 9://鐫″矖鍒ゆ柇 + if (modelCode == "9")//鐫″矖鍒ゆ柇 + { if (!hatSleep.initConfig(modelPath.c_str(), 0.5, 0.5)) { printf("鐫″矖妯″瀷鍒濆鍖栧け璐n"); @@ -821,7 +902,7 @@ printf("鐫″矖妯″瀷鍒濆鍖栨垚鍔熴�俓n"); hatSleep.isLoad = true; } - areaSleep = stringToPoints(area); + areaSleep = detectarea; videoPathSleep = coalCode + ipccode + modelType + modelAnalysis; wfSleep.setCoalCode(coalCode); wfSleep.setCameraCode(ipccode); @@ -829,9 +910,9 @@ wfSleep.setRtspUrl(ipcrtsppath); wfSleep.setAnalyse(modelType); wfSleep.setAnalyseResult(modelAnalysis); - break; - - case 11://绌挎埓妫�娴�,鍒濆鍖栦袱涓ā鍨� + } + if (modelCode == "10")//绌挎埓妫�娴�,鍒濆鍖栦袱涓ā鍨� + { if (!hatWear.initConfig(modelPath.c_str(), 0.5, 0.5)) { printf("绌挎埓妯″瀷1鍒濆鍖栧け璐n"); @@ -849,7 +930,7 @@ } hatWear.isLoad = true; } - areaWear = stringToPoints(area); + areaWear = detectarea; videoPathWear = coalCode + ipccode + modelType + modelAnalysis; wfWear.setCoalCode(coalCode); wfWear.setCameraCode(ipccode); @@ -857,10 +938,9 @@ wfWear.setRtspUrl(ipcrtsppath); wfWear.setAnalyse(modelType); wfWear.setAnalyseResult(modelAnalysis); - - break; - case 12://鐑熺伀妯″瀷 - + } + if (modelCode == "11")//鐑熺伀妯″瀷 + { if (!hatFire.initConfig(modelPath.c_str())) { printf("鐑熺伀妯″瀷鍒濆鍖栧け璐n"); } @@ -869,7 +949,7 @@ printf("鐑熺伀妯″瀷鍒濆鍖栨垚鍔熴�俓n"); hatFire.isLoad = true; } - areaFire = stringToPoints(area); + areaFire = detectarea; videoPathFire = coalCode + ipccode + modelType + modelAnalysis; wfFire.setCoalCode(coalCode); wfFire.setCameraCode(ipccode); @@ -877,9 +957,10 @@ wfFire.setRtspUrl(ipcrtsppath); wfFire.setAnalyse(modelType); wfFire.setAnalyseResult(modelAnalysis); - break; - default: - break; + } + if (modelCode == "12")//浜哄憳璺屽�� + { + } } @@ -891,7 +972,7 @@ Mat iMatWear;//浜哄憳绌挎埓鐨勭涓�甯� long currentFrame = 1;//璁板綍褰撳墠甯ф暟 - long skip_frame_num = deley;//璺冲抚闂撮殧璁剧疆 + long skip_frame_num = skipN;//璺冲抚闂撮殧璁剧疆 Mat frame; while (!asyncStop) { @@ -930,7 +1011,7 @@ //浜哄憳闂叆妯″瀷澶勭悊鍙婂垽鏂� modelId = 3 if (hatJC.isLoad) { - futurePerson = std::async(std::launch::async, &PreProcessModel::fnImRecProByModelHAT, &ppm, std::ref(frame), std::ref(hatJC), areaPerson,workareaPerson); + futurePerson = std::async(std::launch::async, &PreProcessModel::fnImRecProByModelHAT1, &ppm, std::ref(frame), std::ref(hatJC), areaPerson,workareaPerson,c_list,lable_title,color_result); } //鎽勫儚澶寸Щ鍔ㄥ拰閬尅涓撶敤 @@ -1659,14 +1740,14 @@ Mat frame; long currentFrame = 1; - long skip_frame_num = deley;//璺冲抚闂撮殧璁剧疆锛堟瘡1甯э級 + long skip_frame_num = skipN;//璺冲抚闂撮殧璁剧疆锛堟瘡1甯э級 //鍒涘缓url杩炴帴锛屽畾鏃跺垽鏂湁娌℃湁椤甸潰杩涜鎷夋祦 CURL* curl; CURLcode res; std::string readBuffer; curl = curl_easy_init(); - bool pushflg = false;//鏄惁鎺ㄦ祦鏍囧織 + bool pushflg = true;//鏄惁鎺ㄦ祦鏍囧織 if(curl) { @@ -1745,17 +1826,7 @@ //cv::resize(frame, frame, Size(1280, 720)); imgStr = Mat2Base64(frame, ".jpg");//杈撳嚭Base64缂栫爜鐨勫瓧绗︿覆 - //std::cout << "Base64 size: " << imgStr.size() << std::endl; - - // // 缂栫爜涓篔PEG鏍煎紡鐨勪簩杩涘埗鏁版嵁 - // std::vector<uchar> encoded; - // std::vector<int> params = {cv::IMWRITE_JPEG_QUALITY, 90}; - // cv::imencode(".jpg", frame, encoded, params); - // imgStr = std::string(reinterpret_cast<const char*>(encoded.data()), encoded.size()); - // std::cout << "Binary size: " << imgStr.size() << std::endl; - - //cout << getCurrentDateTime("%Y%m%d%H%M%S") << endl; - + //std::cout << "Base64 size: " << imgStr.size() << std::endl; objRabbitmq.Publish(imgStr, ipccode, ""); //cv::resize(frame, frame, Size(1280, 720)); @@ -1850,3 +1921,67 @@ frame.release(); } + + +/// @brief 鎺ㄦ祦鍒版祦濯掍綋鏈嶅姟鍣� +/// @param queJC2 澶勭悊瀹岀殑瑙嗛娴佸抚闃熷垪 +/// @param ipccode 鎽勫儚鏈虹紪鍙� +void PreProcessFn::fnPushVideoToUrl(queue<Mat>& queJC2,string toRtsp, string fps, string ipccode) +{ + //瀹氫箟鎺ュ彈甯� + Mat frame; + + while (!asyncStop) { + //std::cout << ipccode + "褰撳墠绾跨▼Rabbitmq鏁版嵁鏁伴噺2222:" << queJC2.size() << std::endl; + try + { + if (queJC2.size() > 500) + { + cout << "鎺ㄩ�佽棰戞椂锛屽瓨鍦ㄥ唴瀛樻孩鍑洪闄╋紒" << endl; + } + + if (queJC2.empty() || queJC2.size() == 0) + { + continue; + } + + frame = queJC2.front(); + queJC2.pop(); + + if (frame.empty())//甯т负绌猴紝鍒欒垗寮� + continue; + + // FFmpeg鎺ㄦ祦鍛戒护 + std::string ffmpeg_command = + "ffmpeg -y -f rawvideo -pixel_format bgr24 -video_size 640x480 " + "-framerate 30 -i - -c:v libx264 -pix_fmt yuv420p -f rtsp " + "rtsp://192.168.1.8:8554/live/stream"; + + // 鎵撳紑FFmpeg杩涚▼ + FILE* pipe = popen(ffmpeg_command.c_str(), "w"); + if (!pipe) { + std::cerr << "鏃犳硶鍚姩FFmpeg" << std::endl; + } + + // 灏嗗抚鍐欏叆鍒癋Fmpeg绠¢亾涓� + fwrite(frame.data, 1, frame.total() * frame.elemSize(), pipe); + + //cv::resize(frame, frame, Size(1280, 720)); + //cv::imshow(ipccode, frame);//灞曠ず甯у浘鐗� + //waitKey(10); + + //std::this_thread::sleep_for(std::chrono::milliseconds(10));// 寤惰繜绛夊緟涓�娈垫椂闂� + + } + catch (const std::exception& ex) + { + std::string errorMessage = "淇濆瓨鍒癛abbitMQ澶辫触:-"; + errorMessage += ex.what(); + cout << errorMessage << endl; + continue; + } + } + + frame.release(); +} + -- Gitblit v1.8.0