You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
167 lines
4.8 KiB
167 lines
4.8 KiB
/*
|
|
* @Author: your name
|
|
* @Date: 2022-04-20 15:50:00
|
|
* @LastEditTime: 2022-09-26 16:27:27
|
|
* @LastEditors: sueRimn
|
|
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
* @FilePath: /ZCXD_MonitorPlatform/src/CoreLogicModule/src/CamDeal.cpp
|
|
*/
|
|
#include "ImgBasicDeal.h"
|
|
ImgBasicDeal::ImgBasicDeal()
|
|
{
|
|
|
|
// DrawBlobErrorCorleList[ERROR_TYPE_OK] = cv::Scalar(128, 128, 128);
|
|
// DrawBlobErrorCorleList[ERROR_TYPE_yc] = cv::Scalar(255, 0, 0);
|
|
}
|
|
|
|
ImgBasicDeal::~ImgBasicDeal()
|
|
{
|
|
}
|
|
|
|
int ImgBasicDeal::DrawResult(cv::Mat &image_draw, CheckResult result)
|
|
{
|
|
|
|
// if (resultimg.channels() == 1)
|
|
// {
|
|
// cv::cvtColor(resultimg, image_draw, cv::COLOR_GRAY2RGB); // 彩色 可选项
|
|
// }
|
|
// else
|
|
// {
|
|
// image_draw = resultimg.clone();
|
|
// }
|
|
// printf("result.blobResult.blobNum %d\n", result.blobResult.blobNum);
|
|
// for (int i = 0; i < result.blobResult.blobNum; i++)
|
|
// {
|
|
// // if (blobs.Pass[i])
|
|
// {
|
|
// auto enType = result.blobResult.bloblist[i].UserErrorType;
|
|
// if (result.blobResult.bloblist[i].UserErrorType == 0)
|
|
// {
|
|
// continue;
|
|
// }
|
|
|
|
// cv::Rect roi = result.blobResult.bloblist[i].blob_ResizeImg;
|
|
|
|
// cv::Point pc;
|
|
// pc.x = roi.x + roi.width * 0.5;
|
|
// pc.y = roi.y + roi.height * 0.5;
|
|
// int rw = roi.width * 0.5;
|
|
// int rh = roi.height * 0.5;
|
|
// int r = std::sqrt(rw * rw + rh * rh) * 1.1 + 8;
|
|
|
|
// cv::circle(image_draw, pc, r, DrawBlobErrorCorleList[result.blobResult.bloblist[i].UserErrorType]);
|
|
|
|
// // 设置绘制文本的相关参数
|
|
// std::string text = std::to_string(result.blobResult.bloblist[i].UserErrorType) + " A: " + std::to_string(result.blobResult.bloblist[i].JudgArea) + " E: " + std::to_string(result.blobResult.bloblist[i].energy);
|
|
|
|
// int baseline;
|
|
// // 获取文本框的长宽
|
|
// cv::Size text_size = cv::getTextSize(text, font_face, font_scale, thickness, &baseline);
|
|
// // 将文本框居中绘制
|
|
// cv::Point origin = CalcTextPosition(pc, r, text_size, image_draw.size(), (ERROR_TYPE_)enType);
|
|
// cv::putText(image_draw, text, origin, font_face, font_scale, cv::Scalar(255, 0, 0), thickness, 1, 0);
|
|
// }
|
|
// }
|
|
|
|
return 0;
|
|
}
|
|
cv::Point ImgBasicDeal::CalcTextPosition(cv::Point pt, int radius, cv::Size text_size, cv::Size image_size, ERROR_TYPE_ type)
|
|
{
|
|
cv::Point dst;
|
|
int y_offset = 0;
|
|
// switch (type)
|
|
// {
|
|
// case ERROR_TYPE_OK:
|
|
// y_offset = 20;
|
|
// break;
|
|
// case ERROR_TYPE_yc:
|
|
// y_offset = 40;
|
|
// break;
|
|
// default:
|
|
// break;
|
|
// }
|
|
dst.y = (pt.y - y_offset > text_size.height) ? pt.y - y_offset : pt.y + y_offset;
|
|
if (dst.y >= image_size.height)
|
|
{
|
|
dst.y = image_size.height - 1;
|
|
}
|
|
dst.x = (pt.x + radius + text_size.width > image_size.width) ? pt.x - text_size.width - radius : pt.x + radius;
|
|
if (dst.x < 0)
|
|
{
|
|
dst.x = 0;
|
|
}
|
|
return dst;
|
|
}
|
|
|
|
int ImgBasicDeal::DrawResult_small(cv::Mat &image_draw, int i, int j, CheckResult result)
|
|
{
|
|
|
|
// cv::cvtColor(result.SamllImgList[i][j].img, image_draw, cv::COLOR_GRAY2RGB); // 彩色 可选项
|
|
// for (int k = 0; k < result.SamllImgList[i][j].qxIndexArr.size(); k++)
|
|
// {
|
|
// int idx = result.SamllImgList[i][j].qxIndexArr.at(k);
|
|
// {
|
|
|
|
// float energy;
|
|
// float hj;
|
|
// cv::Rect roi = result.qxiImageResult.at(idx).SmallImgroi;
|
|
|
|
// cv::Point pc;
|
|
// pc.x = roi.x + roi.width * 0.5;
|
|
// pc.y = roi.y + roi.height * 0.5;
|
|
// int rw = roi.width * 0.5;
|
|
// int rh = roi.height * 0.5;
|
|
// int r = std::sqrt(rw * rw + rh * rh) * 1.5 + 12;
|
|
|
|
// cv::Scalar dcolor = cv::Scalar(0, 0, 255);
|
|
|
|
// if (result.qxiImageResult.at(idx).type == 0)
|
|
// {
|
|
// dcolor = cv::Scalar(0, 255, 0);
|
|
// }
|
|
|
|
// cv::circle(image_draw, pc, r, dcolor);
|
|
|
|
// // 设置绘制文本的相关参数
|
|
// char text[1024] = {0};
|
|
// sprintf(text, "A:%.2f E:%.0f", result.qxiImageResult.at(idx).area, result.qxiImageResult.at(idx).energy);
|
|
|
|
// int baseline;
|
|
// int font_face = cv::FONT_HERSHEY_SIMPLEX;
|
|
// double font_scale = 0.5;
|
|
// int thickness = 1;
|
|
// // 获取文本框的长宽
|
|
// cv::Size text_size = cv::getTextSize(text, font_face, font_scale, thickness, &baseline);
|
|
|
|
// // 将文本框居中绘制
|
|
// cv::Point origin = cv::Point(roi.x, roi.y - 10);
|
|
// if (origin.x + text_size.width > image_draw.cols)
|
|
|
|
// {
|
|
// origin.x = image_draw.cols - text_size.width;
|
|
// }
|
|
|
|
// if (origin.y < 10)
|
|
|
|
// {
|
|
// origin.y = 10;
|
|
// }
|
|
|
|
// cv::putText(image_draw, text, origin, font_face, font_scale, cv::Scalar(255, 0, 0), thickness, 1, 0);
|
|
// }
|
|
// }
|
|
return 0;
|
|
}
|
|
|
|
int ImgBasicDeal::DrawPointList(cv::Mat &image_draw, std::vector<cv::Point> plist)
|
|
{
|
|
|
|
return 0;
|
|
}
|
|
|
|
int ImgBasicDeal::preDealImg(cv::Mat &srcimg, cv::Mat &image_resize, bool bfilpSrcImg)
|
|
{
|
|
|
|
return 0;
|
|
}
|