|
|
|
@ -561,12 +561,16 @@ int ImgCheckAnalysisy::CheckRun()
|
|
|
|
long time_calan_e = CheckUtil::getcurTime();
|
|
|
|
long time_calan_e = CheckUtil::getcurTime();
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_0, "2.1、pre detect", "-------------------------CalAndAffine------------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);
|
|
|
|
|
|
|
|
|
|
|
|
/*生成 检测的图片*/
|
|
|
|
/*生成 检测的图片(检测用图固定为单通道灰度;彩色原图按 BGR 顺序转灰度,与 imread(path,0) 的亮度一致)*/
|
|
|
|
cv::Mat image;
|
|
|
|
cv::Mat image;
|
|
|
|
image = m_CheckResult_shareP->in_shareImage->img;
|
|
|
|
image = m_CheckResult_shareP->in_shareImage->img;
|
|
|
|
if (image.channels() == 3)
|
|
|
|
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
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -1139,8 +1143,7 @@ int ImgCheckAnalysisy::GetALLBlob()
|
|
|
|
int thickness = 1;
|
|
|
|
int thickness = 1;
|
|
|
|
|
|
|
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, strBaseLog, "Save Tem Img");
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, strBaseLog, "Save Tem Img");
|
|
|
|
cv::Mat tm;
|
|
|
|
cv::Mat tm = m_pImageAllResult->AIMaskImg.clone(); // 保持 mask 单通道,不再灰度转假彩
|
|
|
|
cv::cvtColor(m_pImageAllResult->AIMaskImg, tm, cv::COLOR_GRAY2RGB); // 彩色 可选项
|
|
|
|
|
|
|
|
for (int i = 0; i < blobs.blobCount; i++)
|
|
|
|
for (int i = 0; i < blobs.blobCount; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cv::Rect roi;
|
|
|
|
cv::Rect roi;
|
|
|
|
@ -1151,18 +1154,18 @@ int ImgCheckAnalysisy::GetALLBlob()
|
|
|
|
|
|
|
|
|
|
|
|
if (blobs.blobTab[i].ErrType == 0)
|
|
|
|
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
|
|
|
|
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];
|
|
|
|
char buffer[128];
|
|
|
|
sprintf(buffer, "id:%d type:%d m %0.1f", i,blobs.blobTab[i].ErrType, blobs.blobTab[i].density);
|
|
|
|
sprintf(buffer, "id:%d type:%d m %0.1f", i,blobs.blobTab[i].ErrType, blobs.blobTab[i].density);
|
|
|
|
std::string text = buffer;
|
|
|
|
std::string text = buffer;
|
|
|
|
cv::Point origin = cv::Point(roi.x, roi.y);
|
|
|
|
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);
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -1383,18 +1386,10 @@ int ImgCheckAnalysisy::AI_Detect_Thread(const cv::Mat &img, cv::Mat &ResultImg)
|
|
|
|
if (DetImgInfo_shareP->bsaveProcessImg)
|
|
|
|
if (DetImgInfo_shareP->bsaveProcessImg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
cv::Mat imshow;
|
|
|
|
cv::Mat imshow = img.clone(); // 保持输入通道,不再灰度转假彩
|
|
|
|
if (img.channels() == 1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
cv::cvtColor(img, imshow, cv::COLOR_GRAY2RGB); // 彩色 可选项
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
imshow = img.clone();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < SmallRoiList.size(); i++)
|
|
|
|
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);
|
|
|
|
cv::imwrite(DetImgInfo_shareP->strChannel + "_AI_Det_ROI.jpg", imshow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -1719,11 +1714,21 @@ int ImgCheckAnalysisy::ResizeImg()
|
|
|
|
float fw = RESIZE_IMAGE_WIDTH * 1.0f / m_pImageAllResult->detImg.cols;
|
|
|
|
float fw = RESIZE_IMAGE_WIDTH * 1.0f / m_pImageAllResult->detImg.cols;
|
|
|
|
sz.height = int(m_pImageAllResult->detImg.rows * fw);
|
|
|
|
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))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
srcCanvas = srcImg(m_outer_roi);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cv::cvtColor(m_pImageAllResult->resultImg, m_pImageAllResult->resultImg, cv::COLOR_GRAY2BGR);
|
|
|
|
srcCanvas = m_pImageAllResult->detImg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cv::resize(srcCanvas, m_pImageAllResult->resultImg, sz);
|
|
|
|
m_CheckResult_shareP->resultimg = m_pImageAllResult->resultImg;
|
|
|
|
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_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);
|
|
|
|
m_outer_roi.width, m_outer_roi.height, sz.width, sz.height);
|
|
|
|
@ -1820,8 +1825,9 @@ int ImgCheckAnalysisy::DrawResult_Step_1()
|
|
|
|
|
|
|
|
|
|
|
|
// std::cout << polygon << std::endl;
|
|
|
|
// std::cout << polygon << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
// 绘制多边形的边界(不填充),使用绿色线条,线宽为2
|
|
|
|
// 绘制多边形的边界(不填充),线宽为1;颜色按画布通道自适应
|
|
|
|
cv::polylines(m_CheckResult_shareP->resultimg, polygon, true, cv::Scalar(128, 128, 255), 1); // true表示闭合多边形
|
|
|
|
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_src.png", m_pdetlog->temImgList[TEM_IMG_IDX_DrawSrc]);
|
|
|
|
// cv::imwrite(DetImgInfo_shareP->strChannel + "roi_ss.png", m_pdetlog->temImgList[TEM_IMG_IDX_Result]);
|
|
|
|
// cv::imwrite(DetImgInfo_shareP->strChannel + "roi_ss.png", m_pdetlog->temImgList[TEM_IMG_IDX_Result]);
|
|
|
|
@ -1841,7 +1847,8 @@ int ImgCheckAnalysisy::DrawResult_Step_1()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
draw_pts.emplace_back(cvRound(pt.x * fs_resize_x), cvRound(pt.y * fs_resize_y));
|
|
|
|
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);
|
|
|
|
cv::polylines(m_CheckResult_shareP->resultimg, draw_pts, true,
|
|
|
|
|
|
|
|
CheckUtil::GetDrawColor(m_CheckResult_shareP->resultimg, cv::Scalar(255, 255, 0)), 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const auto &contour : m_curPinContours)
|
|
|
|
for (const auto &contour : m_curPinContours)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -1851,7 +1858,8 @@ int ImgCheckAnalysisy::DrawResult_Step_1()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
draw_pts.emplace_back(cvRound(pt.x * fs_resize_x), cvRound(pt.y * fs_resize_y));
|
|
|
|
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);
|
|
|
|
cv::polylines(m_CheckResult_shareP->resultimg, draw_pts, true,
|
|
|
|
|
|
|
|
CheckUtil::GetDrawColor(m_CheckResult_shareP->resultimg, cv::Scalar(255, 0, 255)), 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 绘制m_inner_rroi(蓝色)
|
|
|
|
// 绘制m_inner_rroi(蓝色)
|
|
|
|
@ -1865,7 +1873,8 @@ int ImgCheckAnalysisy::DrawResult_Step_1()
|
|
|
|
draw_pts.emplace_back(cvRound((vertices[i].x - m_Crop_Roi_paramImg.x) * fs_resize_x),
|
|
|
|
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));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// cv::imwrite("sss.png", m_CheckResult_shareP->resultimg);
|
|
|
|
// cv::imwrite("sss.png", m_CheckResult_shareP->resultimg);
|
|
|
|
@ -2095,10 +2104,24 @@ int ImgCheckAnalysisy::Pin_Qx_Det(const cv::Mat &img)
|
|
|
|
|
|
|
|
|
|
|
|
if (m_Edge_DetConfig.bSaveResultImg)
|
|
|
|
if (m_Edge_DetConfig.bSaveResultImg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
// 画布优先用原图裁剪区(保持原图通道),ReJson 或异常时退回检测图
|
|
|
|
Mat showimg;
|
|
|
|
Mat showimg;
|
|
|
|
cv::cvtColor(img, showimg, cv::COLOR_GRAY2BGR);
|
|
|
|
const cv::Mat &srcImg = m_CheckResult_shareP->in_shareImage->img;
|
|
|
|
cv::drawContours(showimg, m_curPinContours, -1, cv::Scalar(0, 0, 255), 1);
|
|
|
|
if (m_CheckResult_shareP->in_shareImage->Det_Mode != DET_MODE_ReJson &&
|
|
|
|
cv::drawContours(showimg, m_tplPinContours, -1, cv::Scalar(0, 255, 0), 1);
|
|
|
|
!srcImg.empty() && CheckUtil::RoiInImg(m_outer_roi, srcImg))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
showimg = srcImg(m_outer_roi).clone();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
showimg = img.clone();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showimg.size() != img.size())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
showimg = img.clone();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cv::drawContours(showimg, m_curPinContours, -1, CheckUtil::GetDrawColor(showimg, cv::Scalar(0, 0, 255)), 1);
|
|
|
|
|
|
|
|
cv::drawContours(showimg, m_tplPinContours, -1, CheckUtil::GetDrawColor(showimg, cv::Scalar(0, 255, 0)), 1);
|
|
|
|
imwrite("pin_contours.png", showimg);
|
|
|
|
imwrite("pin_contours.png", showimg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|