| | |
| | | } |
| | | } |
| | | |
| | | int ToWchar(char* &src, wchar_t* &dest, const char *locale = "zh_CN.utf8") |
| | | { |
| | | if (src == NULL) { |
| | | dest = NULL; |
| | | return 0; |
| | | } |
| | | |
| | | // 根据环境变量设置locale |
| | | setlocale(LC_CTYPE, locale); |
| | | |
| | | // 得到转化为需要的宽字符大小 |
| | | int w_size = mbstowcs(NULL, src, 0) + 1; |
| | | |
| | | // w_size = 0 说明mbstowcs返回值为-1。即在运行过程中遇到了非法字符(很有可能使locale |
| | | // 没有设置正确) |
| | | if (w_size == 0) { |
| | | dest = NULL; |
| | | return -1; |
| | | } |
| | | |
| | | //wcout << "w_size" << w_size << endl; |
| | | dest = new wchar_t[w_size]; |
| | | if (!dest) { |
| | | return -1; |
| | | } |
| | | |
| | | int ret = mbstowcs(dest, src, strlen(src)+1); |
| | | if (ret <= 0) { |
| | | return -1; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | // 在图像上绘制带有背景的文本 |
| | | void drawTextWithBackground(Mat& image, const string& text, int txalign, const Point& orgxy, const Point& orgwh, Scalar bgColor) |
| | | { |
| | |
| | | { |
| | | CvxText chinese = CvxText("SimHei.ttf"); |
| | | //设置位置和字体参数 |
| | | Scalar textColor(0, 0, 0);//白色文本 |
| | | Scalar textColor(255, 255, 255);//白色文本 |
| | | //Scalar bgColor(0, 255, 0);//绿色背景 |
| | | int fontFace = FONT_HERSHEY_SIMPLEX; |
| | | int fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX; |
| | | double fontScale = 0.2; |
| | | int thickness = 1; |
| | | |
| | |
| | | Size textSize = getTextSize(text, fontFace, fontScale, thickness, 0); |
| | | |
| | | //计算文本背景矩形框的大小 |
| | | Rect backgroundRect(orgxy.x, orgxy.y - textSize.height - 30, orgwh.x, textSize.height + 30); |
| | | |
| | | //Rect backgroundRect(orgxy.x, orgxy.y - textSize.height - 30, orgwh.x, textSize.height + 30); |
| | | if (text.length() >= 6) |
| | | { |
| | | Rect backgroundRect(orgxy.x, orgxy.y - textSize.height - 30, orgwh.x + textSize.width + 30, textSize.height + 30); |
| | | //绘制文本背景 |
| | | cv::rectangle(image, backgroundRect, bgColor, FILLED); |
| | | } |
| | | else |
| | | { |
| | | Rect backgroundRect(orgxy.x, orgxy.y - textSize.height - 30, orgwh.x, textSize.height + 30); |
| | | //绘制文本背景 |
| | | cv::rectangle(image, backgroundRect, bgColor, FILLED); |
| | | } |
| | | //绘制文本背景 |
| | | rectangle(image, backgroundRect, bgColor, FILLED); |
| | | //rectangle(image, backgroundRect, bgColor, FILLED); |
| | | |
| | | //CvxText chinese(ttfFont); |
| | | //设置字体的大小 / 空白比例 / 间隔比较 / 旋转角度 |
| | | Scalar size(30, 0.5, 0, 0); |
| | | //Scalar size(30, 0.5, 0, 0); |
| | | Scalar size(25, 0, 0.1, 0); |
| | | float p = 1.0f; //设置字体的透明度 |
| | | //设置字体 |
| | | chinese.setFont(nullptr, &size, nullptr, &p); |
| | |
| | | { |
| | | case 1://文字左对齐 |
| | | //绘制文本 |
| | | chinese.putText(image, text.c_str(), cv::Point(orgxy.x + 5, (orgxy.y - (orgwh.y / 2) - 2)), textColor); |
| | | |
| | | //chinese.putText(image, text.c_str(), cv::Point(orgxy.x + 5, (orgxy.y - (orgwh.y / 2) - 2)), textColor); |
| | | chinese.putText(image, text.c_str(), cv::Point(orgxy.x + 5, orgxy.y - 8), textColor); |
| | | break; |
| | | case 2://文字居中 |
| | | //绘制文本 |
| | |
| | | } |
| | | |
| | | } |
| | | // 在图像上绘制带有背景的文本 |
| | | void drawTextWithBackgroundWstr(Mat& image, const string& _text, int txalign, const Point& orgxy, const Point& orgwh, Scalar bgColor) |
| | | { |
| | | try |
| | | { |
| | | |
| | | |
| | | std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter; |
| | | std::wstring text = converter.from_bytes(_text); |
| | | |
| | | CvxText chinese = CvxText("SimHei.ttf"); |
| | | //设置位置和字体参数 |
| | | Scalar textColor(255, 255, 255);//白色文本 |
| | | //Scalar bgColor(0, 255, 0);//绿色背景 |
| | | int fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX; |
| | | double fontScale = 0.2; |
| | | int thickness = 1; |
| | | |
| | | // 获取文字长度大小 |
| | | Size textSize = getTextSize(_text, fontFace, fontScale, thickness, 0); |
| | | |
| | | //计算文本背景矩形框的大小 |
| | | //Rect backgroundRect(orgxy.x, orgxy.y - textSize.height - 30, orgwh.x, textSize.height + 30); |
| | | if (text.length() >= 6) |
| | | { |
| | | Rect backgroundRect(orgxy.x, orgxy.y - textSize.height - 30, orgwh.x + textSize.width + 30, textSize.height + 30); |
| | | //绘制文本背景 |
| | | cv::rectangle(image, backgroundRect, bgColor, FILLED); |
| | | } |
| | | else |
| | | { |
| | | Rect backgroundRect(orgxy.x, orgxy.y - textSize.height - 30, orgwh.x, textSize.height + 30); |
| | | //绘制文本背景 |
| | | cv::rectangle(image, backgroundRect, bgColor, FILLED); |
| | | } |
| | | //绘制文本背景 |
| | | //rectangle(image, backgroundRect, bgColor, FILLED); |
| | | |
| | | //CvxText chinese(ttfFont); |
| | | //设置字体的大小 / 空白比例 / 间隔比较 / 旋转角度 |
| | | //Scalar size(30, 0.5, 0, 0); |
| | | Scalar size(25, 0, 0.1, 0); |
| | | float p = 1.0f; //设置字体的透明度 |
| | | //设置字体 |
| | | chinese.setFont(nullptr, &size, nullptr, &p); |
| | | |
| | | switch (txalign) |
| | | { |
| | | case 1://文字左对齐 |
| | | //绘制文本 |
| | | //chinese.putText(image, text.c_str(), cv::Point(orgxy.x + 5, (orgxy.y - (orgwh.y / 2) - 2)), textColor); |
| | | chinese.putText(image, text.c_str(), cv::Point(orgxy.x + 5, orgxy.y - 8), textColor); |
| | | break; |
| | | case 2://文字居中 |
| | | //绘制文本 |
| | | chinese.putText(image, text.c_str(), cv::Point(orgxy.x + 5 + (orgwh.x - textSize.width) / 2, (orgxy.y - 2)), textColor); |
| | | |
| | | break; |
| | | case 3://文字右对齐 |
| | | //绘制文本 |
| | | chinese.putText(image, text.c_str(), cv::Point(orgxy.x + 5 + (orgwh.x - textSize.width), (orgxy.y - 2)), textColor); |
| | | |
| | | break; |
| | | default://默认不支持中文 |
| | | //绘制文本 |
| | | putText(image, _text.c_str(), cv::Point(orgxy.x + (orgwh.x - textSize.width) / 2, (orgxy.y - (orgwh.y / 2) - 2)), fontFace, 1, textColor, 2); |
| | | break; |
| | | } |
| | | } |
| | | catch (const std::exception& ex) |
| | | { |
| | | std::string errorMessage = "drawTextWithBackground-"; |
| | | errorMessage += ex.what(); |
| | | cout << errorMessage << endl; |
| | | throw std::runtime_error(errorMessage); |
| | | } |
| | | |
| | | } |
| | | //皮带运行状态检测 modelId = 1 |
| | | double PreProcessModel::fnBeltMoveRec(Mat& imMat, std::vector<cv::Mat>& imagesBelt, int& beltCount, RUN& rBelt, std::vector<cv::Point> vertices) |
| | | { |
| | |
| | | //定义接受帧 |
| | | cv::Mat frame = imMat; |
| | | // 在视频帧上添加矩形框 |
| | | rectangle(frame, cv::Point(vertices[0].x, vertices[0].y), cv::Point(vertices[1].x, vertices[1].y), cv::Scalar(255, 255, 0), 2); |
| | | rectangle(frame, cv::Point(vertices[0].x, vertices[0].y), cv::Point(vertices[1].x, vertices[1].y), cv::Scalar(255, 255, 0), 1); |
| | | |
| | | if (imagesBelt.size() >= 3)//长度大于3自动去掉头部帧 |
| | | { |
| | |
| | | //std::vector<cv::Point> vertices = stringToPoints(area); |
| | | |
| | | // 绘制多边形 |
| | | cv::polylines(frame, vertices, true, cv::Scalar(0, 0, 255), 2); |
| | | cv::polylines(frame, vertices, true, cv::Scalar(0, 0, 255), 1); |
| | | |
| | | // 定义要测试的点 |
| | | cv::Point testPoint; |
| | |
| | | } |
| | | |
| | | //标注人形 |
| | | drawTextWithBackground(frame, titleperson, 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), sl); |
| | | drawTextWithBackgroundWstr(frame, titleperson, 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), sl); |
| | | //在视频帧上添加矩形框 |
| | | rectangle(frame, cv::Point(boxes[i].x, boxes[i].y), cv::Point((boxes[i].x + boxes[i].width), (boxes[i].y + boxes[i].height)), sl, 1); |
| | | |
| | | break; |
| | | //case 1: |
| | | // //标注帽子 |
| | | // drawTextWithBackground(frame, "安全帽", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), cv::Scalar(0, 255, 0)); |
| | | // drawTextWithBackgroundWstr(frame, "安全帽", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), cv::Scalar(0, 255, 0)); |
| | | // //在视频帧上添加矩形框 |
| | | // rectangle(frame, cv::Point(boxes[i].x, boxes[i].y), cv::Point((boxes[i].x + boxes[i].width), (boxes[i].y + boxes[i].height)), cv::Scalar(0, 255, 0), 1); |
| | | |
| | |
| | | //wearHat++;//未佩戴安全帽的人的数量 |
| | | |
| | | //标注头部 |
| | | drawTextWithBackground(frame, "头", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), cv::Scalar(0, 255, 0)); |
| | | drawTextWithBackgroundWstr(frame, "头", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), cv::Scalar(0, 255, 0)); |
| | | rectangle(frame, cv::Point(boxes[i].x, boxes[i].y), cv::Point((boxes[i].x + boxes[i].width), (boxes[i].y + boxes[i].height)), cv::Scalar(0, 255, 0), 1); |
| | | |
| | | break; |
| | |
| | | |
| | | if (workpersons <= 0 && workvertices.size() > 0) |
| | | { |
| | | drawTextWithBackground(frame,"离 岗", 2, cv::Point(workvertices[0].x, workvertices[0].y), cv::Point(workvertices[1].x - workvertices[0].x, workvertices[1].y - workvertices[0].y), Scalar(255, 255, 0)); |
| | | drawTextWithBackgroundWstr(frame,"离 岗", 2, cv::Point(workvertices[0].x, workvertices[0].y), cv::Point(workvertices[1].x - workvertices[0].x, workvertices[1].y - workvertices[0].y), Scalar(255, 255, 0)); |
| | | |
| | | // 绘制多边形,工作区域 |
| | | cv::polylines(frame, workvertices, true, cv::Scalar(255, 255, 0), 2); |
| | | } |
| | | |
| | | frame.release(); |
| | | |
| | | result.push_back(distance);//有人进入危险区域 |
| | | result.push_back(wearHat);//未带安全帽人员数量 |
| | | result.push_back(workpersons);//工作区域人员数量 |
| | | |
| | | return result; |
| | | } |
| | | catch (const std::exception& ex) |
| | | { |
| | | std::string errorMessage = "fnImRecProByModelHAT-"; |
| | | errorMessage += ex.what(); |
| | | cout << errorMessage << endl; |
| | | throw std::runtime_error(errorMessage); |
| | | } |
| | | } |
| | | vector<double> PreProcessModel::fnImRecProByModelHAT1(Mat& imMat, HAT& hat, std::vector<cv::Point> vertices, std::vector<cv::Point> workvertices,std::vector<std::vector<int>> c_list,std::string lable_title,std::string color_result) |
| | | { |
| | | try |
| | | { |
| | | vector<double> result; |
| | | string titleperson = "人 员"; |
| | | |
| | | double distance = -1;//0:危险区域边界线上 >1:危险区域内 <1:危险区域外 |
| | | double workdistance = -1;//0:工作区域边界线上 >1:工作区域内 <1:工作区域外 |
| | | double workpersons = 0;//工作区域人的数量 |
| | | double wearHat = 0;//0:全部佩戴安全帽 1:未佩戴安全帽的人的数量 |
| | | |
| | | //定义接受帧 |
| | | cv::Mat frame = imMat; |
| | | |
| | | //获取视频帧的宽度和高度和帧率 |
| | | int frame_width = frame.cols; |
| | | int frame_height = frame.rows; |
| | | double frameRate = 25; |
| | | |
| | | // 创建一个空的边界框向量 |
| | | std::vector<Box> boxes; |
| | | // 调用 detect 函数获取检测到的边界框 |
| | | hat.detect(frame, boxes); |
| | | |
| | | //多边形区域 |
| | | //std::vector<cv::Point> vertices = stringToPoints(area); |
| | | // 绘制多边形 |
| | | cv::polylines(frame, vertices, true, cv::Scalar(0, 0, 255), 1); |
| | | drawTextWithBackgroundWstr(frame, lable_title, 1, cv::Point(vertices[0].x, vertices[0].y), cv::Point(150, 40), Scalar(c_list[0][0], c_list[0][1], c_list[0][2])); |
| | | |
| | | // 定义要测试的点 |
| | | cv::Point testPoint; |
| | | cv::Scalar sl;//标框颜色 |
| | | |
| | | // 使用索引遍历boxes |
| | | for (int i = 0; i < boxes.size(); i++) { |
| | | |
| | | switch (boxes[i].class_id) |
| | | { |
| | | case 0: |
| | | //如果标注了危险区域 |
| | | if (vertices.size()>0) |
| | | { |
| | | distance = cv::pointPolygonTest(vertices, testPoint, false);//危险区域判断 |
| | | if (distance > 0)//危险区域内有个人,画红色 |
| | | { |
| | | if(color_result == "false") |
| | | { |
| | | sl = Scalar(255, 0, 0); |
| | | } |
| | | else |
| | | { |
| | | sl = Scalar(0, 0, 255); |
| | | } |
| | | titleperson = "闯 入"; |
| | | } |
| | | else |
| | | { |
| | | if(color_result == "false") |
| | | { |
| | | sl = Scalar(255, 0, 0); |
| | | } |
| | | else |
| | | { |
| | | sl = Scalar(0, 0, 255); |
| | | } |
| | | titleperson = "人 员"; |
| | | } |
| | | } |
| | | |
| | | //如果标注了工作区域 |
| | | if (workvertices.size()>0) |
| | | { |
| | | workdistance = cv::pointPolygonTest(workvertices, testPoint, false);//脱岗离岗判断 |
| | | |
| | | |
| | | if (workdistance >= 0)//工作区域内有个人 |
| | | { |
| | | workpersons++; |
| | | } |
| | | } |
| | | |
| | | //标注人形 |
| | | drawTextWithBackgroundWstr(frame, titleperson, 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), sl); |
| | | //在视频帧上添加矩形框 |
| | | rectangle(frame, cv::Point(boxes[i].x, boxes[i].y), cv::Point((boxes[i].x + boxes[i].width), (boxes[i].y + boxes[i].height)), sl, 1); |
| | | |
| | | break; |
| | | //case 1: |
| | | // //标注帽子 |
| | | // drawTextWithBackgroundWstr(frame, "安全帽", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), cv::Scalar(0, 255, 0)); |
| | | // //在视频帧上添加矩形框 |
| | | // rectangle(frame, cv::Point(boxes[i].x, boxes[i].y), cv::Point((boxes[i].x + boxes[i].width), (boxes[i].y + boxes[i].height)), cv::Scalar(0, 255, 0), 1); |
| | | |
| | | // break; |
| | | case 2: |
| | | |
| | | //如果标注了工作区域 |
| | | if (workvertices.size() > 0) |
| | | { |
| | | workdistance = cv::pointPolygonTest(workvertices, testPoint, false);//脱岗离岗判断 |
| | | |
| | | if (workdistance >= 0)//工作区域内有个人 |
| | | { |
| | | workpersons++; |
| | | } |
| | | } |
| | | |
| | | //wearHat++;//未佩戴安全帽的人的数量 |
| | | |
| | | //标注头部 |
| | | drawTextWithBackgroundWstr(frame, "头", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), cv::Scalar(0, 255, 0)); |
| | | rectangle(frame, cv::Point(boxes[i].x, boxes[i].y), cv::Point((boxes[i].x + boxes[i].width), (boxes[i].y + boxes[i].height)), cv::Scalar(0, 255, 0), 1); |
| | | |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (workpersons <= 0 && workvertices.size() > 0) |
| | | { |
| | | drawTextWithBackgroundWstr(frame,"离 岗", 2, cv::Point(workvertices[0].x, workvertices[0].y), cv::Point(workvertices[1].x - workvertices[0].x, workvertices[1].y - workvertices[0].y), Scalar(255, 255, 0)); |
| | | |
| | | // 绘制多边形,工作区域 |
| | | cv::polylines(frame, workvertices, true, cv::Scalar(255, 255, 0), 2); |
| | |
| | | frameout.copyTo(roi); |
| | | |
| | | // 煤炭占比 |
| | | drawTextWithBackground(frame, std::to_string(result), 0, cv::Point(vertices[0].x, vertices[0].y), cv::Point(vertices[1].x - vertices[0].x, vertices[1].y - vertices[0].y), Scalar(255, 255, 0)); |
| | | drawTextWithBackgroundWstr(frame, std::to_string(result), 0, cv::Point(vertices[0].x, vertices[0].y), cv::Point(vertices[1].x - vertices[0].x, vertices[1].y - vertices[0].y), Scalar(255, 255, 0)); |
| | | |
| | | // 在视频帧上添加矩形框 |
| | | //rectangle(frame, cv::Point(vertices[0].x, vertices[0].y), cv::Point(vertices[2].x, vertices[3].y), cv::Scalar(255, 255, 0), 2); |
| | |
| | | if (cv::pointPolygonTest(vertices, testPoint, false) > 0)//区域内有个人,画红色 |
| | | { |
| | | //标注大媒块 |
| | | drawTextWithBackground(frame, "大 煤 块", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), sPurple); |
| | | drawTextWithBackgroundWstr(frame, "大 煤 块", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), sPurple); |
| | | //在视频帧上添加矩形框 |
| | | rectangle(frame, cv::Point(boxes[i].x, boxes[i].y), cv::Point((boxes[i].x + boxes[i].width), (boxes[i].y + boxes[i].height)), sPurple, 1); |
| | | } |
| | |
| | | if (cv::pointPolygonTest(vertices, testPoint, false) > 0)//区域内有个人,画红色 |
| | | { |
| | | //标注异物 |
| | | drawTextWithBackground(frame, "异物", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), sRed); |
| | | drawTextWithBackgroundWstr(frame, "异物", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), sRed); |
| | | //在视频帧上添加矩形框 |
| | | rectangle(frame, cv::Point(boxes[i].x, boxes[i].y), cv::Point((boxes[i].x + boxes[i].width), (boxes[i].y + boxes[i].height)), sRed, 1); |
| | | } |
| | |
| | | if (cv::pointPolygonTest(vertices, testPoint, false) > 0)//进入区域后再画框 |
| | | { |
| | | //标注大煤块 |
| | | drawTextWithBackground(frame, "大煤块", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), sPurple); |
| | | drawTextWithBackgroundWstr(frame, "大煤块", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), sPurple); |
| | | //在视频帧上添加矩形框 |
| | | rectangle(frame, cv::Point(boxes[i].x, boxes[i].y), cv::Point((boxes[i].x + boxes[i].width), (boxes[i].y + boxes[i].height)), sPurple, 1); |
| | | } |
| | |
| | | case 1: |
| | | cv::rectangle(frame, cv::Point(boxes[i].x - boxes[i].width / 2, boxes[i].y - boxes[i].height / 2), cv::Point(boxes[i].x + boxes[i].width / 2, boxes[i].y + boxes[i].height / 2), roller_color2, 3); |
| | | //标注托辊 |
| | | drawTextWithBackground(frame, "托辊", 2, cv::Point(boxes[i].x - boxes[i].width / 2, boxes[i].y - boxes[i].height / 2), cv::Point(boxes[i].width, boxes[i].height), sPurple); |
| | | drawTextWithBackgroundWstr(frame, "托辊", 2, cv::Point(boxes[i].x - boxes[i].width / 2, boxes[i].y - boxes[i].height / 2), cv::Point(boxes[i].width, boxes[i].height), sPurple); |
| | | break; |
| | | case 2: |
| | | case 3: |
| | |
| | | if (cv::pointPolygonTest(vertices, testPoint, false) > 0)//区域内,画红色 |
| | | { |
| | | //标注异物 |
| | | drawTextWithBackground(frame, "异物", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), sRed); |
| | | drawTextWithBackgroundWstr(frame, "异物", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), sRed); |
| | | //在视频帧上添加矩形框 |
| | | rectangle(frame, cv::Point(boxes[i].x, boxes[i].y), cv::Point((boxes[i].x + boxes[i].width), (boxes[i].y + boxes[i].height)), sRed, 1); |
| | | } |
| | |
| | | sl = Scalar(0, 0, 255); |
| | | |
| | | //标注人形 |
| | | drawTextWithBackground(frame, "携 带 大 件", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), sl); |
| | | drawTextWithBackgroundWstr(frame, "携 带 大 件", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), sl); |
| | | |
| | | //在视频帧上添加矩形框 |
| | | rectangle(frame, cv::Point(boxes[i].x, boxes[i].y), cv::Point((boxes[i].x + boxes[i].width), (boxes[i].y + boxes[i].height)), sl, 1); |
| | |
| | | break; |
| | | //case 1: |
| | | // //标注帽子 |
| | | // drawTextWithBackground(frame, "安全帽", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), cv::Scalar(0, 255, 0)); |
| | | // drawTextWithBackgroundWstr(frame, "安全帽", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), cv::Scalar(0, 255, 0)); |
| | | // //在视频帧上添加矩形框 |
| | | // rectangle(frame, cv::Point(boxes[i].x, boxes[i].y), cv::Point((boxes[i].x + boxes[i].width), (boxes[i].y + boxes[i].height)), cv::Scalar(0, 255, 0), 1); |
| | | |
| | |
| | | |
| | | // wearHat++;//未佩戴安全帽的人的数量 |
| | | // //标注头部 |
| | | // drawTextWithBackground(frame, "头", 3, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), cv::Scalar(0, 255, 0)); |
| | | // drawTextWithBackgroundWstr(frame, "头", 3, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), cv::Scalar(0, 255, 0)); |
| | | // rectangle(frame, cv::Point(boxes[i].x, boxes[i].y), cv::Point((boxes[i].x + boxes[i].width), (boxes[i].y + boxes[i].height)), cv::Scalar(0, 255, 0), 1); |
| | | |
| | | // break; |
| | |
| | | sl = Scalar(0, 0, 255); |
| | | |
| | | //标注人形 |
| | | drawTextWithBackground(frame, "睡 岗", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), sl); |
| | | drawTextWithBackgroundWstr(frame, "睡 岗", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), sl); |
| | | |
| | | //在视频帧上添加矩形框 |
| | | rectangle(frame, cv::Point(boxes[i].x, boxes[i].y), cv::Point((boxes[i].x + boxes[i].width), (boxes[i].y + boxes[i].height)), sl, 1); |
| | |
| | | checkpersons = 1; |
| | | |
| | | //标注人形 |
| | | drawTextWithBackground(frame, title, 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), sl); |
| | | drawTextWithBackgroundWstr(frame, title, 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), sl); |
| | | //在视频帧上添加矩形框 |
| | | rectangle(frame, cv::Point(boxes[i].x, boxes[i].y), cv::Point((boxes[i].x + boxes[i].width), (boxes[i].y + boxes[i].height)), sl, 1); |
| | | |
| | |
| | | reshat = 1; |
| | | |
| | | //标注帽子 |
| | | drawTextWithBackground(frame, title, 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), cv::Scalar(0, 255, 0)); |
| | | drawTextWithBackgroundWstr(frame, title, 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), cv::Scalar(0, 255, 0)); |
| | | //在视频帧上添加矩形框 |
| | | rectangle(frame, cv::Point(boxes[i].x, boxes[i].y), cv::Point((boxes[i].x + boxes[i].width), (boxes[i].y + boxes[i].height)), cv::Scalar(0, 255, 0), 1); |
| | | } |
| | |
| | | //case 2://头部 |
| | | |
| | | // //标注头部 |
| | | // drawTextWithBackground(frame, "头", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), cv::Scalar(0, 255, 0)); |
| | | // drawTextWithBackgroundWstr(frame, "头", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), cv::Scalar(0, 255, 0)); |
| | | // rectangle(frame, cv::Point(boxes[i].x, boxes[i].y), cv::Point((boxes[i].x + boxes[i].width), (boxes[i].y + boxes[i].height)), cv::Scalar(0, 255, 0), 1); |
| | | |
| | | // break; |
| | |
| | | respager = 1; |
| | | |
| | | //标注自救器 |
| | | drawTextWithBackground(frame, title, 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), cv::Scalar(0, 255, 0)); |
| | | drawTextWithBackgroundWstr(frame, title, 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), cv::Scalar(0, 255, 0)); |
| | | rectangle(frame, cv::Point(boxes[i].x, boxes[i].y), cv::Point((boxes[i].x + boxes[i].width), (boxes[i].y + boxes[i].height)), cv::Scalar(0, 255, 0), 1); |
| | | } |
| | | |
| | |
| | | resshoes = 1; |
| | | |
| | | //标注鞋 |
| | | drawTextWithBackground(frame, title, 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), cv::Scalar(0, 255, 0)); |
| | | drawTextWithBackgroundWstr(frame, title, 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), cv::Scalar(0, 255, 0)); |
| | | rectangle(frame, cv::Point(boxes[i].x, boxes[i].y), cv::Point((boxes[i].x + boxes[i].width), (boxes[i].y + boxes[i].height)), cv::Scalar(0, 255, 0), 1); |
| | | } |
| | | |
| | |
| | | case 0: |
| | | fire++; |
| | | //标注火 |
| | | drawTextWithBackground(frame, "火", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), sl); |
| | | drawTextWithBackgroundWstr(frame, "火", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), sl); |
| | | |
| | | //在视频帧上添加矩形框 |
| | | rectangle(frame, cv::Point(boxes[i].x, boxes[i].y), cv::Point((boxes[i].x + boxes[i].width), (boxes[i].y + boxes[i].height)), sl, 1); |
| | |
| | | case 1: |
| | | smoke++; |
| | | //标注烟 |
| | | drawTextWithBackground(frame, "烟", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), sl); |
| | | drawTextWithBackgroundWstr(frame, "烟", 2, cv::Point(boxes[i].x, boxes[i].y), cv::Point(boxes[i].width, boxes[i].height), sl); |
| | | |
| | | //在视频帧上添加矩形框 |
| | | rectangle(frame, cv::Point(boxes[i].x, boxes[i].y), cv::Point((boxes[i].x + boxes[i].width), (boxes[i].y + boxes[i].height)), sl, 1); |