|
|
|
@ -1,6 +1,7 @@
|
|
|
|
#include "Side_Detect.hpp"
|
|
|
|
#include "Side_Detect.hpp"
|
|
|
|
#include "CheckErrorCode.hpp"
|
|
|
|
#include "CheckErrorCode.hpp"
|
|
|
|
#include "CheckUtil.hpp"
|
|
|
|
#include "CheckUtil.hpp"
|
|
|
|
|
|
|
|
#include "DetCommonDefine.hpp"
|
|
|
|
using namespace cv;
|
|
|
|
using namespace cv;
|
|
|
|
using namespace std;
|
|
|
|
using namespace std;
|
|
|
|
// 检测模型 单个小图 输入模型图片尺寸
|
|
|
|
// 检测模型 单个小图 输入模型图片尺寸
|
|
|
|
@ -87,6 +88,8 @@ int Side_Detect::CheckRun()
|
|
|
|
t1 = CheckUtil::getcurTime();
|
|
|
|
t1 = CheckUtil::getcurTime();
|
|
|
|
CheckImgInit();
|
|
|
|
CheckImgInit();
|
|
|
|
cv::Mat detimg = DetImgInfo_shareP->img;
|
|
|
|
cv::Mat detimg = DetImgInfo_shareP->img;
|
|
|
|
|
|
|
|
//准备结果图
|
|
|
|
|
|
|
|
cv::resize(detimg.clone(), m_CheckResult_shareP->resultImg, cv::Size(800, 600));
|
|
|
|
if (detimg.empty())
|
|
|
|
if (detimg.empty())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
@ -124,7 +127,7 @@ int Side_Detect::CheckRun()
|
|
|
|
t2 = CheckUtil::getcurTime();
|
|
|
|
t2 = CheckUtil::getcurTime();
|
|
|
|
m_CheckResult_shareP->UseTimeMS = t2 - t1;
|
|
|
|
m_CheckResult_shareP->UseTimeMS = t2 - t1;
|
|
|
|
|
|
|
|
|
|
|
|
re = Draw(AlignImg, m_CheckResult_shareP->resultImg);
|
|
|
|
re = Draw(detimg, m_CheckResult_shareP->resultImg);
|
|
|
|
if (0 != re)
|
|
|
|
if (0 != re)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return re;
|
|
|
|
return re;
|
|
|
|
@ -300,13 +303,30 @@ int Side_Detect::Draw(const cv::Mat &img, cv::Mat &resultimg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
resultimg = img.clone();
|
|
|
|
resultimg = img.clone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//裁剪到包括产品(1600x1200)
|
|
|
|
|
|
|
|
int w = 1600;
|
|
|
|
|
|
|
|
int h = 1200;
|
|
|
|
|
|
|
|
cv::Point center{this->m_AlignMaxRoi.x + this->m_AlignMaxRoi.width / 2, this->m_AlignMaxRoi.y + this->m_AlignMaxRoi.height / 2};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int x = center.x - w / 2;
|
|
|
|
|
|
|
|
int y = center.y - h / 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 确保裁剪区域不超出图像边界
|
|
|
|
|
|
|
|
x = std::max(0, x);
|
|
|
|
|
|
|
|
y = std::max(0, y);
|
|
|
|
|
|
|
|
x = std::min(x, img.cols - w);
|
|
|
|
|
|
|
|
y = std::min(y, img.rows - h);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建裁剪区域
|
|
|
|
|
|
|
|
cv::Rect cropRoi(x, y, w, h);
|
|
|
|
|
|
|
|
resultimg = resultimg(cropRoi).clone();
|
|
|
|
|
|
|
|
|
|
|
|
// cv::polylines(resultimg, m_CheckBaseConfig->pointArry, true, cv::Scalar(0, 255, 0), 2);
|
|
|
|
// cv::polylines(resultimg, m_CheckBaseConfig->pointArry, true, cv::Scalar(0, 255, 0), 2);
|
|
|
|
auto regions = m_CheckBaseConfig->nodeConfigArr[0].regionConfigArr;
|
|
|
|
// auto regions = m_CheckBaseConfig->nodeConfigArr[0].regionConfigArr;
|
|
|
|
for (int i = 0; i < regions.size(); i++)
|
|
|
|
// for (int i = 0; i < regions.size(); i++)
|
|
|
|
{
|
|
|
|
// {
|
|
|
|
cv::polylines(resultimg, regions[i].basicInfo.pointArry, true, cv::Scalar(0, 255, 0), 2);
|
|
|
|
// cv::polylines(resultimg, regions[i].basicInfo.pointArry, true, cv::Scalar(0, 255, 0), 2);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
int fontFace = cv::FONT_HERSHEY_SIMPLEX; // 字体样式
|
|
|
|
int fontFace = cv::FONT_HERSHEY_SIMPLEX; // 字体样式
|
|
|
|
double fontScale = 1; // 字体大小
|
|
|
|
double fontScale = 1; // 字体大小
|
|
|
|
@ -332,8 +352,8 @@ int Side_Detect::Draw(const cv::Mat &img, cv::Mat &resultimg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cv::Rect roi = m_resultList.at(i).roi;
|
|
|
|
cv::Rect roi = m_resultList.at(i).roi;
|
|
|
|
cv::Point pc;
|
|
|
|
cv::Point pc;
|
|
|
|
pc.x = roi.x + roi.width * 0.5;
|
|
|
|
pc.x = roi.x + roi.width * 0.5 + (m_AlignMaxRoi.x - cropRoi.x);//转换为cropRoi中坐标
|
|
|
|
pc.y = roi.y + roi.height * 0.5;
|
|
|
|
pc.y = roi.y + roi.height * 0.5 + (m_AlignMaxRoi.y - cropRoi.y);
|
|
|
|
int rw = roi.width * 0.5;
|
|
|
|
int rw = roi.width * 0.5;
|
|
|
|
int rh = roi.height * 0.5;
|
|
|
|
int rh = roi.height * 0.5;
|
|
|
|
int r = std::sqrt(rw * rw + rh * rh) * 1.1 + 8;
|
|
|
|
int r = std::sqrt(rw * rw + rh * rh) * 1.1 + 8;
|
|
|
|
@ -349,13 +369,13 @@ int Side_Detect::Draw(const cv::Mat &img, cv::Mat &resultimg)
|
|
|
|
string show_info = buffer;
|
|
|
|
string show_info = buffer;
|
|
|
|
|
|
|
|
|
|
|
|
cv::Point p;
|
|
|
|
cv::Point p;
|
|
|
|
p.x = m_resultList.at(i).roi.x;
|
|
|
|
p.x = m_resultList.at(i).roi.x + (m_AlignMaxRoi.x - cropRoi.x);//转换为cropRoi中坐标
|
|
|
|
p.y = m_resultList.at(i).roi.y;
|
|
|
|
p.y = m_resultList.at(i).roi.y + (m_AlignMaxRoi.y - cropRoi.y);
|
|
|
|
cv::putText(resultimg, show_info, p, fontFace, 1, color, 1);
|
|
|
|
cv::putText(resultimg, show_info, p, fontFace, 1, color, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//裁剪
|
|
|
|
// 裁剪
|
|
|
|
cv::Size sz{RESULT_WIDTH, resultimg.rows};
|
|
|
|
cv::Size dstSize(RESULT_WIDTH, RESULT_HEIGHT);
|
|
|
|
cv::resize(resultimg, resultimg, sz);
|
|
|
|
cv::resize(resultimg, resultimg, dstSize);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -465,9 +485,22 @@ int Side_Detect::ImgAlinRotate(const cv::Mat &img, cv::Mat &alignImg)
|
|
|
|
|
|
|
|
|
|
|
|
if (alignImg.empty())
|
|
|
|
if (alignImg.empty())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
printf("Align is Error exit \n");
|
|
|
|
printf("Align is empty, Error exit \n");
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//判断尺寸
|
|
|
|
|
|
|
|
int w = m_CheckBaseConfig->baseCheckFunction.detconfig.chip_width_mm / m_CheckBaseConfig->imageScaleParam.fScale_X;
|
|
|
|
|
|
|
|
int h = m_CheckBaseConfig->baseCheckFunction.detconfig.chip_height_mm / m_CheckBaseConfig->imageScaleParam.fScale_Y;
|
|
|
|
|
|
|
|
auto w_offset = std::abs(w - m_AlignMaxRoi.width);
|
|
|
|
|
|
|
|
auto h_offset = std::abs(h - m_AlignMaxRoi.height);
|
|
|
|
|
|
|
|
int param_w_offset = m_CheckBaseConfig->baseCheckFunction.detconfig.chip_width_offset_mm / m_CheckBaseConfig->imageScaleParam.fScale_X;
|
|
|
|
|
|
|
|
int param_h_offset = m_CheckBaseConfig->baseCheckFunction.detconfig.chip_height_offset_mm / m_CheckBaseConfig->imageScaleParam.fScale_Y;
|
|
|
|
|
|
|
|
if (w_offset > param_w_offset || h_offset > param_h_offset)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("Align error, no product\n");
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DetRotateType ratio = m_CheckBaseConfig->baseCheckFunction.detconfig.rotate;
|
|
|
|
DetRotateType ratio = m_CheckBaseConfig->baseCheckFunction.detconfig.rotate;
|
|
|
|
std::cout << "rotate ratio : " << ratio << std::endl;
|
|
|
|
std::cout << "rotate ratio : " << ratio << std::endl;
|
|
|
|
if (ratio == Ratio_0)
|
|
|
|
if (ratio == Ratio_0)
|
|
|
|
@ -662,7 +695,7 @@ int Side_Detect::DetectImg(const cv::Mat &img)
|
|
|
|
if (tem.area_mm2 > cur_check.area && tem.hj > cur_check.hj && cur_check.bEnable)
|
|
|
|
if (tem.area_mm2 > cur_check.area && tem.hj > cur_check.hj && cur_check.bEnable)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tem.nresult = 1;
|
|
|
|
tem.nresult = 1;
|
|
|
|
printf("region %d NG tem.nresult : %f>%f \n", i, tem.area_mm2, m_CheckBaseConfig->qxSegParam.Area);
|
|
|
|
printf("region %d NG tem.nresult : %f>%f \n", i, tem.area_mm2, cur_check.area);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -670,11 +703,11 @@ int Side_Detect::DetectImg(const cv::Mat &img)
|
|
|
|
if (tem.area_mm2 > cur_ys.area && tem.hj > cur_ys.hj && cur_ys.bEnable)
|
|
|
|
if (tem.area_mm2 > cur_ys.area && tem.hj > cur_ys.hj && cur_ys.bEnable)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tem.nYsresult = 1;
|
|
|
|
tem.nYsresult = 1;
|
|
|
|
printf("region %d YS tem.nresult : %f>%f \n", i, tem.area_mm2, m_CheckBaseConfig->ysSegParam.Area);
|
|
|
|
printf("region %d YS tem.nresult : %f>%f \n", i, tem.area_mm2, cur_ys.area);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
printf("region %d OK tem.nresult : %f < %f \n", i, tem.area_mm2, m_CheckBaseConfig->qxSegParam.Area);
|
|
|
|
printf("region %d OK tem.nresult : %f < %f \n", i, tem.area_mm2, cur_check.area);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|