|
|
|
@ -11,6 +11,7 @@
|
|
|
|
#include "Define.h"
|
|
|
|
#include "Define.h"
|
|
|
|
#include <omp.h>
|
|
|
|
#include <omp.h>
|
|
|
|
#include "AICommonDefine.h"
|
|
|
|
#include "AICommonDefine.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
// 用于排序轮廓的比较函数
|
|
|
|
// 用于排序轮廓的比较函数
|
|
|
|
static bool compareContourAreas(const vector<Point> &contour1, const vector<Point> &contour2)
|
|
|
|
static bool compareContourAreas(const vector<Point> &contour1, const vector<Point> &contour2)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -2025,6 +2026,8 @@ int ImgCheckAnalysisy::AI_Edge(const cv::Mat &img, cv::RotatedRect &outerRoi, cv
|
|
|
|
}
|
|
|
|
}
|
|
|
|
config.strChannel = DetImgInfo_shareP->strChannel;
|
|
|
|
config.strChannel = DetImgInfo_shareP->strChannel;
|
|
|
|
config.pBaseCheckFunction = m_pbaseCheckFunction;
|
|
|
|
config.pBaseCheckFunction = m_pbaseCheckFunction;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 定位获取三个roi */
|
|
|
|
int re = m_pAI_Edge_Algin.Detect(img, &config, m_pEdge_Align_Result);
|
|
|
|
int re = m_pAI_Edge_Algin.Detect(img, &config, m_pEdge_Align_Result);
|
|
|
|
if (re != 0)
|
|
|
|
if (re != 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -2042,7 +2045,92 @@ int ImgCheckAnalysisy::AI_Edge(const cv::Mat &img, cv::RotatedRect &outerRoi, cv
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tagroiList = m_pEdge_Align_Result->tagroi;
|
|
|
|
tagroiList = m_pEdge_Align_Result->tagroi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// getchar();
|
|
|
|
|
|
|
|
|
|
|
|
/*使用m_pEdge_Align_Result->bigmask检测把手是否缺失*/
|
|
|
|
|
|
|
|
// 截取把手大致区域
|
|
|
|
|
|
|
|
RotatedRect tpl_handle_rroi = m_pbaseCheckFunction->supportDet.handleRect;
|
|
|
|
|
|
|
|
Rect handle_rect = Rect(tpl_handle_rroi.boundingRect().x, 0, tpl_handle_rroi.boundingRect().width, m_pEdge_Align_Result->bigmask.rows);
|
|
|
|
|
|
|
|
Mat handle_roi = m_pEdge_Align_Result->bigmask(handle_rect & Rect(0, 0, m_pEdge_Align_Result->bigmask.cols, m_pEdge_Align_Result->bigmask.rows)).clone();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 对handle_roi做一下开运算
|
|
|
|
|
|
|
|
Mat element = getStructuringElement(MORPH_RECT, Size(tpl_handle_rroi.boundingRect().width / 3, tpl_handle_rroi.boundingRect().height / 3));
|
|
|
|
|
|
|
|
morphologyEx(handle_roi, handle_roi, MORPH_OPEN, element);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// imwrite("handle_roi.png", handle_roi);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// handle_roi找到最大连通域,和tpl_handle_rroi做面积形状比较,差异过大判为把手缺失,添加到缺陷并NG
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Base_Function_Support_Det &handleDet = m_pbaseCheckFunction->supportDet;
|
|
|
|
|
|
|
|
if (handleDet.bOpen && tpl_handle_rroi.size.width > 0 && tpl_handle_rroi.size.height > 0 && !handle_roi.empty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::vector<std::vector<cv::Point>> handle_contours;
|
|
|
|
|
|
|
|
cv::findContours(handle_roi, handle_contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool bHandleLoss = false;
|
|
|
|
|
|
|
|
if (handle_contours.empty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bHandleLoss = true; // 没有连通域,把手完全缺失
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 取最大连通域
|
|
|
|
|
|
|
|
std::sort(handle_contours.begin(), handle_contours.end(), compareContourAreas);
|
|
|
|
|
|
|
|
cv::RotatedRect cur_handle_rrect = cv::minAreaRect(handle_contours[0]);
|
|
|
|
|
|
|
|
double curArea = cv::contourArea(handle_contours[0]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 面积比较
|
|
|
|
|
|
|
|
double tplArea = tpl_handle_rroi.size.width * tpl_handle_rroi.size.height;
|
|
|
|
|
|
|
|
double areaRatio = (tplArea > 0.0) ? (curArea / tplArea) : 0.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 形状比较(长宽比)
|
|
|
|
|
|
|
|
float tplW = std::max(tpl_handle_rroi.size.width, tpl_handle_rroi.size.height);
|
|
|
|
|
|
|
|
float tplH = std::min(tpl_handle_rroi.size.width, tpl_handle_rroi.size.height);
|
|
|
|
|
|
|
|
float curW = std::max(cur_handle_rrect.size.width, cur_handle_rrect.size.height);
|
|
|
|
|
|
|
|
float curH = std::min(cur_handle_rrect.size.width, cur_handle_rrect.size.height);
|
|
|
|
|
|
|
|
float tplRatio = (tplH > 0.0f) ? (tplW / tplH) : 0.0f;
|
|
|
|
|
|
|
|
float curRatio = (curH > 0.0f) ? (curW / curH) : 0.0f;
|
|
|
|
|
|
|
|
float ratioDiff = (tplRatio > 0.0f) ? fabs(curRatio - tplRatio) / tplRatio : 0.0f;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 面积差异过大 或 形状差异过大 判为把手缺失
|
|
|
|
|
|
|
|
if (areaRatio < 0.6f || ratioDiff > 0.6f)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bHandleLoss = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_0, "把手检测", "areaRatio %f ratioDiff %f", areaRatio, ratioDiff);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (bHandleLoss)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QX_ERROR_INFO_ temerror;
|
|
|
|
|
|
|
|
temerror.Idx = m_pDetResult->pQx_ErrorList->size();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 把手模板 roi 在原图坐标系,转换为检测图(detImg)坐标系
|
|
|
|
|
|
|
|
cv::Rect roi = tpl_handle_rroi.boundingRect();
|
|
|
|
|
|
|
|
roi.x -= outerRoi.boundingRect().x;
|
|
|
|
|
|
|
|
roi.y -= outerRoi.boundingRect().y;
|
|
|
|
|
|
|
|
roi &= cv::Rect(0, 0, outerRoi.boundingRect().width, outerRoi.boundingRect().height);
|
|
|
|
|
|
|
|
temerror.roi = roi;
|
|
|
|
|
|
|
|
temerror.area = roi.width * roi.height;
|
|
|
|
|
|
|
|
temerror.JudgArea = roi.width * m_fImgage_Scale_X * roi.height * m_fImgage_Scale_Y;
|
|
|
|
|
|
|
|
temerror.JudgArea_second = temerror.JudgArea;
|
|
|
|
|
|
|
|
float w = tpl_handle_rroi.size.width;
|
|
|
|
|
|
|
|
float h = tpl_handle_rroi.size.height;
|
|
|
|
|
|
|
|
temerror.flen = (w > h ? w : h) * m_fImgage_Scale_X;
|
|
|
|
|
|
|
|
temerror.fbreadth = (w > h ? h : w) * m_fImgage_Scale_Y;
|
|
|
|
|
|
|
|
temerror.nconfig_qx_type = CONFIG_QX_NAME_support_loss;
|
|
|
|
|
|
|
|
temerror.qx_name = CONFIG_QX_NAME_Names[temerror.nconfig_qx_type];
|
|
|
|
|
|
|
|
temerror.result = QX_RESULT_TYPE_NG;
|
|
|
|
|
|
|
|
temerror.result_name = QX_RESULT_TYPE_Names[QX_RESULT_TYPE_NG];
|
|
|
|
|
|
|
|
temerror.detRegionidxList.push_back(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_pDetResult->pQx_ErrorList->push_back(temerror);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_0, "把手检测", "handle loss NG roi [%d %d %d %d]", roi.x, roi.y, roi.width, roi.height);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return re;
|
|
|
|
return re;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|