|
|
|
|
@ -503,12 +503,16 @@ int ImgCheckAnalysisy::CheckRun()
|
|
|
|
|
long time_calan_e = CheckUtil::getcurTime();
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_0, "2.1、pre detect", "-------------------------Adapt_Config------------succ---time %ld----\n", time_calan_e - time_edge_s);
|
|
|
|
|
|
|
|
|
|
/*生成 检测的图片*/
|
|
|
|
|
/*生成 检测的图片(检测用图固定为单通道灰度;彩色原图按 BGR 顺序转灰度,与 imread(path,0) 的亮度一致)*/
|
|
|
|
|
cv::Mat image;
|
|
|
|
|
image = m_CheckResult_shareP->in_shareImage->img;
|
|
|
|
|
if (image.channels() == 3)
|
|
|
|
|
{
|
|
|
|
|
cv::cvtColor(image(m_outer_roi), m_pImageAllResult->detImg, cv::COLOR_RGB2GRAY);
|
|
|
|
|
cv::cvtColor(image(m_outer_roi), m_pImageAllResult->detImg, cv::COLOR_BGR2GRAY);
|
|
|
|
|
}
|
|
|
|
|
else if (image.channels() == 4)
|
|
|
|
|
{
|
|
|
|
|
cv::cvtColor(image(m_outer_roi), m_pImageAllResult->detImg, cv::COLOR_BGRA2GRAY);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
@ -1269,8 +1273,7 @@ int ImgCheckAnalysisy::GetALLBlob()
|
|
|
|
|
int thickness = 1;
|
|
|
|
|
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, strBaseLog, "Save Tem Img");
|
|
|
|
|
cv::Mat tm;
|
|
|
|
|
cv::cvtColor(m_pImageAllResult->AIMaskImg, tm, cv::COLOR_GRAY2RGB); // 彩色 可选项
|
|
|
|
|
cv::Mat tm = m_pImageAllResult->AIMaskImg.clone(); // 保持 mask 单通道,不再灰度转假彩
|
|
|
|
|
for (int i = 0; i < blobs.blobCount; i++)
|
|
|
|
|
{
|
|
|
|
|
cv::Rect roi;
|
|
|
|
|
@ -1281,18 +1284,18 @@ int ImgCheckAnalysisy::GetALLBlob()
|
|
|
|
|
|
|
|
|
|
if (blobs.blobTab[i].ErrType == 0)
|
|
|
|
|
{
|
|
|
|
|
cv::rectangle(tm, roi, cv::Scalar(0, 0, 255));
|
|
|
|
|
cv::rectangle(tm, roi, CheckUtil::GetDrawColor(tm, cv::Scalar(0, 0, 255)));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cv::rectangle(tm, roi, cv::Scalar(0, 255, 255));
|
|
|
|
|
cv::rectangle(tm, roi, CheckUtil::GetDrawColor(tm, cv::Scalar(0, 255, 255)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char buffer[128];
|
|
|
|
|
sprintf(buffer, "id:%d type:%d m %0.1f", i,blobs.blobTab[i].ErrType, blobs.blobTab[i].density);
|
|
|
|
|
std::string text = buffer;
|
|
|
|
|
cv::Point origin = cv::Point(roi.x, roi.y);
|
|
|
|
|
cv::putText(tm, text, origin, font_face, font_scale, cv::Scalar(0, 255, 0), thickness, 1, 0);
|
|
|
|
|
cv::putText(tm, text, origin, font_face, font_scale, CheckUtil::GetDrawColor(tm, cv::Scalar(0, 255, 0)), thickness, 1, 0);
|
|
|
|
|
|
|
|
|
|
// printf("type: %d %d %d %d %d %d %d\n", blobs.blobTab[i].ErrType, blobs.blobTab[i].area, blobs.blobTab[i].energy, roi.x, roi.y, roi.width, roi.height);
|
|
|
|
|
}
|
|
|
|
|
@ -1510,18 +1513,10 @@ int ImgCheckAnalysisy::AI_Detect_Thread(const cv::Mat &img, cv::Mat &ResultImg)
|
|
|
|
|
if (DetImgInfo_shareP->bsaveProcessImg)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
cv::Mat imshow;
|
|
|
|
|
if (img.channels() == 1)
|
|
|
|
|
{
|
|
|
|
|
cv::cvtColor(img, imshow, cv::COLOR_GRAY2RGB); // 彩色 可选项
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
imshow = img.clone();
|
|
|
|
|
}
|
|
|
|
|
cv::Mat imshow = img.clone(); // 保持输入通道,不再灰度转假彩
|
|
|
|
|
for (int i = 0; i < SmallRoiList.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
cv::rectangle(imshow, SmallRoiList.at(i), cv::Scalar(0, 0, 255), 3);
|
|
|
|
|
cv::rectangle(imshow, SmallRoiList.at(i), CheckUtil::GetDrawColor(imshow, cv::Scalar(0, 0, 255)), 3);
|
|
|
|
|
}
|
|
|
|
|
cv::imwrite(DetImgInfo_shareP->strChannel + "_AI_Det_ROI.jpg", imshow);
|
|
|
|
|
}
|
|
|
|
|
@ -1791,11 +1786,21 @@ int ImgCheckAnalysisy::ResizeImg()
|
|
|
|
|
float fw = RESIZE_IMAGE_WIDTH * 1.0f / m_pImageAllResult->detImg.cols;
|
|
|
|
|
sz.height = int(m_pImageAllResult->detImg.rows * fw);
|
|
|
|
|
|
|
|
|
|
cv::resize(m_pImageAllResult->detImg, m_pImageAllResult->resultImg, sz);
|
|
|
|
|
if (m_pImageAllResult->resultImg.channels() == 1)
|
|
|
|
|
// 结果图画布取自"原图裁剪区",保持原图通道(彩色原图 -> 真实彩色,不再灰度转假彩);
|
|
|
|
|
// ReJson 复测模式下 in_shareImage->img 本身就是裁剪图,直接用检测图兜底
|
|
|
|
|
cv::Mat srcCanvas;
|
|
|
|
|
const cv::Mat &srcImg = m_CheckResult_shareP->in_shareImage->img;
|
|
|
|
|
if (m_CheckResult_shareP->in_shareImage->Det_Mode != DET_MODE_ReJson &&
|
|
|
|
|
!srcImg.empty() && CheckUtil::RoiInImg(m_outer_roi, srcImg))
|
|
|
|
|
{
|
|
|
|
|
cv::cvtColor(m_pImageAllResult->resultImg, m_pImageAllResult->resultImg, cv::COLOR_GRAY2BGR);
|
|
|
|
|
srcCanvas = srcImg(m_outer_roi);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
srcCanvas = m_pImageAllResult->detImg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cv::resize(srcCanvas, m_pImageAllResult->resultImg, sz);
|
|
|
|
|
m_CheckResult_shareP->resultimg = m_pImageAllResult->resultImg;
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_1, "showImg size", " [w %d,h %d]-> show img [w %d,h %d] ",
|
|
|
|
|
m_outer_roi.width, m_outer_roi.height, sz.width, sz.height);
|
|
|
|
|
@ -1892,8 +1897,9 @@ int ImgCheckAnalysisy::DrawResult_Step_1()
|
|
|
|
|
|
|
|
|
|
// std::cout << polygon << std::endl;
|
|
|
|
|
|
|
|
|
|
// 绘制多边形的边界(不填充),使用绿色线条,线宽为2
|
|
|
|
|
cv::polylines(m_CheckResult_shareP->resultimg, polygon, true, cv::Scalar(128, 128, 255), 1); // true表示闭合多边形
|
|
|
|
|
// 绘制多边形的边界(不填充),线宽为1;颜色按画布通道自适应
|
|
|
|
|
cv::polylines(m_CheckResult_shareP->resultimg, polygon, true,
|
|
|
|
|
CheckUtil::GetDrawColor(m_CheckResult_shareP->resultimg, cv::Scalar(128, 128, 255)), 1); // true表示闭合多边形
|
|
|
|
|
}
|
|
|
|
|
// cv::imwrite(DetImgInfo_shareP->strChannel + "roi_src.png", m_pdetlog->temImgList[TEM_IMG_IDX_DrawSrc]);
|
|
|
|
|
// cv::imwrite(DetImgInfo_shareP->strChannel + "roi_ss.png", m_pdetlog->temImgList[TEM_IMG_IDX_Result]);
|
|
|
|
|
@ -1916,7 +1922,8 @@ int ImgCheckAnalysisy::DrawResult_Step_1()
|
|
|
|
|
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);
|
|
|
|
|
cv::polylines(m_CheckResult_shareP->resultimg, draw_pts, true,
|
|
|
|
|
CheckUtil::GetDrawColor(m_CheckResult_shareP->resultimg, cv::Scalar(255, 0, 0)), 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_pbaseCheckFunction && m_pbaseCheckFunction->markLine.region.size() > 1)
|
|
|
|
|
@ -1934,7 +1941,7 @@ int ImgCheckAnalysisy::DrawResult_Step_1()
|
|
|
|
|
m_CheckResult_shareP->resultimg,
|
|
|
|
|
product_roi_show,
|
|
|
|
|
true,
|
|
|
|
|
cv::Scalar(0, 255, 0),
|
|
|
|
|
CheckUtil::GetDrawColor(m_CheckResult_shareP->resultimg, cv::Scalar(0, 255, 0)),
|
|
|
|
|
1);
|
|
|
|
|
}
|
|
|
|
|
if (m_pEdge_Align_Result.get() != NULL)
|
|
|
|
|
@ -1949,7 +1956,8 @@ int ImgCheckAnalysisy::DrawResult_Step_1()
|
|
|
|
|
cv::Point p;
|
|
|
|
|
p.x = m_pEdge_Align_Result->markresulList[i].det_Local_DetImg.x * fs_resize_x;
|
|
|
|
|
p.y = m_pEdge_Align_Result->markresulList[i].det_Local_DetImg.y * fs_resize_y;
|
|
|
|
|
cv::circle(m_CheckResult_shareP->resultimg, p, 5, cv::Scalar(0, 255, 0));
|
|
|
|
|
cv::circle(m_CheckResult_shareP->resultimg, p, 5,
|
|
|
|
|
CheckUtil::GetDrawColor(m_CheckResult_shareP->resultimg, cv::Scalar(0, 255, 0)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|