| | |
| | | //cout << current_time << endl; |
| | | // 如果录制时间超过 10 秒,则停止录制 |
| | | if (seconds >= _recordtime) { |
| | | cout << "已录制 10 秒视频,停止录制" << endl; |
| | | std::cout << "已录制 10 秒视频,停止录制" << endl; |
| | | video_writer.release(); |
| | | } |
| | | else |
| | |
| | | if (mysql_query(mysql, query.c_str())) |
| | | { |
| | | string err_string = mysql_error(mysql); |
| | | cout << err_string << endl; |
| | | std::cout << err_string << endl; |
| | | } |
| | | } |
| | | } |
| | |
| | | if (mysql_query(mysql, query.c_str())) |
| | | { |
| | | string err_string = mysql_error(mysql); |
| | | cout << err_string << endl; |
| | | std::cout << err_string << endl; |
| | | } |
| | | } |
| | | } |
| | |
| | | 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); |
| | |
| | | return true; |
| | | } |
| | | |
| | | //json转换字符串 |
| | | std::string jsontostr(Json::Value& json) |
| | | { |
| | | string return_str; |
| | |
| | | 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") //摄像头移动算法 |
| | | { |
| | |
| | | } |
| | | 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") //皮带跑偏和异物检测 |
| | | { |
| | |
| | | wfFire.setAnalyse(modelType); |
| | | wfFire.setAnalyseResult(modelAnalysis); |
| | | } |
| | | if (modelCode == "12")//人员跌倒 |
| | | { |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | std::queue<int> quTSJ;//记录提升机运动的判断结果 |
| | | std::queue<int> quBelt;//记录皮带运动判断结果 |
| | |
| | | /// @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; |
| | |
| | | "-f", "rawvideo", |
| | | "-vcodec", "rawvideo", |
| | | "-pix_fmt", "bgr24", |
| | | "-s", "1280x720", |
| | | "-s", video_size, |
| | | "-r", fps, |
| | | "-i", "-", |
| | | "-pix_fmt", "yuv420p", |