zhuanglj
2025-04-29 c402412da9e89c4927ac12b82ca2d8b7a4e0296b
添加推流分辨率参数
3个文件已修改
258 ■■■■ 已修改文件
PreProcessFn.cpp 253 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
PreProcessFn.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
main.cpp 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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;
        }
    }
}
@@ -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",
PreProcessFn.h
@@ -74,7 +74,7 @@
    void fnPushVideo(queue<Mat>& queJC2, string ipccode);
    void fnPushVideoToUrl(queue<Mat>& queJC2,string toRtsp, string fps,string ipccode);
    void fnPushVideoToUrl(queue<Mat>& queJC2,string toRtsp, string fps,string video_size,string ipccode);
};
main.cpp
@@ -37,6 +37,7 @@
            long skipN = stol(ipcNode["skipN"].asString()); 
            ppf.skipN = skipN;
            std::string push_type = ipcNode["push_type"].asString();
            std::string video_size = ipcNode["video_size"].asString();
            std::string fps = ipcNode["fps"].asString();
            std::string toRtmp = ipcNode["toRtmp"].asString();
            std::string interval = ipcNode["interval"].asString();
@@ -51,7 +52,7 @@
                    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));
                   pushVideoTasks.push_back(std::async(std::launch::async, &PreProcessFn::fnPushVideoToUrl, &ppf, std::ref(queMatVec2[i]),toRtmp,fps,video_size, ipccode));
               }
            }