From 4d6a23ebbb8ce3e13e1ab1894b26481d3cad83cc Mon Sep 17 00:00:00 2001 From: bestlqiang Date: Wed, 1 Dec 2021 23:45:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=AE=97=E6=B3=95:=E5=88=9A?= =?UTF-8?q?=E6=80=A7=E5=8F=98=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LaiPuLaser/CommonFlowMgr.cpp | 35 +++++++++++++++++++++ LaiPuLaser/CommonFlowMgr.h | 5 +++ LaiPuLaser/Product.cpp | 60 ++++++++++++++++++++++++++++++------ 3 files changed, 90 insertions(+), 10 deletions(-) diff --git a/LaiPuLaser/CommonFlowMgr.cpp b/LaiPuLaser/CommonFlowMgr.cpp index bb3e90b..a1dfa78 100644 --- a/LaiPuLaser/CommonFlowMgr.cpp +++ b/LaiPuLaser/CommonFlowMgr.cpp @@ -381,6 +381,41 @@ CMFCPropertyGridProperty * CCommonFlowMgr::CreatGridProperty() pGroup1->AddSubItem(p); gDevicePropertieMgr.Insert(p, pPropertie); } + + { + //添加属性变量映射 + Name = _T("m_bUseEstimateAffine");//变量名字 + CPropertie *pPropertie = new CPropertie; + pPropertie->SetpVal((void*)&m_bUseEstimateAffine); + pPropertie->SetType(_PROP_TYPE_BOOL); + pPropertie->SetpModule(this); + pPropertie->SetPath(Path); + pPropertie->SetName(Name); + pPropertie->WriteRead(true);//读取保存的属性 + //添加属性显示 + PropertyName = _T("使用刚性变换"); + Description = _T("true:刚性变换 ,false:仿射变换"); + CMFCPropertyGridProperty* p = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_bUseEstimateAffine, Description); + pGroup1->AddSubItem(p); + gDevicePropertieMgr.Insert(p, pPropertie); + } + { + //添加属性变量映射 + Name = _T("m_EstimateAffinepar");//变量名字 + CPropertie *pPropertie = new CPropertie; + pPropertie->SetpVal((void*)&m_EstimateAffinepar); + pPropertie->SetType(_PROP_TYPE_INT); + pPropertie->SetpModule(this); + pPropertie->SetPath(Path); + pPropertie->SetName(Name); + pPropertie->WriteRead(true);//读取保存的属性 + //添加属性显示 + PropertyName = _T("刚性变换参数"); + Description = _T("刚性变换参数:0,1,2"); + CMFCPropertyGridProperty* p = new CMFCPropertyGridProperty(PropertyName, (_variant_t)m_EstimateAffinepar, Description); + pGroup1->AddSubItem(p); + gDevicePropertieMgr.Insert(p, pPropertie); + } { //添加属性变量映射 Name = _T("m_AdjustOffset_X");//变量名字 diff --git a/LaiPuLaser/CommonFlowMgr.h b/LaiPuLaser/CommonFlowMgr.h index 132daf2..cab34ae 100644 --- a/LaiPuLaser/CommonFlowMgr.h +++ b/LaiPuLaser/CommonFlowMgr.h @@ -56,6 +56,10 @@ public: void ResetProductOffset(); void SetbCollectSpecialObj(bool b){m_bCollectSpecialObj = b;}; bool IsbCollectSpecialObj(){return m_bCollectSpecialObj;}; + + bool IsUseEstimateAffine() { return m_bUseEstimateAffine; }; //是否使用刚性变换 + int m_EstimateAffinepar=0; + bool IsbStretchDataToRealSize(){return m_bStretchDataToRealSize;}; bool CameraCatchMark3(CProduct &Product); @@ -116,6 +120,7 @@ private: double m_RotatoAdjust;//旋转调整mm bool m_bStretchDataToRealSize;//根据抓取结果拉伸数据 + bool m_bUseEstimateAffine = true;//是否使用刚性变换,否则使用仿射变换 //平台cut 参数-------------------------------------------------------------- bool m_bUseLaser;//是否开关激光 //振镜校准参数-------------------------------------------------------------- diff --git a/LaiPuLaser/Product.cpp b/LaiPuLaser/Product.cpp index 319e994..ef96464 100644 --- a/LaiPuLaser/Product.cpp +++ b/LaiPuLaser/Product.cpp @@ -348,20 +348,60 @@ void CProduct::CalAffinePars() - //得放射变换参数矩阵 - warp_mat = getAffineTransform(ThroryCoords, RealCoords); - warp_mat.convertTo(warp_mat, CV_32FC1);//不转化时,默认CV_64FC1 后续计算会错误 + //得放射变换参数矩阵 + warp_mat = getAffineTransform(ThroryCoords, RealCoords); + warp_mat.convertTo(warp_mat, CV_32FC1);//不转化时,默认CV_64FC1 后续计算会错误 + + //取出6个变换参数 + m_p00 = warp_mat.at(0, 0); + m_p01 = warp_mat.at(0, 1); + m_p02 = warp_mat.at(0, 2);//m_CatchMark1Oft.x;// + + m_p10 = warp_mat.at(1, 0); + m_p11 = warp_mat.at(1, 1); + m_p12 = warp_mat.at(1, 2);//m_CatchMark1Oft.y;// + + + logstr.Format("仿射=====>偏移:[%.4f]~[%.4f]", m_p02, m_p12); + gLogMgr->WriteDebugLog(logstr); + + logstr.Format("仿射=====>X参数:[ %.4f ]~[%.4f]", m_p00, m_p01); + gLogMgr->WriteDebugLog(logstr); + + logstr.Format("仿射=====>Y参数:[ %.4f ]~[%.4f]", m_p10, m_p11); + gLogMgr->WriteDebugLog(logstr); + + //刚性变换 + if (gCommonFlowMgr->IsUseEstimateAffine()) + { + vector src(ThroryCoords, ThroryCoords + 2); + vector dest(RealCoords, RealCoords + 2); + auto tempMat = warp_mat; + + int Method = abs(gCommonFlowMgr->m_EstimateAffinepar) % 3; + Method = 4 * pow(2, Method); - //取出6个变换参数 - m_p00 = warp_mat.at(0, 0); - m_p01 = warp_mat.at(0, 1); - m_p02 = warp_mat.at(0, 2);//m_CatchMark1Oft.x;// + warp_mat = estimateAffinePartial2D(src, dest, tempMat, Method/*LMEDS*/); + warp_mat.convertTo(warp_mat, CV_32FC1);//不转化时,默认CV_64FC1 后续计算会错误 + + //取出6个变换参数 + m_p00 = warp_mat.at(0, 0); + m_p01 = warp_mat.at(0, 1); + m_p02 = warp_mat.at(0, 2); + + m_p10 = warp_mat.at(1, 0); + m_p11 = warp_mat.at(1, 1); + m_p12 = warp_mat.at(1, 2); - m_p10 = warp_mat.at(1, 0); - m_p11 = warp_mat.at(1, 1); - m_p12 = warp_mat.at(1, 2);//m_CatchMark1Oft.y;// + logstr.Format("刚性=====>偏移:[%.4f]~[%.4f]", m_p02, m_p12); + gLogMgr->WriteDebugLog(logstr); + logstr.Format("刚性=====>X参数:[ %.4f ]~[%.4f]", m_p00, m_p01); + gLogMgr->WriteDebugLog(logstr); + logstr.Format("刚性=====>Y参数:[ %.4f ]~[%.4f]", m_p10, m_p11); + gLogMgr->WriteDebugLog(logstr); + } } //计算真实数据的偏移和旋转值 void CProduct::CalTheoryToRealPar()