|
|
|
|
@ -389,7 +389,26 @@ int ImgCheckAnalysisy::Adapt_Config(RotatedRect tplOuterRect, RotatedRect curOut
|
|
|
|
|
// 仿射变换
|
|
|
|
|
cv::warpAffine(det_img, det_img, affine_mat, det_img.size());
|
|
|
|
|
|
|
|
|
|
// imwrite("det_img.png", det_img);
|
|
|
|
|
// 将m_outer_rroi和m_inner_rroi变换到模板图像坐标系下
|
|
|
|
|
auto transformRotatedRect = [&affine_mat](cv::RotatedRect &rrect)
|
|
|
|
|
{
|
|
|
|
|
const double *M = affine_mat.ptr<double>(0);
|
|
|
|
|
|
|
|
|
|
cv::Point2f pts[4];
|
|
|
|
|
rrect.points(pts);
|
|
|
|
|
|
|
|
|
|
std::vector<cv::Point2f> transformed_pts(4);
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
float x = static_cast<float>(M[0] * pts[i].x + M[1] * pts[i].y + M[2]);
|
|
|
|
|
float y = static_cast<float>(M[3] * pts[i].x + M[4] * pts[i].y + M[5]);
|
|
|
|
|
transformed_pts[i] = cv::Point2f(x, y);
|
|
|
|
|
}
|
|
|
|
|
rrect = cv::minAreaRect(transformed_pts);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
transformRotatedRect(m_outer_rroi);
|
|
|
|
|
transformRotatedRect(m_inner_rroi);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
@ -438,10 +457,8 @@ int ImgCheckAnalysisy::CheckRun()
|
|
|
|
|
long time_edge_s = CheckUtil::getcurTime();
|
|
|
|
|
|
|
|
|
|
/*AI 边缘定位(内外边缘)*/
|
|
|
|
|
cv::RotatedRect outer_roi;
|
|
|
|
|
cv::RotatedRect inner_roi;
|
|
|
|
|
// 模型定位内外边缘
|
|
|
|
|
int reedge = AI_Edge(m_CheckResult_shareP->in_shareImage->img, outer_roi, inner_roi);
|
|
|
|
|
int reedge = AI_Edge(m_CheckResult_shareP->in_shareImage->img, m_outer_rroi, m_inner_rroi);
|
|
|
|
|
if (reedge != 0)
|
|
|
|
|
{
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_0, "Error", "AI_Edge is error type = %d", reedge);
|
|
|
|
|
@ -453,20 +470,20 @@ int ImgCheckAnalysisy::CheckRun()
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_0, "2、pre detect", "-------------------------AI_Edge------------succ---time %ld----\n", time_edge_e - time_edge_s);
|
|
|
|
|
|
|
|
|
|
// 计算内外边缘夹角
|
|
|
|
|
float aouter = CheckUtil::getLongAxisAngle(outer_roi);
|
|
|
|
|
float ainner = CheckUtil::getLongAxisAngle(inner_roi);
|
|
|
|
|
float aouter = CheckUtil::getLongAxisAngle(m_outer_rroi);
|
|
|
|
|
float ainner = CheckUtil::getLongAxisAngle(m_inner_rroi);
|
|
|
|
|
|
|
|
|
|
float diff_align = std::fabs(aouter - ainner);
|
|
|
|
|
diff_align = std::fmod(diff_align, 180.0f); // 模 180 度
|
|
|
|
|
|
|
|
|
|
/*投影对齐模板*/
|
|
|
|
|
Adapt_Config(m_tplOuterRect, outer_roi, m_CheckResult_shareP->in_shareImage->img);
|
|
|
|
|
Adapt_Config(m_tplOuterRect, m_outer_rroi, m_CheckResult_shareP->in_shareImage->img);
|
|
|
|
|
m_outer_roi = m_tplOuterRect.boundingRect();
|
|
|
|
|
m_Crop_Roi_paramImg = m_outer_roi;
|
|
|
|
|
m_pImageAllResult->pDetResult->CutRoi = m_outer_roi;
|
|
|
|
|
m_pImageAllResult->pDetResult->Param_CropRoi = m_Crop_Roi_paramImg;
|
|
|
|
|
long time_calan_e = CheckUtil::getcurTime();
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_0, "2.1、pre detect", "-------------------------CalAn------------succ---time %ld----\n", time_calan_e - time_edge_s);
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_0, "2.1、pre detect", "-------------------------CalAndAffine------------succ---time %ld----\n", time_calan_e - time_edge_s);
|
|
|
|
|
|
|
|
|
|
/*生成 检测的图片*/
|
|
|
|
|
cv::Mat image;
|
|
|
|
|
@ -1681,6 +1698,42 @@ int ImgCheckAnalysisy::DrawResult_Step_1()
|
|
|
|
|
float fs_resize_x = m_pImageAllResult->resultImg.cols * 1.0f / m_pImageAllResult->detImg.cols;
|
|
|
|
|
float fs_resize_y = m_pImageAllResult->resultImg.rows * 1.0f / m_pImageAllResult->detImg.rows;
|
|
|
|
|
|
|
|
|
|
// 绘制模板 pin 轮廓(绿色)与当前 pin 轮廓(红色)
|
|
|
|
|
for (const auto &contour : m_tplPinContours)
|
|
|
|
|
{
|
|
|
|
|
std::vector<cv::Point> draw_pts;
|
|
|
|
|
draw_pts.reserve(contour.size());
|
|
|
|
|
for (const auto &pt : contour)
|
|
|
|
|
{
|
|
|
|
|
draw_pts.emplace_back(cvRound(pt.x * fs_resize_x), cvRound(pt.y * fs_resize_y));
|
|
|
|
|
}
|
|
|
|
|
cv::polylines(m_CheckResult_shareP->resultimg, draw_pts, true, cv::Scalar(255, 255, 0), 1);
|
|
|
|
|
}
|
|
|
|
|
for (const auto &contour : m_curPinContours)
|
|
|
|
|
{
|
|
|
|
|
std::vector<cv::Point> draw_pts;
|
|
|
|
|
draw_pts.reserve(contour.size());
|
|
|
|
|
for (const auto &pt : contour)
|
|
|
|
|
{
|
|
|
|
|
draw_pts.emplace_back(cvRound(pt.x * fs_resize_x), cvRound(pt.y * fs_resize_y));
|
|
|
|
|
}
|
|
|
|
|
cv::polylines(m_CheckResult_shareP->resultimg, draw_pts, true, cv::Scalar(255, 0, 255), 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 绘制m_inner_rroi(蓝色)
|
|
|
|
|
{
|
|
|
|
|
cv::Point2f vertices[4];
|
|
|
|
|
m_inner_rroi.points(vertices);
|
|
|
|
|
std::vector<cv::Point> draw_pts;
|
|
|
|
|
draw_pts.reserve(4);
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
draw_pts.emplace_back(cvRound((vertices[i].x - m_Crop_Roi_paramImg.x) * fs_resize_x),
|
|
|
|
|
cvRound((vertices[i].y - m_Crop_Roi_paramImg.y) * fs_resize_y));
|
|
|
|
|
}
|
|
|
|
|
cv::polylines(m_CheckResult_shareP->resultimg, draw_pts, true, cv::Scalar(255, 0, 0), 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_pbaseCheckFunction && m_pbaseCheckFunction->markLine.region.size() > 1)
|
|
|
|
|
{
|
|
|
|
|
std::vector<cv::Point> product_roi_show;
|
|
|
|
|
@ -1815,7 +1868,7 @@ int ImgCheckAnalysisy::Pin_Qx_Det(const cv::Mat &img)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (m_Edge_DetConfig.bSaveResultImg)
|
|
|
|
|
if (m_Edge_DetConfig.bSaveResultImg)
|
|
|
|
|
{
|
|
|
|
|
Mat showimg;
|
|
|
|
|
cv::cvtColor(img, showimg, cv::COLOR_GRAY2BGR);
|
|
|
|
|
|