From 4114d380bd594385fa6f10bb36a9eef4d19e8db1 Mon Sep 17 00:00:00 2001
From: kojingeun <diteam.co.kr>
Date: 월, 05 6월 2023 23:33:58 +0900
Subject: [PATCH] Ongoing50 #4517 CF AOI Review 결과 파일 찾기 실패 개선 1. Find Bin File 찾는 Library 변경  - CRT _findfirsti64 / _findnexti64 -> C++17 Filesystem directory_iterator  - 파일 탐색 시간 20k Files(80GB) 1sec 소요

---
 ReviewSystem/ReviewSystem/CameraControlAlign.cpp |   62 ++++++++++++++++++++++++++++--
 1 files changed, 57 insertions(+), 5 deletions(-)

diff --git a/ReviewSystem/ReviewSystem/CameraControlAlign.cpp b/ReviewSystem/ReviewSystem/CameraControlAlign.cpp
index 2b4ac05..c9a8055 100644
--- a/ReviewSystem/ReviewSystem/CameraControlAlign.cpp
+++ b/ReviewSystem/ReviewSystem/CameraControlAlign.cpp
@@ -19,6 +19,8 @@
 	m_pVectorAlignLightControl = NULL;
 	m_nViewMode = 0;
 	m_strSaveImageBasePath = _T("");
+	m_strSaveImageOKPath = _T("");
+	m_strSaveImageNGPath = _T("");
 
 	m_nAlignType = FALSE;
 
@@ -444,6 +446,16 @@
 	m_strSaveImageBasePath = strPath;
 }
 
