|
|
|
@ -8,6 +8,7 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#include "ImgCheckAnalysisy.hpp"
|
|
|
|
#include "ImgCheckAnalysisy.hpp"
|
|
|
|
#include "CheckUtil.hpp"
|
|
|
|
#include "CheckUtil.hpp"
|
|
|
|
|
|
|
|
#include "ImgMmPatch.hpp"
|
|
|
|
#include "Define.h"
|
|
|
|
#include "Define.h"
|
|
|
|
#include <omp.h>
|
|
|
|
#include <omp.h>
|
|
|
|
#include "AICommonDefine.h"
|
|
|
|
#include "AICommonDefine.h"
|
|
|
|
@ -2819,6 +2820,7 @@ int ImgCheckAnalysisy::AI_Edge(const cv::Mat &img, cv::Rect &cutRoi)
|
|
|
|
int ImgCheckAnalysisy::CalProductSize()
|
|
|
|
int ImgCheckAnalysisy::CalProductSize()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
float fw, fh;
|
|
|
|
float fw, fh;
|
|
|
|
|
|
|
|
float fhPixel = 0.f; // 产品沿长度方向(y)的像素高度,供长度方向分段补丁换算用
|
|
|
|
if (m_bRotCurRoiValid)
|
|
|
|
if (m_bRotCurRoiValid)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// 产品存在旋转角:用旋转矩形四个顶点的实际边长换算物理尺寸
|
|
|
|
// 产品存在旋转角:用旋转矩形四个顶点的实际边长换算物理尺寸
|
|
|
|
@ -2829,21 +2831,31 @@ int ImgCheckAnalysisy::CalProductSize()
|
|
|
|
double dy = (a.y - b.y) * m_fImgage_Scale_Y;
|
|
|
|
double dy = (a.y - b.y) * m_fImgage_Scale_Y;
|
|
|
|
return std::sqrt(dx * dx + dy * dy);
|
|
|
|
return std::sqrt(dx * dx + dy * dy);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// 纯像素边长(不带成像精度),供长度方向的分段补丁使用
|
|
|
|
|
|
|
|
auto edgeLenPixel = [&](const cv::Point2f &a, const cv::Point2f &b) -> double {
|
|
|
|
|
|
|
|
double dx = a.x - b.x;
|
|
|
|
|
|
|
|
double dy = a.y - b.y;
|
|
|
|
|
|
|
|
return std::sqrt(dx * dx + dy * dy);
|
|
|
|
|
|
|
|
};
|
|
|
|
fw = (float)((edgeLenPhys(v[0], v[1]) + edgeLenPhys(v[2], v[3])) * 0.5); // 上边+下边平均
|
|
|
|
fw = (float)((edgeLenPhys(v[0], v[1]) + edgeLenPhys(v[2], v[3])) * 0.5); // 上边+下边平均
|
|
|
|
fh = (float)((edgeLenPhys(v[0], v[2]) + edgeLenPhys(v[1], v[3])) * 0.5); // 左边+右边平均
|
|
|
|
fhPixel = (float)((edgeLenPixel(v[0], v[2]) + edgeLenPixel(v[1], v[3])) * 0.5); // 左边+右边平均(像素)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
fw = m_CutRoi.width * m_fImgage_Scale_X;
|
|
|
|
fw = m_CutRoi.width * m_fImgage_Scale_X;
|
|
|
|
fh = m_CutRoi.height * m_fImgage_Scale_Y;
|
|
|
|
fhPixel = (float)m_CutRoi.height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 【临时补丁】长度方向(上下边)产品运动速率不恒定,按分段像素进度换算像素->mm;
|
|
|
|
|
|
|
|
// 与缺陷 y 坐标(ImageResultJudge::BuildDefectImage)共用 ImgMmPatch.hpp 里的同一张分段表。
|
|
|
|
|
|
|
|
// 宽度不做补丁,仍用成像精度换算。
|
|
|
|
|
|
|
|
fh = PixelYToMm(fhPixel);
|
|
|
|
fw = std::ceil(fw * 10) / 10;
|
|
|
|
fw = std::ceil(fw * 10) / 10;
|
|
|
|
fh = std::ceil(fh * 10) / 10;
|
|
|
|
fh = std::ceil(fh * 10) / 10;
|
|
|
|
m_CheckResult_shareP->productWidht_mm = fw;
|
|
|
|
m_CheckResult_shareP->productWidht_mm = fw;
|
|
|
|
m_CheckResult_shareP->productHeight_mm = fh;
|
|
|
|
m_CheckResult_shareP->productHeight_mm = fh;
|
|
|
|
|
|
|
|
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_1, "Det ROI", " [x%d, y%d, w %d,h %d] (piexl) -> [w %f h %f](mm),scale %f %f",
|
|
|
|
m_pdetlog->AddCheckstr(PrintLevel_1, "Det ROI", " [x%d, y%d, w %d,h %d] (piexl) -> [w %f h %f](mm),scale %f %f, hPixel %f",
|
|
|
|
m_CutRoi.x, m_CutRoi.y, m_CutRoi.width, m_CutRoi.height, fw, fh, m_fImgage_Scale_X, m_fImgage_Scale_Y);
|
|
|
|
m_CutRoi.x, m_CutRoi.y, m_CutRoi.width, m_CutRoi.height, fw, fh, m_fImgage_Scale_X, m_fImgage_Scale_Y, fhPixel);
|
|
|
|
|
|
|
|
|
|
|
|
// 打印产品旋转矩形的四角坐标(原图坐标系),便于核对尺寸换算与后续坐标映射
|
|
|
|
// 打印产品旋转矩形的四角坐标(原图坐标系),便于核对尺寸换算与后续坐标映射
|
|
|
|
if (m_bRotCurRoiValid)
|
|
|
|
if (m_bRotCurRoiValid)
|
|
|
|
|