+void CCameraControlAlign::SetSaveImageOKPath(CString strPath)
+{
+	m_strSaveImageOKPath = strPath;
+}
+
+void CCameraControlAlign::SetSaveImageNGPath(CString strPath)
+{
+	m_strSaveImageNGPath = strPath;
+}
+
 CCameraControl* CCameraControlAlign::GetCameraControl(int nCameraIndex)
 {
 	for (VectorCameraControlIt it=m_vecCameraControl.begin(); it!=m_vecCameraControl.end(); it++)
@@ -657,10 +669,11 @@
 
 	
 	//SAlignFindResult findResult = pAlignFinder->FindAlign(pCameraImage->GetImageData(View_Matching), findParam, pCameraImage->GetImageData(View_Template));
+	//Main Align Matching
 	SAlignFindResult findResult = pAlignFinder->FindAlign(&camImage, findParam, pCameraImage->GetImageData(View_Template));
 	g_pLog->DisplayMessage(_T("Main TempleteMatching Result : %d Cam ResultCode = %d, PixelX = %d, PixelY = %d, MatchingRate = %.3lf"), nCameraIdx, findResult.nResultCode, int(findResult.dPosX + 0.5), int(findResult.dPosY + 0.5), findResult.dMatchValue);
 
-	// result process
+	//Main Align Matching result process
 	if (findResult.nResultCode==AlignMatch_Success)
 	{
 		/*< LYW 20211015 - #3671 ADD Start >*/
@@ -676,8 +689,10 @@
 
 	else
 	{
+		//Assistant Align Matching
 		SAlignFindResult findAssistantResult = pAlignFinder->FindAlign(&camImage, findParam, pCameraImage->GetImageData(View_AssistantTemplate));
 		g_pLog->DisplayMessage(_T("Assistant TempleteMatching Result : %d Cam ResultCode = %d, PixelX = %d, PixelY = %d, MatchingRate = %.3lf"), nCameraIdx, findAssistantResult.nResultCode, int(findAssistantResult.dPosX + 0.5), int(findAssistantResult.dPosY + 0.5), findAssistantResult.dMatchValue);
+		//Assistant Align Matching result process
 		if (findAssistantResult.nResultCode == AlignMatch_Success)
 		{
 			/*< LYW 20211015 - #3671 ADD Start >*/
@@ -692,15 +707,22 @@
 
 		else 
 		{
+			//Main, Assistant Find Pos Compare
 			int dffmain2assistanstX = int(findResult.dPosX) - int(findAssistantResult.dPosX);
 			int dffmain2assistanstY = int(findResult.dPosY) - int(findAssistantResult.dPosY);
 			g_pLog->DisplayMessage(_T("Main, Assistant TempleteMatching All Low Score! differenceX = %d, differenceY = %d"), dffmain2assistanstX, dffmain2assistanstY);
 
-			if (abs(dffmain2assistanstX) <= findParam.dMatchingPixelStandard && abs(dffmain2assistanstY) <= findParam.dMatchingPixelStandard && findResult.dMatchValue != 0.0)
+			if (abs(dffmain2assistanstX) <= findParam.dMatchingPixelStandard && abs(dffmain2assistanstY) <= findParam.dMatchingPixelStandard && findResult.dMatchValue != 0.0 && findAssistantResult.dMatchValue != 0.0)
 			{
+				//Main, Assistant Find Pos Compare Result Success Process
 				m_AlignResult.nFindAlign[nCameraIdx] = 1;
-				m_AlignResult.dFindPixelX[nCameraIdx] = int(findResult.dPosX + 0.5);
-				m_AlignResult.dFindPixelY[nCameraIdx] = int(findResult.dPosY + 0.5);
+				/*< LYW 20211015 - #3671 MOD Start >*/
+				m_AlignResult.dFindPixelX[nCameraIdx] = int((findResult.dPosX + findAssistantResult.dPosX) / 2 + 0.5);
+				m_AlignResult.dFindPixelY[nCameraIdx] = int((findResult.dPosY + findAssistantResult.dPosY) / 2 + 0.5);
+				/*< LYW 20211015 - #3671 MOD End >*/
+				/*< Origin Code >*/
+				//m_AlignResult.dFindPixelX[nCameraIdx] = int(findResult.dPosX + 0.5);
+				//m_AlignResult.dFindPixelY[nCameraIdx] = int(findResult.dPosY + 0.5);
 				m_AlignResult.dFindScore[nCameraIdx] = findResult.dMatchValue;
 				m_pACC2P->IACC2P_SetAccumaulate(m_pACC2P->IACC2P_GetAccumaulate() + 1);
 				g_pLog->DisplayMessage(_T("Main, Assistant Templete Find Same Point! Align Success! Accumaulate = %d"), m_pACC2P->IACC2P_GetAccumaulate());
@@ -708,6 +730,7 @@
 
 			else
 			{
+				//Main, Assistant Find Pos Compare Result Fail Process
 				g_pLog->DisplayMessage(_T("Main Assistant Templete Don`t Find Same Point! Align Fail!"));
 				m_AlignResult.nFindAlign[nCameraIdx] = 0;
 				m_AlignResult.dFindScore[nCameraIdx] = findResult.dMatchValue;
@@ -715,6 +738,7 @@
 
 			if (m_pACC2P->IACC2P_GetAccumaulate() >= findParam.dMatchingAlarmCondition)
 			{
+				//Main, Assistant Find Pos Alarm Process
 				m_AlignResult.nFindAlign[nCameraIdx] = 0;
 				m_AlignResult.dFindScore[nCameraIdx] = findResult.dMatchValue;
 				m_pACC2P->IACC2P_SetAccumaulate(0);
@@ -742,7 +766,8 @@
 		time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond());
 	pAlignFinder->SaveResultImage(strPath);
 
-	Sleep(10);
+	//< SWK 20221226 - #4403 DEL >
+//	Sleep(10);
 	if (nCameraIdx == 0)
 	{
 		m_AlignResult.strAlignFirest = strPath;
@@ -752,6 +777,33 @@
 		m_AlignResult.strAlignSecond = strPath;
 	}
 
+	if (m_AlignResult.nFindAlign[nCameraIdx] == 1)
+	{
+		CreateDirectory(m_strSaveImageOKPath, NULL);
+		// save threshold image
+		strPath.Format(_T("%s\\Cam%02d_Align_OK_TH_%04d%02d%02d%02d%02d%02d.jpg"), m_strSaveImageOKPath, nCameraIdx,
+			time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond());
+		pAlignFinder->SaveThresholdImage(strPath);
+
+		// save Result Image 20210208 �뼹�씪�씤 寃곌낵 ���옣
+		strPath.Format(_T("%s\\Cam%02d_AlignResultOK_%04d%02d%02d%02d%02d%02d.jpg"), m_strSaveImageOKPath, nCameraIdx,
+			time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond());
+		pAlignFinder->SaveResultImage(strPath);
+	}
+
+	else
+	{
+		CreateDirectory(m_strSaveImageNGPath, NULL);
+		// save threshold image
+		strPath.Format(_T("%s\\Cam%02d_Align_NG_TH_%04d%02d%02d%02d%02d%02d.jpg"), m_strSaveImageNGPath, nCameraIdx,
+			time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond());
+		pAlignFinder->SaveThresholdImage(strPath);
+
+		// save Result Image 20210208 �뼹�씪�씤 寃곌낵 ���옣
+		strPath.Format(_T("%s\\Cam%02d_AlignResultNG_%04d%02d%02d%02d%02d%02d.jpg"), m_strSaveImageNGPath, nCameraIdx,
+			time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond());
+		pAlignFinder->SaveResultImage(strPath);
+	}
 
 	// update matching image
 	pAlignFinder->GetBlobImage(pCameraImage->GetImageData(View_Matching));

--
Gitblit v1.9.3