#include "StdAfx.h"
|
#include "PostProcess.h"
|
#include "Config.h"
|
#include "FreeImage.h"
|
#include "Glass_Data.h"
|
#include "GlassRecipe.h"
|
#include "Transfer_Data.h"
|
#include "InspectCamera.h"
|
#include "EdgeInspector_AppView.h"
|
|
#include <ctime>
|
|
#define JPEG_RATE JPEG_QUALITYNORMAL|JPEG_OPTIMIZE
|
|
CPostProcess::CPostProcess(void)
|
{
|
m_pView = NULL;
|
InitPostProcessing();
|
}
|
|
CPostProcess::~CPostProcess(void)
|
{
|
}
|
|
void CPostProcess::SetInspectCamera(int iCam,CInspectCamera *pIns)
|
{
|
m_pInspectCamera[iCam] = pIns;
|
}
|
|
void CPostProcess::SetPrameter(CGlass_Data *pGlsData,CHardwareSettings *pHW,CGlassRecipe *pRecipe,CTransfer_Data *pTransData)
|
{
|
m_pGlassData = pGlsData;
|
m_pHardware = pHW;
|
m_pRecipe = pRecipe;
|
m_pTransData = pTransData;
|
}
|
|
void CPostProcess::WriteSetupData()
|
{
|
if(m_pView != NULL)
|
((CEdgeInspector_AppView*) m_pView)->SetupImageSave();
|
|
CString strSetupDataPath;
|
strSetupDataPath.Format(_T("D:\\Inspection\\Data\\SetupData.csv"));
|
|
CFile file_module;
|
CFileException file_exception;
|
|
file_module.Open(strSetupDataPath, CFile::modeCreate|CFile::modeWrite|CFile::modeNoTruncate|CFile::shareDenyWrite|CFile::shareDenyRead, &file_exception);
|
|
if(file_exception.m_cause == CFileException::none)
|
{
|
if(file_module.SeekToEnd() == 0L)
|
{
|
CString title;
|
title.Format(_T("Time, ID, Side, Find Start Line, Find End Line, Pre End Line, Top Mark X, Top Mark Y, Bot Mark X, Bot Mark Y\r\n"));
|
file_module.Write(title, title.GetLength()*sizeof(TCHAR));
|
}
|
|
CTime currentTime = CTime::GetCurrentTime();
|
|
g_pLog->DisplayMessage(_T("=========== Set-up Data (%d/%d/%d - %d:%d:%d)=============="),currentTime.GetYear(), currentTime.GetMonth(), currentTime.GetDay(), currentTime.GetHour(), currentTime.GetMinute(), currentTime.GetSecond());
|
|
for(int i=0; i<MAX_SIDE_COUNT; i++)
|
{
|
CSide_Data* pSideData = m_pGlassData->GetSideData((DimensionDir) i);
|
|
CString strData;
|
strData.Format(_T("%s, %s, %s, %d, %d, %d, %d, %d, %d, %d\r\n"), m_pGlassData->GetLoadingTimeString(), _T("Setup"), g_SideName[i], pSideData->m_nGlassStartLine, pSideData->m_nGlassEndLine, pSideData->m_nPreGlassEndLine, pSideData->m_ptTopMark_FindResult.x, pSideData->m_ptTopMark_FindResult.y, pSideData->m_ptBotMark_FindResult.x, pSideData->m_ptBotMark_FindResult.y);
|
file_module.Write(strData, strData.GetLength()*sizeof(TCHAR));
|
|
g_pLog->DisplayMessage(_T("%d. %s ===="), i+1, g_SideName[i]);
|
g_pLog->DisplayMessage(_T("Side[%s] Find Start Line - %d pixel"), g_SideName[i], pSideData->m_nGlassStartLine);
|
g_pLog->DisplayMessage(_T("Side[%s] Find End Line - %d pixel"), g_SideName[i], pSideData->m_nGlassEndLine);
|
g_pLog->DisplayMessage(_T("Side[%s] Find Pre End Line - %d pixel"), g_SideName[i], pSideData->m_nPreGlassEndLine);
|
g_pLog->DisplayMessage(_T("Side[%s] Top Align Mark - (%d, %d) pixel"), g_SideName[i], pSideData->m_ptTopMark_FindResult.x, pSideData->m_ptTopMark_FindResult.y);
|
g_pLog->DisplayMessage(_T("Side[%s] Bot Align Mark - (%d, %d) pixel"), g_SideName[i], pSideData->m_ptBotMark_FindResult.x, pSideData->m_ptBotMark_FindResult.y);
|
g_pLog->DisplayMessage(_T("==========="));
|
}
|
|
g_pLog->DisplayMessage(_T("=========== End Set-up Data (%d/%d/%d - %d:%d:%d)=============="),currentTime.GetYear(), currentTime.GetMonth(), currentTime.GetDay(), currentTime.GetHour(), currentTime.GetMinute(), currentTime.GetSecond());
|
|
file_module.Close();
|
}
|
}
|
|
BOOL CPostProcess::InitPostProcessing()
|
{
|
m_pGlassData = NULL;
|
m_pHardware = NULL;
|
m_pRecipe = NULL;
|
|
for(int i=0;i<MAX_CAMERA_COUNT;i++)
|
{
|
m_pInspectCamera[i] = NULL;
|
}
|
|
return TRUE;
|
}
|
|
BOOL CPostProcess::ProcessingScanEnd()
|
{
|
|
return TRUE;
|
}
|
|
BOOL CPostProcess::RunPostProcessing()
|
{
|
g_pLog->DisplayMessage(_T("Start RunPostProcessing - Defect Process"));
|
|
if(m_pGlassData == NULL)
|
{
|
g_pLog->DisplayMessage(_T("Glass Data is NULL"));
|
return FALSE;
|
}
|
|
CreateDataDirectory();
|
|
MergeDefect();
|
|
// WriteSetupData();
|
|
g_pLog->DisplayMessage(_T("Before - Total Defect Count : Tot %d, NG %d, OK %d"),m_pGlassData->GetTotalDefectCount(),m_pGlassData->GetDefectCount_NG(), m_pGlassData->GetDefectCount_OK());
|
|
PostDefectJudgeProcess();
|
|
g_pLog->DisplayMessage(_T("After - Total Defect Count : Tot %d, NG %d, OK %d"),m_pGlassData->GetTotalDefectCount(),m_pGlassData->GetDefectCount_NG(), m_pGlassData->GetDefectCount_OK());
|
|
#if MINI_LED
|
|
if(m_pGlassData->GetSimulation() == FALSE)
|
{
|
WriteDefectFile();
|
WriteMapFile();
|
WriteDataFile();
|
}
|
#endif
|
return TRUE;
|
}
|
|
BOOL CPostProcess::RunPostProcessing_SaveDefectInfo()
|
{
|
g_pLog->DisplayMessage(_T("Start RunPostProcessing - Save Defect Info Process"));
|
|
if(m_pGlassData == NULL)
|
{
|
g_pLog->DisplayMessage(_T("Glass Data is NULL"));
|
return FALSE;
|
}
|
|
// Save Defect Data..
|
SaveDefectData();
|
|
// Save Defect Image..
|
SaveDefectImageNG();
|
|
return TRUE;
|
}
|
|
BOOL CPostProcess::RunPostProcessing_SaveFiltImage()
|
{
|
g_pLog->DisplayMessage(_T("Start RunPostProcessing - Save Defect Info Process"));
|
|
if (m_pGlassData == NULL)
|
{
|
g_pLog->DisplayMessage(_T("Glass Data is NULL"));
|
return FALSE;
|
}
|
|
SaveDefectImageOK();
|
|
return TRUE;
|
}
|
|
void CPostProcess::SaveDefectData()
|
{
|
CString glass_id;
|
glass_id.Format(_T("%s"), g_pBase->m_strHPanelID);
|
|
if (glass_id.IsEmpty() == TRUE)
|
glass_id.Format(_T("MANUAL_ID"));
|
|
// 获取当前产品加载时间
|
CTime tGlassLoading = m_pGlassData->GetLoadingTime();
|
|
CString measure_data;
|
CString chip_data;
|
CString defect_data;
|
CString strTime = g_pBase->m_strLoadingTime;
|
|
double dTFTYOff = 0;
|
//double dSumTFTYOff = 0;
|
//int nCountTFTYOff = 0;
|
//for (int nFrameIdx = 0; nFrameIdx < MAX_IMAGE_FRAME; nFrameIdx++)
|
//{
|
// if (m_pGlassData->GetSideData(DIMENSION_B)->m_nSide_Electrode_Result_um[nFrameIdx] == -1) continue;
|
// dSumTFTYOff += m_pGlassData->GetSideData(DIMENSION_B)->m_nSide_Electrode_Result_um[nFrameIdx];
|
// nCountTFTYOff++;
|
//}
|
//if (nCountTFTYOff > 0)
|
// dTFTYOff = dSumTFTYOff / nCountTFTYOff;
|
|
double dTFTXOff = 0;
|
//double dSumTFTXOff = 0;
|
//int nCountTFTXOff = 0;
|
//for (int nFrameIdx = 0; nFrameIdx < MAX_IMAGE_FRAME; nFrameIdx++)
|
//{
|
// if (m_pGlassData->GetSideData(DIMENSION_A)->m_nSide_Electrode_Result_um[nFrameIdx] == -1) continue;
|
// dSumTFTXOff += m_pGlassData->GetSideData(DIMENSION_A)->m_nSide_Electrode_Result_um[nFrameIdx];
|
// nCountTFTXOff++;
|
//}
|
//if (nCountTFTXOff > 0)
|
// dTFTXOff = dSumTFTXOff / nCountTFTXOff;
|
|
double nPanelSizeCF_X = ((m_pGlassData->GetSideData(DIMENSION_B)->m_nGlassEndLine - m_pGlassData->GetSideData(DIMENSION_B)->m_nGlassStartLine) * m_pGlassData->GetSideData(DIMENSION_B)->m_dPixelSizeY / 1000.0);
|
double nPanelSizeCF_Y = ((m_pGlassData->GetSideData(DIMENSION_A)->m_nGlassEndLine - m_pGlassData->GetSideData(DIMENSION_A)->m_nGlassStartLine) * m_pGlassData->GetSideData(DIMENSION_A)->m_dPixelSizeY / 1000.0);
|
double nPanelSizeTFT_X = (((m_pGlassData->GetSideData(DIMENSION_B)->m_nGlassEndLine - m_pGlassData->GetSideData(DIMENSION_B)->m_nGlassStartLine) * m_pGlassData->GetSideData(DIMENSION_B)->m_dPixelSizeY - dTFTXOff) / 1000.0);
|
double nPanelSizeTFT_Y = (((m_pGlassData->GetSideData(DIMENSION_A)->m_nGlassEndLine - m_pGlassData->GetSideData(DIMENSION_A)->m_nGlassStartLine) * m_pGlassData->GetSideData(DIMENSION_A)->m_dPixelSizeY - dTFTYOff) / 1000.0);
|
|
measure_data.AppendFormat(_T("%s,%s,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%f,%f,%f,%f,%d,%d,%d,%d,%d,%d,%d,%d"),
|
strTime,
|
glass_id,
|
m_pTransData->m_nUnitNo,
|
m_pTransData->m_nEqpNo,
|
m_pTransData->m_nisGrind,
|
m_pTransData->m_nRoughPadLayer,
|
MeasrueCutLineResult(DIMENSION_A),
|
MeasrueCutLineResult(DIMENSION_B),
|
MeasrueCutLineResult(DIMENSION_C),
|
MeasrueCutLineResult(DIMENSION_D),
|
MeasrueCutLineResult(DIMENSION_A_DN),
|
MeasrueCutLineResult(DIMENSION_B_DN),
|
MeasrueCutLineResult(DIMENSION_C_DN),
|
MeasrueCutLineResult(DIMENSION_D_DN),
|
nPanelSizeCF_X,
|
nPanelSizeCF_Y,
|
nPanelSizeTFT_X,
|
nPanelSizeTFT_Y,
|
m_pGlassData->GetSideData(DIMENSION_A)->m_nTopCornerWidth,
|
m_pGlassData->GetSideData(DIMENSION_A)->m_nTopCornerHeight,
|
m_pGlassData->GetSideData(DIMENSION_A)->m_nBottomCornerWidth,
|
m_pGlassData->GetSideData(DIMENSION_A)->m_nBottomCornerHeight,
|
m_pGlassData->GetSideData(DIMENSION_C)->m_nTopCornerWidth,
|
m_pGlassData->GetSideData(DIMENSION_C)->m_nTopCornerHeight,
|
m_pGlassData->GetSideData(DIMENSION_C)->m_nBottomCornerWidth,
|
m_pGlassData->GetSideData(DIMENSION_C)->m_nBottomCornerHeight
|
);
|
measure_data.Append(_T("\r\n"));
|
|
CString measure_file_path;
|
if (m_pHardware->m_bSaveResultByHour) {
|
// 按小时保存结果
|
measure_file_path.Format(_T("%s\\%s_%02d_MeasureData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, tGlassLoading.GetHour());
|
}
|
else {
|
// 不按小时保存结果
|
measure_file_path.Format(_T("%s\\%s_MeasureData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay);
|
}
|
|
CheckDirectory(measure_file_path);
|
|
CFile measure_module;
|
CFileException measure_exception;
|
|
measure_module.Open(measure_file_path, CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate | CFile::shareDenyWrite | CFile::shareDenyRead, &measure_exception);
|
|
if (measure_exception.m_cause == CFileException::none)
|
{
|
if (measure_module.SeekToEnd() == 0L)
|
{
|
CString defect_title;
|
defect_title.Format(_T("Time,Glass ID,Unit_No,Table_No,Slot_No,Panel_count,AT_SizeAVG,BT_SizeAVG,CT_SizeAVG,DT_SizeAVG,AB_SizeAVG,BB_SizeAVG,CB_SizeAVG,DB_SizeAVG,CF_SizeX,CF_SizeY,TFT_SizeX,TFT_SizeY,AT_CorX,AT_CorY,AB_CorX,AB_CorY,CT_CorX,CT_CorY,CB_CorX,CB_CorY\r\n"));
|
measure_module.Write(defect_title, defect_title.GetLength() * sizeof(TCHAR));
|
}
|
measure_module.Write(measure_data, measure_data.GetLength() * sizeof(TCHAR));
|
measure_module.Close();
|
}
|
|
{
|
MapDefectIt it;
|
MapDefect* pMapDefect = m_pGlassData->GetMapDefect_OK();
|
|
for (it = pMapDefect->begin(); it != pMapDefect->end(); it++)
|
{
|
CDefect* pDefect = static_cast<CDefect*>(it->second);
|
|
if (pDefect == NULL)
|
continue;
|
|
if (pDefect->m_bJudge_NG == TRUE)
|
continue;
|
|
CString strDefectType = g_strDefectType[pDefect->m_DefectInfo.m_DefectLoc];
|
if ((strDefectType.Compare(_T("Chip")) == 0 || strDefectType.Compare(_T("In_Chip")) == 0))
|
{
|
// 获取当前时间
|
std::time_t now = std::time(nullptr);
|
// 使用localtime_s代替localtime
|
std::tm nowTm;
|
localtime_s(&nowTm, &now);
|
|
CString strDate;
|
strDate.Format(_T("%04d%02d%02d%02d%02d%02d"),
|
nowTm.tm_year + 1900, nowTm.tm_mon + 1, nowTm.tm_mday, nowTm.tm_hour, nowTm.tm_min, nowTm.tm_sec);
|
|
CString strCLCS;
|
m_pGlassData->DecodeDefectPose(&(pDefect->m_DefectInfo), strCLCS);
|
|
#if HALCON_VISION_KEY
|
Point2I pos2I = BlVision_GetSoftVisionApp()->getPose(pDefect->m_DefectInfo.m_nSideIdx, pDefect->m_DefectInfo.m_ptDefectPos_pxl.x, pDefect->m_DefectInfo.m_ptDefectPos_pxl.y);
|
#else
|
CPoint pos2I = m_pGlassData->TransformToGlobal((DimensionDir)pDefect->m_DefectInfo.m_nSideIdx, pDefect->m_DefectInfo.m_ptDefectPos_pxl);
|
#endif // HALCON_VISION_KEY
|
|
int nMinSize_X = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[(int)pDefect->m_DefectInfo.m_DefectLoc].m_nMinSize_Filter_X_um;
|
int nMinSize_Y = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[(int)pDefect->m_DefectInfo.m_DefectLoc].m_nMinSize_Filter_Y_um;;
|
|
if (static_cast<int>(round(pDefect->m_dSizeX_um)) > nMinSize_X && static_cast<int>(round(pDefect->m_dSizeY_um)) > nMinSize_Y)
|
{
|
chip_data.AppendFormat(_T("%s,%s,%s,%s,%s,%s,%s,%f,%f,%d,%d"),
|
strDate,
|
glass_id,
|
g_pBase->m_strRecipeName,
|
g_pBase->m_strSBKLine,
|
PANEL_SIDE[pDefect->m_DefectInfo.m_nSideIdx],
|
strCLCS,
|
pDefect->m_DefectInfo.m_nSideIdx >= 0 && pDefect->m_DefectInfo.m_nSideIdx < 4 ? _T("CF") : _T("TFT"),
|
pDefect->m_dSizeY_um,
|
pDefect->m_dSizeX_um,
|
std::abs(pos2I.x),
|
std::abs(pos2I.y));
|
chip_data.Append(_T("\r\n"));
|
}
|
}
|
}
|
}
|
|
{
|
MapDefectIt it;
|
MapDefect* pMapDefect = m_pGlassData->GetMapDefect_NG();
|
|
for (it = pMapDefect->begin(); it != pMapDefect->end(); it++)
|
{
|
CDefect* pDefect = static_cast<CDefect*>(it->second);
|
|
if (pDefect == NULL)
|
continue;
|
|
if (pDefect->m_bJudge_NG == FALSE)
|
continue;
|
|
CString strDefectType = g_strDefectType[pDefect->m_DefectInfo.m_DefectLoc];
|
|
CString strEqip, strUnit;
|
|
CTransfer_Data* pTrans = m_pTransData;
|
if (pTrans != NULL)
|
{
|
strEqip.Format(_T("%d"), pTrans->m_nEqpNo);
|
strUnit.Format(_T("%d"), pTrans->m_nUnitNo);
|
}
|
else
|
{
|
strEqip.Format(_T("%d"), 0);
|
strUnit.Format(_T("%d"), 0);
|
}
|
|
defect_data.AppendFormat(_T("%s,%s,%s,%s,%s,%s,%f,%f,%s"),
|
strTime,
|
glass_id,
|
strEqip,
|
strUnit,
|
PANEL_SIDE[pDefect->m_DefectInfo.m_nSideIdx],
|
strDefectType,
|
pDefect->m_dSizeX_um,
|
pDefect->m_dSizeY_um,
|
pDefect->m_strSaveImagePath);
|
defect_data.Append(_T("\r\n"));
|
|
if ((strDefectType.Compare(_T("Chip")) == 0 || strDefectType.Compare(_T("In_Chip")) == 0))
|
{
|
// 获取当前时间
|
std::time_t now = std::time(nullptr);
|
// 使用localtime_s代替localtime
|
std::tm nowTm;
|
localtime_s(&nowTm, &now);
|
|
CString strDate;
|
strDate.Format(_T("%04d%02d%02d%02d%02d%02d"),
|
nowTm.tm_year + 1900, nowTm.tm_mon + 1, nowTm.tm_mday, nowTm.tm_hour, nowTm.tm_min, nowTm.tm_sec);
|
|
CString strCLCS;
|
m_pGlassData->DecodeDefectPose(&(pDefect->m_DefectInfo), strCLCS);
|
CPoint pos2I = m_pGlassData->TransformToGlobal((DimensionDir)pDefect->m_DefectInfo.m_nSideIdx, pDefect->m_DefectInfo.m_ptDefectPos_pxl);
|
|
chip_data.AppendFormat(_T("%s,%s,%s,%s,%s,%s,%s,%f,%f,%d,%d"),
|
strDate,
|
glass_id,
|
g_pBase->m_strRecipeName,
|
g_pBase->m_strSBKLine,
|
PANEL_SIDE[pDefect->m_DefectInfo.m_nSideIdx],
|
strCLCS,
|
pDefect->m_DefectInfo.m_nSideIdx >= 0 && pDefect->m_DefectInfo.m_nSideIdx < 4 ? _T("CF") : _T("TFT"),
|
pDefect->m_dSizeY_um,
|
pDefect->m_dSizeX_um,
|
std::abs(pos2I.y),
|
std::abs(pos2I.x));
|
chip_data.Append(_T("\r\n"));
|
}
|
}
|
}
|
|
CString Chip_file_path;
|
if (m_pHardware->m_bSaveResultByHour) {
|
// 按小时保存结果
|
Chip_file_path.Format(_T("%s\\%s_%02d_ChipData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, tGlassLoading.GetHour());
|
}
|
else {
|
// 不按小时保存结果
|
Chip_file_path.Format(_T("%s\\%s_ChipData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay);
|
}
|
|
CheckDirectory(Chip_file_path);
|
|
CFile chip_module;
|
CFileException chip_exception;
|
|
chip_module.Open(Chip_file_path, CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate | CFile::shareDenyWrite | CFile::shareDenyRead, &chip_exception);
|
|
if (chip_exception.m_cause == CFileException::none)
|
{
|
if (chip_module.SeekToEnd() == 0L)
|
{
|
CString defect_title;
|
defect_title.Format(_T("Date,GlassID,Model,SBK Line,Side,C-L/C-S,TFT/CF,Length,Depth,PosX,PosY\r\n"));
|
chip_module.Write(defect_title, defect_title.GetLength() * sizeof(TCHAR));
|
}
|
chip_module.Write(chip_data, chip_data.GetLength() * sizeof(TCHAR));
|
chip_module.Close();
|
}
|
|
CString Defect_file_path;
|
if (m_pHardware->m_bSaveResultByHour) {
|
// 按小时保存结果
|
Defect_file_path.Format(_T("%s\\%s_%02d_DefectData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay, tGlassLoading.GetHour());
|
}
|
else {
|
// 不按小时保存结果
|
Defect_file_path.Format(_T("%s\\%s_DefectData.csv"), m_strResultFolder, g_pBase->m_strLoadingDay);
|
}
|
|
CheckDirectory(Defect_file_path);
|
|
CFile defect_module;
|
CFileException defect_exception;
|
|
defect_module.Open(Defect_file_path, CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate | CFile::shareDenyWrite | CFile::shareDenyRead, &defect_exception);
|
|
if (defect_exception.m_cause == CFileException::none)
|
{
|
if (defect_module.SeekToEnd() == 0L)
|
{
|
CString defect_title;
|
defect_title.Format(_T("TIME,ID,EQP NO,UNIT NO,SIDE,LOCATION,SIZE_X,SIZE_Y,IMAGE_PATH\r\n"));
|
defect_module.Write(defect_title, defect_title.GetLength()*sizeof(TCHAR));
|
}
|
defect_module.Write(defect_data, defect_data.GetLength()*sizeof(TCHAR));
|
defect_module.Close();
|
}
|
}
|
|
void CPostProcess::JudgementData()
|
{
|
if(m_pGlassData == NULL)
|
return;
|
|
/*
|
PROFILECHAMFER_RESULT_DATA *pResult = m_pGlassData->GetProfileInspectData();
|
PROFILE_RESULT *pProfileRes;
|
int index;
|
|
for(index=0;index<MAX_PROFILE_SETTING_COUNT;index++)
|
{
|
pProfileRes = &pResult->ProfileData[index];
|
|
pProfileRes->bProfileJudge = TRUE;
|
if(pProfileRes->bUseJudge == TRUE)
|
{
|
if(pProfileRes->nProfileDiff < -1*pProfileRes->nJudgeMinus || pProfileRes->nProfileDiff > pProfileRes->nJudgePlus)
|
{
|
pProfileRes->bProfileJudge = FALSE;
|
}
|
}
|
|
for(int i=0;i<2;i++)
|
{
|
CHAMFER_RESULT *pChamferRes = &pResult->ResultChamfer[index][i];
|
pChamferRes->bChamferJudge = TRUE;
|
if(pChamferRes->bUseJudge == TRUE)
|
{
|
if(pChamferRes->nChamferThick < pChamferRes->nJudgeReference - pChamferRes->nJudgeMinusChamfer || pChamferRes->nChamferThick > pChamferRes->nJudgeReference+pChamferRes->nJudgePlusChamfer)
|
{
|
pChamferRes->bChamferJudge = FALSE;
|
//InsertManualDefect(pInspect,m_pHardware->GetCameraSettings(pProfileRes->iCam,pProfileRes->iScan),pProfileRes->iScan,pProfileRes->ptGlassStart.x,pProfileRes->ptGlassStart.y,DefectLoc_Chamfer);
|
}
|
}
|
}
|
}
|
*/
|
}
|
|
BOOL CPostProcess::SaveDefectImage(LPBYTE pImage,CSize szImage,CRect rectDefect,CString strFile,DimensionDir emDir)
|
{
|
if (pImage == NULL || szImage.cx <= 0 || szImage.cy <= 0) {
|
g_pLog->DisplayMessage(_T("Invalid image data or size"));
|
return FALSE;
|
}
|
|
Lock();
|
FIBITMAP* bitmap = FreeImage_Allocate(szImage.cx, szImage.cy, 8);
|
if (bitmap == NULL) {
|
g_pLog->DisplayMessage(_T("FreeImage_Allocate failed"));
|
Unlock();
|
return FALSE;
|
}
|
|
BYTE* pBitBuffer = FreeImage_GetBits(bitmap);
|
if(pBitBuffer == NULL) {
|
FreeImage_Unload(bitmap);
|
Unlock();
|
return FALSE;
|
}
|
|
CopyMemory(pBitBuffer, pImage, szImage.cx * szImage.cy);
|
|
FIBITMAP *pBit24 = FreeImage_ConvertTo24Bits(bitmap);
|
if (pBit24 == NULL) {
|
Unlock();
|
return FALSE;
|
}
|
|
char cFilePath[255];
|
|
#ifdef _UNICODE
|
int nSize = WideCharToMultiByte(CP_ACP, 0, strFile.GetBuffer(), -1, NULL, 0, NULL,NULL);
|
WideCharToMultiByte(CP_ACP, 0, strFile.GetBuffer(), -1, cFilePath, nSize, NULL, NULL);
|
#else
|
sprintf_s(cFilePath,sizeof(char)*255,_T("%s"),(LPSTR)(LPCTSTR)strFile);
|
#endif
|
|
FreeImage_FlipVertical(pBit24);
|
FreeImage_Save(FIF_JPEG, pBit24, cFilePath,JPEG_RATE);
|
FreeImage_Unload(bitmap);
|
FreeImage_Unload(pBit24);
|
|
Unlock();
|
|
return TRUE;
|
}
|
|
BOOL CPostProcess::SaveDefectImageModern(LPBYTE pImage,CSize szImage,CRect rectDefect,CString strFile)
|
{
|
if (!pImage || szImage.cx <= 0 || szImage.cy <= 0) {
|
return FALSE;
|
}
|
|
#if 0
|
IplImage* pImageTmp = cvCreateImage(cvSize(szImage.cx, szImage.cy), 8, 1);
|
cvZero(pImageTmp);
|
|
// add point to the image
|
for (int i = 0; i < szImage.cy; i++) {
|
for (int j = 0; j < szImage.cx; j++) {
|
pImageTmp->imageData[i * pImageTmp->widthStep + j] = pImage[i * szImage.cx + j];
|
}
|
}
|
|
IplImage* pColorImg = cvCreateImage(cvSize(szImage.cx, szImage.cy), 8, 3);
|
cvZero(pColorImg);
|
|
cvCvtColor(pImageTmp, pColorImg, CV_GRAY2BGR);
|
cvRectangle(pColorImg, CvPoint(rectDefect.left, rectDefect.top), CvPoint(rectDefect.left + rectDefect.Width(), rectDefect.top + rectDefect.Height()), cvScalar(0, 0, 255), 1);
|
|
USES_CONVERSION;
|
char str_filename[1024];
|
sprintf_s(str_filename, "%s", W2A(strFile));
|
cvSaveImage(str_filename, pColorImg);
|
|
cvReleaseImage(&pColorImg);
|
cvReleaseImage(&pImageTmp);
|
#else
|
Lock();
|
cv::Mat grayImg(szImage.cy, szImage.cx, CV_8UC1, pImage);
|
cv::Mat colorImg;
|
cv::cvtColor(grayImg, colorImg, cv::COLOR_GRAY2BGR);
|
|
cv::rectangle(
|
colorImg,
|
cv::Rect(rectDefect.left, rectDefect.top, rectDefect.Width(), rectDefect.Height()),
|
cv::Scalar(0, 0, 255),
|
1
|
);
|
|
USES_CONVERSION;
|
std::string strFilename = W2A(strFile);
|
|
if (!cv::imwrite(strFilename, colorImg)) {
|
Unlock();
|
g_pLog->DisplayMessage(_T("Failed to save image to %s"), strFile);
|
return FALSE;
|
}
|
Unlock();
|
#endif // 0
|
|
return TRUE;
|
}
|
|
BOOL CPostProcess::SaveDefectImage_with_Title(CDefect* pDefect, CSize szImage,CRect rectDefect,CString strFile, CvScalar color)
|
{
|
if (pDefect == NULL || pDefect->m_Image == NULL) {
|
g_pLog->DisplayMessage(_T("Invalid defect data or image"));
|
return FALSE;
|
}
|
|
if (szImage.cx <= 0 || szImage.cy <= 0) {
|
g_pLog->DisplayMessage(_T("Invalid image size: %d x %d"), szImage.cx, szImage.cy);
|
return FALSE;
|
}
|
|
BOOL bSuccess = TRUE;
|
|
Lock();
|
// 标题文本
|
CString strTitle;
|
int nSideIdx = (0 <= pDefect->m_DefectInfo.m_nSideIdx && pDefect->m_DefectInfo.m_nSideIdx < MAX_SIDE_COUNT) ? pDefect->m_DefectInfo.m_nSideIdx : MAX_SIDE_COUNT;
|
int nCategoryIdx = (0 <= pDefect->m_DefectInfo.m_DefectLoc && pDefect->m_DefectInfo.m_DefectLoc < DefectLoc_None) ? pDefect->m_DefectInfo.m_DefectLoc : DefectLoc_Unknown;
|
|
DefectLocation eCategory = pDefect->m_DefectInfo.m_DefectLoc;
|
if (eCategory == DefectLoc_Notch_Dimension || eCategory == DefectLoc_Notch_Chamfer) {
|
strTitle.Format(_T("SIDE[%s] CAT[%s] SIZE[%d,%d] distance[%d,%d] "), g_SideName[nSideIdx], g_strDefectType[nCategoryIdx], (int)pDefect->m_dSizeX_um, (int)pDefect->m_dSizeY_um, (int)pDefect->m_dChamfer_um, (int)pDefect->m_dChamferOff_um);
|
}
|
else {
|
strTitle.Format(_T("SIDE[%s] CAT[%s] SIZE[%d,%d]"), g_SideName[nSideIdx], g_strDefectType[nCategoryIdx], (int)pDefect->m_dSizeX_um, (int)pDefect->m_dSizeY_um);
|
}
|
Unlock();
|
|
try {
|
Lock();
|
cv::Mat imgTmp(szImage.cy, szImage.cx, CV_8UC1, pDefect->m_Image);
|
cv::Mat colorImg(szImage.cy, szImage.cx, CV_8UC3);
|
cv::cvtColor(imgTmp, colorImg, cv::COLOR_GRAY2BGR);
|
|
cv::rectangle(colorImg, cv::Point(rectDefect.left, rectDefect.top), cv::Point(rectDefect.right, rectDefect.bottom), color, 1);
|
cv::rectangle(colorImg, cv::Point(0, szImage.cy - 40), cv::Point(szImage.cx, szImage.cy), cv::Scalar(0, 0, 0), cv::FILLED);
|
|
int fontFace = cv::FONT_HERSHEY_TRIPLEX;
|
double fontScale = 0.7;
|
int thickness = 1;
|
|
if (m_pHardware->m_bUse_SaveDLDefectImage==TRUE)
|
{
|
if (eCategory== DefectLoc_Chip|| eCategory== DefectLoc_Crack|| eCategory == DefectLoc_Burr|| eCategory == DefectLoc_In_Chip|| eCategory == DefectLoc_In_Burr|| eCategory == DefectLoc_UserDefect)
|
{
|
CT2CA pszConvertedAnsiDLFile(strDLFile);
|
cv::String strDLFile(pszConvertedAnsiDLFile);
|
cv::imwrite(strDLFile, imgTmp);
|
}
|
}
|
|
CT2CA pszConvertedAnsiTitle(strTitle);
|
cv::String strCVTitle(pszConvertedAnsiTitle);
|
cv::putText(colorImg, strCVTitle, cv::Point(10, szImage.cy - 10), fontFace, fontScale, CV_RGB(255, 255, 255), thickness);
|
|
CT2CA pszConvertedAnsiFile(strFile);
|
cv::String strStdFile(pszConvertedAnsiFile);
|
cv::imwrite(strStdFile, colorImg);
|
Unlock();
|
}
|
catch (cv::Exception& e) {
|
bSuccess = FALSE;
|
Unlock();
|
g_pLog->DisplayMessage(_T("OpenCV Exception: %s"), e.what());
|
}
|
return bSuccess;
|
|
#if 0
|
IplImage *pImageTmp = cvCreateImage(cvSize(szImage.cx, szImage.cy), 8,1);
|
cvZero(pImageTmp);
|
|
// add point to the image
|
for (int i = 0; i<szImage.cy; i++)
|
{
|
for (int j = 0; j<szImage.cx; j++)
|
{
|
pImageTmp->imageData[i*pImageTmp->widthStep+j] = pDefect->m_Image[i*szImage.cx+j];
|
}
|
}
|
|
IplImage *pColorImg = cvCreateImage(cvSize(szImage.cx, szImage.cy), 8, 3);
|
cvZero(pColorImg);
|
|
cvCvtColor(pImageTmp, pColorImg, CV_GRAY2BGR);
|
|
cvRectangle(pColorImg,CvPoint(rectDefect.left,rectDefect.top), CvPoint(rectDefect.left+rectDefect.Width(),rectDefect.top+rectDefect.Height()), color, 1);
|
|
// Title
|
// 1. Draw BackGround
|
cvRectangle(pColorImg,CvPoint(0, szImage.cy-40), CvPoint(szImage.cx, szImage.cy), cvScalar(0,0,0), CV_FILLED);
|
|
USES_CONVERSION;
|
|
// 2. Draw Title Text..
|
CvFont font;
|
cvInitFont(&font, CV_FONT_HERSHEY_TRIPLEX, 0.7, 0.7, 0, 1);
|
|
CString strTitle;
|
int nSideIdx = (0 <= pDefect->m_DefectInfo.m_nSideIdx && pDefect->m_DefectInfo.m_nSideIdx < MAX_SIDE_COUNT) ? pDefect->m_DefectInfo.m_nSideIdx : MAX_SIDE_COUNT;
|
int nCategoryIdx = (0 <= pDefect->m_DefectInfo.m_DefectLoc && pDefect->m_DefectInfo.m_DefectLoc < DefectLoc_None) ? pDefect->m_DefectInfo.m_DefectLoc : DefectLoc_Unknown;
|
|
strTitle.Format(_T("SIDE[%s] CAT[%s] SIZE[%d,%d]"), g_SideName[nSideIdx], g_strDefectType[nCategoryIdx], (int) pDefect->m_dSizeX_um, (int) pDefect->m_dSizeY_um);
|
cvPutText(pColorImg, W2A(strTitle), CvPoint(10, szImage.cy-10), &font, CV_RGB(255,255,255));
|
|
char str_filename[1024];
|
sprintf_s(str_filename, "%s", W2A(strFile));
|
cvSaveImage(str_filename, pColorImg);
|
|
cvReleaseImage(&pColorImg);
|
cvReleaseImage(&pImageTmp);
|
|
return TRUE;
|
#endif
|
}
|
|
void CPostProcess::WriteDefectFile()
|
{
|
g_pLog->DisplayMessage(_T("[Start Defect File...]"));
|
|
CTime tLoadingTime = m_pGlassData->GetLoadingTime();
|
CString strLoadingTime = tLoadingTime.Format(_T("%Y%m%d%H%M%S"));
|
|
CString strDefectFilePath;
|
strDefectFilePath.Format(_T("D:\\Defect\\%s\\%s\\%04d\\%02d\\%02d\\%s_%s_%s\\"), m_pHardware->GetMachineName(), m_pHardware->GetLineID()
|
, tLoadingTime.GetYear(),tLoadingTime.GetMonth(),tLoadingTime.GetDay()
|
, m_pGlassData->GetGlassRecipe()->GetRecipeName(), g_pBase->m_strHPanelID, strLoadingTime);
|
|
CheckDirectory(strDefectFilePath);
|
|
strDefectFilePath.Format(_T("D:\\Defect\\%s\\%s\\%04d\\%02d\\%02d\\%s_%s_%s.csv"), m_pHardware->GetMachineName(), m_pHardware->GetLineID()
|
, tLoadingTime.GetYear(),tLoadingTime.GetMonth(),tLoadingTime.GetDay()
|
, m_pGlassData->GetGlassRecipe()->GetRecipeName(), g_pBase->m_strHPanelID, strLoadingTime);
|
|
CString strTemp;
|
std::vector<CString> vecStrTitle;
|
std::vector<CString> vecStrResultData[MAX_DEFECT_COUNT_GLASS];
|
|
CString strPanelID = g_pBase->m_strHPanelID;
|
|
// Title
|
vecStrTitle.push_back(_T("TIME"));
|
vecStrTitle.push_back(_T("PANEL_ID"));
|
vecStrTitle.push_back(_T("SIDE"));
|
vecStrTitle.push_back(_T("TYPE"));
|
vecStrTitle.push_back(_T("SIZE_X"));
|
vecStrTitle.push_back(_T("SIZE_Y"));
|
vecStrTitle.push_back(_T("IMG_PATH"));
|
|
MapDefectIt it;
|
MapDefect* pMapDefect = m_pGlassData->GetMapDefect_NG();
|
|
if(pMapDefect == NULL)
|
return;
|
|
int nDefectCount = 0;
|
|
CString strSideName[MAX_SIDE_COUNT] = {_T("A_UP"),_T("B_UP"),_T("C_UP"),_T("D_UP"),_T("A_DN"),_T("B_DN"),_T("C_DN"),_T("D_DN")};
|
|
for(it=pMapDefect->begin();it!=pMapDefect->end();it++)
|
{
|
CDefect* pDefect = static_cast<CDefect*>(it->second);
|
|
if(pDefect == NULL)
|
continue;
|
|
// 1. Time
|
vecStrResultData[nDefectCount].push_back(strLoadingTime);
|
|
// 2. PANEL ID
|
vecStrResultData[nDefectCount].push_back(strPanelID);
|
|
// 3. SIDE
|
vecStrResultData[nDefectCount].push_back(strSideName[pDefect->m_DefectInfo.m_nSideIdx]);
|
|
// 4. TYPE
|
vecStrResultData[nDefectCount].push_back(g_strDefectType[(int) pDefect->m_DefectInfo.m_DefectLoc]);
|
|
// 5. SIZE X
|
strTemp.Format(_T("%.3f"), pDefect->m_dSizeX_um);
|
vecStrResultData[nDefectCount].push_back(strTemp);
|
|
// 6. SIZE Y
|
strTemp.Format(_T("%.3f"), pDefect->m_dSizeY_um);
|
vecStrResultData[nDefectCount].push_back(strTemp);
|
|
// 7. Image Path
|
CString strSaveImagePath;
|
strSaveImagePath.Format(_T("D:\\Inspection\\Defect\\Inspection\\%s\\%s\\%04d\\%02d\\%02d\\%s_%s_%s\\L1_%d.png"), m_pHardware->GetMachineName(), m_pHardware->GetLineID()
|
, tLoadingTime.GetYear(),tLoadingTime.GetMonth(),tLoadingTime.GetDay()
|
, m_pGlassData->GetGlassRecipe()->GetRecipeName(), g_pBase->m_strHPanelID, tLoadingTime.Format(_T("%Y%m%d%H%M%S")), nDefectCount+1);
|
|
CRect rectDefect;
|
rectDefect.left = DEFECTIMAGE_WIDTH/2 - pDefect->m_DefectInfo.m_rtDefectPos_pxl.Width()/2;
|
rectDefect.right = DEFECTIMAGE_WIDTH/2 + pDefect->m_DefectInfo.m_rtDefectPos_pxl.Width()/2;
|
rectDefect.top = DEFECTIMAGE_HEIGHT/2 - pDefect->m_DefectInfo.m_rtDefectPos_pxl.Height()/2;
|
rectDefect.bottom = DEFECTIMAGE_HEIGHT/2 + pDefect->m_DefectInfo.m_rtDefectPos_pxl.Height()/2;
|
|
SaveDefectImage_with_Title(pDefect, CSize(DEFECTIMAGE_WIDTH,DEFECTIMAGE_HEIGHT), rectDefect, strSaveImagePath);
|
|
vecStrResultData[nDefectCount].push_back(strSaveImagePath);
|
|
nDefectCount++;
|
}
|
|
g_pLog->DisplayMessage(_T("End of Save Defect Image NG.."));
|
|
|
CFile _File;
|
CFileException _Exception;
|
_File.Open(strDefectFilePath, CFile::modeCreate|CFile::modeWrite|CFile::modeNoTruncate|CFile::shareDenyWrite|CFile::shareDenyRead, &_Exception);
|
|
if(_Exception.m_cause == CFileException::none)
|
{
|
USES_CONVERSION;
|
int nBufferSize = vecStrTitle.size() * 255 * (nDefectCount + 1);
|
char* strBuffer = new char[nBufferSize];
|
int nBufferIdx = 0;
|
|
if(_File.SeekToEnd() == 0L)
|
{
|
ZeroMemory(strBuffer, sizeof(nBufferSize));
|
|
for(int i=0; i<vecStrTitle.size()-1; i++)
|
{
|
sprintf(&strBuffer[nBufferIdx], "%s,", W2A(vecStrTitle[i]));
|
nBufferIdx += vecStrTitle[i].GetLength() + 1;
|
}
|
|
sprintf(&strBuffer[nBufferIdx], "%s\r\n", W2A(vecStrTitle[vecStrTitle.size()-1]));
|
nBufferIdx += vecStrTitle[vecStrTitle.size()-1].GetLength() + 2;
|
|
_File.Write(strBuffer, nBufferIdx);
|
}
|
|
ZeroMemory(strBuffer, sizeof(nBufferSize));
|
nBufferIdx = 0;
|
|
for(int nDefectIdx = 0; nDefectIdx < nDefectCount; nDefectIdx++)
|
{
|
std::vector<CString>* pVecResult = &vecStrResultData[nDefectIdx];
|
|
if(pVecResult == NULL)
|
continue;
|
|
for(int i=0; i<pVecResult->size()-1; i++)
|
{
|
sprintf(&strBuffer[nBufferIdx], "%s,", W2A((*pVecResult)[i]));
|
nBufferIdx += (*pVecResult)[i].GetLength() + 1;
|
}
|
|
sprintf(&strBuffer[nBufferIdx], "%s\r\n", W2A((*pVecResult)[pVecResult->size()-1]));
|
nBufferIdx += (*pVecResult)[pVecResult->size()-1].GetLength() + 2;
|
}
|
|
_File.Write(strBuffer, nBufferIdx);
|
|
delete [] strBuffer;
|
}
|
_File.Close();
|
|
g_pLog->DisplayMessage(_T("[End Data File...] %s"), strDefectFilePath);
|
|
}
|
|
void CPostProcess::WriteMapFile()
|
{
|
|
}
|
|
void CPostProcess::WriteDataFile()
|
{
|
g_pLog->DisplayMessage(_T("[Start Data File...]"));
|
|
CString strTemp;
|
std::vector<CString> vecStrTitle;
|
std::vector<CString> vecStrResultData;
|
|
// 1. Loading Time
|
CTime tLoadingTime = m_pGlassData->GetLoadingTime();
|
strTemp = tLoadingTime.Format(_T("%Y%m%d%H%M%S"));
|
vecStrTitle.push_back(_T("TIME"));
|
vecStrResultData.push_back(strTemp);
|
|
// 2. Panel ID
|
vecStrTitle.push_back(_T("PANEL_ID"));
|
vecStrResultData.push_back(g_pBase->m_strHPanelID);
|
|
DimensionDir arryWriteOrder_UP[MAX_PANEL_SIDE] = {DIMENSION_A, DIMENSION_B, DIMENSION_C, DIMENSION_D};
|
DimensionDir arryWriteOrder_DN[MAX_PANEL_SIDE] = {DIMENSION_A_DN, DIMENSION_B_DN, DIMENSION_C_DN, DIMENSION_D_DN};
|
CString arrStrSideName[MAX_PANEL_SIDE] = {_T("A"), _T("B"), _T("C"), _T("D")};
|
|
// 3. Corner
|
|
|
// A 惑何 官蹿
|
vecStrTitle.push_back(_T("CORNER_1_X"));
|
strTemp.Format(_T("%d"), m_pGlassData->GetSideData(DIMENSION_A)->m_nBottomCornerWidth);
|
vecStrResultData.push_back(strTemp);
|
vecStrTitle.push_back(_T("CORNER_1_Y"));
|
strTemp.Format(_T("%d"), m_pGlassData->GetSideData(DIMENSION_A)->m_nBottomCornerHeight);
|
vecStrResultData.push_back(strTemp);
|
|
// C 惑何 官蹿
|
vecStrTitle.push_back(_T("CORNER_2_X"));
|
strTemp.Format(_T("%d"), m_pGlassData->GetSideData(DIMENSION_C)->m_nBottomCornerWidth);
|
vecStrResultData.push_back(strTemp);
|
vecStrTitle.push_back(_T("CORNER_2_Y"));
|
strTemp.Format(_T("%d"), m_pGlassData->GetSideData(DIMENSION_C)->m_nBottomCornerHeight);
|
vecStrResultData.push_back(strTemp);
|
|
// C 惑何 啪
|
vecStrTitle.push_back(_T("CORNER_3_X"));
|
strTemp.Format(_T("%d"), m_pGlassData->GetSideData(DIMENSION_C)->m_nTopCornerWidth);
|
vecStrResultData.push_back(strTemp);
|
vecStrTitle.push_back(_T("CORNER_3_Y"));
|
strTemp.Format(_T("%d"), m_pGlassData->GetSideData(DIMENSION_C)->m_nTopCornerHeight);
|
vecStrResultData.push_back(strTemp);
|
|
// A 惑何 啪
|
vecStrTitle.push_back(_T("CORNER_4_X"));
|
strTemp.Format(_T("%d"), m_pGlassData->GetSideData(DIMENSION_A)->m_nTopCornerWidth);
|
vecStrResultData.push_back(strTemp);
|
vecStrTitle.push_back(_T("CORNER_4_Y"));
|
strTemp.Format(_T("%d"), m_pGlassData->GetSideData(DIMENSION_A)->m_nTopCornerHeight);
|
vecStrResultData.push_back(strTemp);
|
|
// 4. Side Result
|
for(int nSideIdx=0; nSideIdx<MAX_PANEL_SIDE; nSideIdx++)
|
{
|
CSide_Data* pSideData_UP = m_pGlassData->GetSideData(arryWriteOrder_UP[nSideIdx]);
|
CSide_Data* pSideData_DN = m_pGlassData->GetSideData(arryWriteOrder_DN[nSideIdx]);
|
|
// 4-1. Panel Size
|
strTemp.Format(_T("SIZE_%s"), arrStrSideName[nSideIdx]);
|
vecStrTitle.push_back(strTemp);
|
double dPanelSize = (pSideData_UP->m_nGlassEndLine - pSideData_UP->m_nGlassStartLine) * pSideData_UP->m_dPixelSizeY;
|
strTemp.Format(_T("%.3f"), dPanelSize);
|
vecStrResultData.push_back(strTemp);
|
|
// 4-2. Dimension
|
for(int nMeasureIdx = 0; nMeasureIdx < MAX_SIDE_DIMENSION_MEASURE_COUNT; nMeasureIdx++)
|
{
|
strTemp.Format(_T("%s_DIM_%d"), arrStrSideName[nSideIdx], nMeasureIdx+1);
|
vecStrTitle.push_back(strTemp);
|
|
double dDimension = pSideData_UP->m_dSideMeasrue_CutLine_Result_mm[nMeasureIdx];
|
strTemp.Format(_T("%.0f"), dDimension*1000.0);
|
vecStrResultData.push_back(strTemp);
|
}
|
|
// 4-3. Up Chamfer
|
for(int nMeasureIdx = 0; nMeasureIdx < MAX_SIDE_DIMENSION_MEASURE_COUNT; nMeasureIdx++)
|
{
|
strTemp.Format(_T("%s_UP_CHAM_%d"), arrStrSideName[nSideIdx], nMeasureIdx+1);
|
vecStrTitle.push_back(strTemp);
|
|
double dChamfer = pSideData_UP->m_dSideMeasrue_Chamfer_Result_mm[nMeasureIdx];
|
strTemp.Format(_T("%.0f"), dChamfer*1000.0);
|
vecStrResultData.push_back(strTemp);
|
}
|
|
// 4-4. Dn Chamfer
|
for(int nMeasureIdx = 0; nMeasureIdx < MAX_SIDE_DIMENSION_MEASURE_COUNT; nMeasureIdx++)
|
{
|
strTemp.Format(_T("%s_DN_CHAM_%d"), arrStrSideName[nSideIdx], nMeasureIdx+1);
|
vecStrTitle.push_back(strTemp);
|
|
double dChamfer = pSideData_DN->m_dSideMeasrue_Chamfer_Result_mm[nMeasureIdx];
|
strTemp.Format(_T("%.0f"), dChamfer*1000.0);
|
vecStrResultData.push_back(strTemp);
|
}
|
}
|
|
// 5. Notch
|
CSide_Data* pSideData_UP = NULL;
|
CSide_Data* pSideData_DN = NULL;
|
|
// Notch乐绰 搁 茫扁
|
for(int nSideIdx=0; nSideIdx<MAX_PANEL_SIDE; nSideIdx++)
|
{
|
pSideData_UP = m_pGlassData->GetSideData(arryWriteOrder_UP[nSideIdx]);
|
pSideData_DN = m_pGlassData->GetSideData(arryWriteOrder_DN[nSideIdx]);
|
|
if(pSideData_DN->m_nNotchCount != 0)
|
break;
|
}
|
|
for(int nNotchIdx=0; nNotchIdx<MAX_SIDE_NOTCH_COUNT; nNotchIdx++)
|
{
|
// 4-2. Dimension, 酒阀搁栏肺 螟沥
|
for(int nMeasureIdx = 0; nMeasureIdx < MAX_SIDE_NOTCH_MEASURE_COUNT; nMeasureIdx++)
|
{
|
strTemp.Format(_T("NOTCH_%d_DIM_%d"), nNotchIdx+1, nMeasureIdx+1);
|
vecStrTitle.push_back(strTemp);
|
|
double dDimension = pSideData_DN->m_dNotch_Dimension_Edge_Result_um[nNotchIdx][nMeasureIdx];
|
strTemp.Format(_T("%.0f"), dDimension);
|
vecStrResultData.push_back(strTemp);
|
}
|
|
// 4-3. Up Chamfer
|
for(int nMeasureIdx = 0; nMeasureIdx < MAX_SIDE_NOTCH_MEASURE_COUNT; nMeasureIdx++)
|
{
|
strTemp.Format(_T("NOTCH_%d_UP_CHAM_%d"), nNotchIdx+1, nMeasureIdx+1);
|
vecStrTitle.push_back(strTemp);
|
|
double dChamfer = pSideData_UP->m_dNotch_Chamfer_Edge_Result_um[nNotchIdx][nMeasureIdx];
|
strTemp.Format(_T("%.0f"), dChamfer);
|
vecStrResultData.push_back(strTemp);
|
}
|
|
// 4-4. Dn Chamfer
|
for(int nMeasureIdx = 0; nMeasureIdx < MAX_SIDE_NOTCH_MEASURE_COUNT; nMeasureIdx++)
|
{
|
strTemp.Format(_T("NOTCH_%d_DN_CHAM_%d"), nNotchIdx+1, nMeasureIdx+1);
|
vecStrTitle.push_back(strTemp);
|
|
double dChamfer = pSideData_DN->m_dNotch_Chamfer_Edge_Result_um[nNotchIdx][nMeasureIdx];
|
strTemp.Format(_T("%.0f"), dChamfer);
|
vecStrResultData.push_back(strTemp);
|
}
|
}
|
|
// Save Path
|
CString strFilePath;
|
if (m_pHardware->m_bSaveResultByHour) {
|
// 按小时保存,绑定玻璃 Loading Time
|
strFilePath.Format(_T("D:\\Data\\%s\\%s\\%d\\%02d\\%02d\\%s_%s_%02d.csv"),
|
m_pHardware->GetMachineName(),
|
m_pHardware->GetLineID(),
|
tLoadingTime.GetYear(),
|
tLoadingTime.GetMonth(),
|
tLoadingTime.GetDay(),
|
g_pBase->m_strRecipeName,
|
g_pBase->m_strLoadingDay,
|
tLoadingTime.GetHour());
|
}
|
else {
|
// 按天保存,绑定玻璃 Loading Time
|
strFilePath.Format(_T("D:\\Data\\%s\\%s\\%d\\%02d\\%02d\\%s_%s.csv"),
|
m_pHardware->GetMachineName(),
|
m_pHardware->GetLineID(),
|
tLoadingTime.GetYear(),
|
tLoadingTime.GetMonth(),
|
tLoadingTime.GetDay(),
|
g_pBase->m_strRecipeName,
|
g_pBase->m_strLoadingDay);
|
}
|
|
CheckDirectory(strFilePath);
|
|
CFile _File;
|
CFileException _Exception;
|
_File.Open(strFilePath, CFile::modeCreate|CFile::modeWrite|CFile::modeNoTruncate|CFile::shareDenyWrite|CFile::shareDenyRead, &_Exception);
|
|
if(_Exception.m_cause == CFileException::none)
|
{
|
USES_CONVERSION;
|
int nBufferSize = vecStrTitle.size() * 255;
|
char* strBuffer = new char[nBufferSize];
|
int nBufferIdx = 0;
|
|
if(_File.SeekToEnd() == 0L)
|
{
|
ZeroMemory(strBuffer, sizeof(nBufferSize));
|
|
for(int i=0; i<vecStrTitle.size()-1; i++)
|
{
|
sprintf(&strBuffer[nBufferIdx], "%s,", W2A(vecStrTitle[i]));
|
nBufferIdx += vecStrTitle[i].GetLength() + 1;
|
}
|
|
sprintf(&strBuffer[nBufferIdx], "%s\r\n", W2A(vecStrTitle[vecStrTitle.size()-1]));
|
nBufferIdx += vecStrTitle[vecStrTitle.size()-1].GetLength() + 2;
|
|
_File.Write(strBuffer, nBufferIdx);
|
}
|
|
ZeroMemory(strBuffer, sizeof(nBufferSize));
|
nBufferIdx = 0;
|
|
for(int i=0; i<vecStrResultData.size()-1; i++)
|
{
|
sprintf(&strBuffer[nBufferIdx], "%s,", W2A(vecStrResultData[i]));
|
nBufferIdx += vecStrResultData[i].GetLength() + 1;
|
}
|
|
sprintf(&strBuffer[nBufferIdx], "%s\r\n", W2A(vecStrResultData[vecStrResultData.size()-1]));
|
nBufferIdx += vecStrResultData[vecStrResultData.size()-1].GetLength() + 2;
|
|
_File.Write(strBuffer, nBufferIdx);
|
|
delete [] strBuffer;
|
}
|
_File.Close();
|
|
CString strDmyFilePath;
|
strDmyFilePath.Format(_T("%s.dmy"), strFilePath);
|
CFile _File_Dmy;
|
CFileException _Exception_Dmy;
|
_File_Dmy.Open(strDmyFilePath, CFile::modeCreate|CFile::modeWrite|CFile::modeNoTruncate|CFile::shareDenyWrite|CFile::shareDenyRead, &_Exception_Dmy);
|
_File_Dmy.Close();
|
|
g_pLog->DisplayMessage(_T("[End Data File...] %s"), strFilePath);
|
}
|
|
BOOL CPostProcess::DefectProcess_Judge(CDefect *pDefect)
|
{
|
if(pDefect == NULL)
|
return FALSE;
|
|
int nSide = pDefect->m_DefectInfo.m_nSideIdx;
|
|
if(nSide < 0 || MAX_SIDE_COUNT <= nSide)
|
return FALSE;
|
|
CSIDE_PARM* pSideParam = &m_pRecipe->m_SideParam[nSide];
|
CSIDE_INSPECTT_PARM * pSideInsParam = NULL;
|
|
CSide_Data* pSideData = m_pGlassData->GetSideData((DimensionDir) nSide);
|
|
BOOL bJudgeUse = FALSE;
|
int nJudgeW_um = 0;
|
int nJudgeH_um = 0;
|
BOOL bAnd = TRUE;
|
|
int nJudgeArea = pDefect->m_nJudgeArea;
|
|
switch(pDefect->m_DefectInfo.m_DefectLoc)
|
{
|
case DefectLoc_Chip:
|
pSideInsParam = &pSideParam->m_InspectPrm[(int) eSideInsType_Chip];
|
nJudgeW_um = pSideInsParam->m_nJudge_Size_Min_X_um[nJudgeArea];
|
nJudgeH_um = pSideInsParam->m_nJudge_Size_Min_Y_um[nJudgeArea];
|
bAnd = (pSideInsParam->m_nJudge_Size_Min_OR_AND[nJudgeArea] == 2) ? TRUE : FALSE;
|
bJudgeUse = (pSideInsParam->m_nJudge_Size_Min_OR_AND[nJudgeArea] == 0) ? FALSE : TRUE;
|
break;
|
case DefectLoc_Crack:
|
pSideInsParam = &pSideParam->m_InspectPrm[(int) eSideInsType_Crack];
|
nJudgeW_um = pSideInsParam->m_nJudge_Size_Min_X_um[nJudgeArea];
|
nJudgeH_um = pSideInsParam->m_nJudge_Size_Min_Y_um[nJudgeArea];
|
bAnd = (pSideInsParam->m_nJudge_Size_Min_OR_AND[nJudgeArea] == 2) ? TRUE : FALSE;
|
bJudgeUse = (pSideInsParam->m_nJudge_Size_Min_OR_AND[nJudgeArea] == 0) ? FALSE : TRUE;
|
break;
|
case DefectLoc_Burr:
|
pSideInsParam = &pSideParam->m_InspectPrm[(int) eSideInsType_Burr];
|
nJudgeW_um = pSideInsParam->m_nJudge_Size_Min_X_um[nJudgeArea];
|
nJudgeH_um = pSideInsParam->m_nJudge_Size_Min_Y_um[nJudgeArea];
|
bAnd = (pSideInsParam->m_nJudge_Size_Min_OR_AND[nJudgeArea] == 2) ? TRUE : FALSE;
|
bJudgeUse = (pSideInsParam->m_nJudge_Size_Min_OR_AND[nJudgeArea] == 0) ? FALSE : TRUE;
|
break;
|
case DefectLoc_Chamfer:
|
pSideInsParam = &pSideParam->m_InspectPrm[(int) eSideInsType_Chamfer];
|
nJudgeW_um = pSideInsParam->m_nJudge_Size_Min_X_um[nJudgeArea];
|
nJudgeH_um = pSideInsParam->m_nJudge_Size_Min_Y_um[nJudgeArea];
|
bAnd = (pSideInsParam->m_nJudge_Size_Min_OR_AND[nJudgeArea] == 2) ? TRUE : FALSE;
|
bJudgeUse = (pSideInsParam->m_nJudge_Size_Min_OR_AND[nJudgeArea] == 0) ? FALSE : TRUE;
|
break;
|
case DefectLoc_In_Chip:
|
pSideInsParam = &pSideParam->m_InspectPrm[(int) eSideInsType_In_Chip];
|
nJudgeW_um = pSideInsParam->m_nJudge_Size_Min_X_um[nJudgeArea];
|
nJudgeH_um = pSideInsParam->m_nJudge_Size_Min_Y_um[nJudgeArea];
|
bAnd = (pSideInsParam->m_nJudge_Size_Min_OR_AND[nJudgeArea] == 2) ? TRUE : FALSE;
|
bJudgeUse = (pSideInsParam->m_nJudge_Size_Min_OR_AND[nJudgeArea] == 0) ? FALSE : TRUE;
|
break;
|
case DefectLoc_In_Crack:
|
pSideInsParam = &pSideParam->m_InspectPrm[(int) eSideInsType_In_Crack];
|
nJudgeW_um = pSideInsParam->m_nJudge_Size_Min_X_um[nJudgeArea];
|
nJudgeH_um = pSideInsParam->m_nJudge_Size_Min_Y_um[nJudgeArea];
|
bAnd = (pSideInsParam->m_nJudge_Size_Min_OR_AND[nJudgeArea] == 2) ? TRUE : FALSE;
|
bJudgeUse = (pSideInsParam->m_nJudge_Size_Min_OR_AND[nJudgeArea] == 0) ? FALSE : TRUE;
|
break;
|
case DefectLoc_In_Burr:
|
pSideInsParam = &pSideParam->m_InspectPrm[(int) eSideInsType_In_Burr];
|
nJudgeW_um = pSideInsParam->m_nJudge_Size_Min_X_um[nJudgeArea];
|
nJudgeH_um = pSideInsParam->m_nJudge_Size_Min_Y_um[nJudgeArea];
|
bAnd = (pSideInsParam->m_nJudge_Size_Min_OR_AND[nJudgeArea] == 2) ? TRUE : FALSE;
|
bJudgeUse = (pSideInsParam->m_nJudge_Size_Min_OR_AND[nJudgeArea] == 0) ? FALSE : TRUE;
|
break;
|
case DefectLoc_In_Chamfer:
|
pSideInsParam = &pSideParam->m_InspectPrm[(int) eSideInsType_In_Chamfer];
|
nJudgeW_um = pSideInsParam->m_nJudge_Size_Min_X_um[nJudgeArea];
|
nJudgeH_um = pSideInsParam->m_nJudge_Size_Min_Y_um[nJudgeArea];
|
bAnd = (pSideInsParam->m_nJudge_Size_Min_OR_AND[nJudgeArea] == 2) ? TRUE : FALSE;
|
bJudgeUse = (pSideInsParam->m_nJudge_Size_Min_OR_AND[nJudgeArea] == 0) ? FALSE : TRUE;
|
break;
|
case DefectLoc_Top_Corner:
|
nJudgeW_um = pSideParam->m_nTopCorner_Judge_Size_Min_X_um;
|
nJudgeH_um = pSideParam->m_nTopCorner_Judge_Size_Min_Y_um;
|
bAnd = (pSideParam->m_nTopCorner_Judge_Size_Min_OR_AND == 2) ? TRUE : FALSE;
|
bJudgeUse = (pSideParam->m_nTopCorner_Judge_Size_Min_OR_AND == 0) ? FALSE : TRUE;
|
break;
|
case DefectLoc_Bot_Corner:
|
nJudgeW_um = pSideParam->m_nBottomCorner_Judge_Size_Min_X_um;
|
nJudgeH_um = pSideParam->m_nBottomCorner_Judge_Size_Min_Y_um;
|
bAnd = (pSideParam->m_nBottomCorner_Judge_Size_Min_OR_AND == 2) ? TRUE : FALSE;
|
bJudgeUse = (pSideParam->m_nBottomCorner_Judge_Size_Min_OR_AND == 0) ? FALSE : TRUE;
|
break;
|
case DefectLoc_UserDefect:
|
nJudgeW_um = pSideParam->m_UserDefectPrm[pDefect->m_nUserDefectAreaIdx].m_nJudge_Size_Min_X_um;
|
nJudgeH_um = pSideParam->m_UserDefectPrm[pDefect->m_nUserDefectAreaIdx].m_nJudge_Size_Min_Y_um;
|
bAnd = (pSideParam->m_UserDefectPrm[pDefect->m_nUserDefectAreaIdx].m_nJudge_Size_Min_OR_AND == 2) ? TRUE : FALSE;
|
bJudgeUse = (pSideParam->m_UserDefectPrm[pDefect->m_nUserDefectAreaIdx].m_nJudge_Size_Min_OR_AND == 0) ? FALSE : TRUE;
|
break;
|
case DefectLoc_Notch_Crack:
|
case DefectLoc_Notch_Broken:
|
case DefectLoc_Notch_NoGrind:
|
nJudgeW_um = pSideParam->m_NotchPrm[pDefect->m_nNotchIdx].m_nNotch_Inspect_Defect_Judge_X_um;
|
nJudgeH_um = pSideParam->m_NotchPrm[pDefect->m_nNotchIdx].m_nNotch_Inspect_Defect_Judge_Y_um;
|
bAnd = (pSideParam->m_NotchPrm[pDefect->m_nNotchIdx].m_nNotch_Inspect_Defect_Judge_And == 2) ? TRUE : FALSE;
|
bJudgeUse = (pSideParam->m_NotchPrm[pDefect->m_nNotchIdx].m_nNotch_Inspect_Defect_Judge_And == 0) ? FALSE : TRUE;
|
break;
|
case DefectLoc_Exception:
|
return TRUE;
|
}
|
|
if(bJudgeUse == FALSE)
|
{
|
pDefect->m_bJudge_NG = TRUE;
|
return TRUE;
|
}
|
|
if(bAnd == TRUE)
|
{
|
if((double)pDefect->m_dSizeX_um >= nJudgeW_um && (double)pDefect->m_dSizeY_um >= nJudgeH_um)
|
pDefect->m_bJudge_NG = TRUE;
|
}
|
else
|
{
|
if((double)pDefect->m_dSizeX_um >= nJudgeW_um || (double)pDefect->m_dSizeY_um >= nJudgeH_um)
|
pDefect->m_bJudge_NG = TRUE;
|
}
|
|
return TRUE;
|
}
|
|
void CPostProcess::PostDefectJudgeProcess()
|
{
|
g_pLog->DisplayMessage(_T("Post Defect Judge Procss.."));
|
|
if(m_pRecipe == NULL || m_pHardware == NULL)
|
return;
|
|
CHardwareSettings* pHard = m_pHardware;
|
|
CCameraSettings* pCamera[MAX_CAMERA_COUNT][MAX_SCAN_COUNT] = {};
|
|
for(int i=0; i<MAX_CAMERA_COUNT; i++)
|
for(int j=0; j<MAX_SCAN_COUNT; j++)
|
pCamera[i][j] = m_pHardware->GetCameraSettings(i, j);
|
|
double dScanRes = 0.;
|
double dConvRes = 0.;
|
|
int nStageNo = g_pBase->m_nStageNo;
|
|
if(nStageNo < 0 || nStageNo > 1)
|
nStageNo = 0;
|
|
CDefect* pDefect = NULL;
|
|
for(int iCam=0; iCam<pHard->GetCameraCount(); iCam++)
|
{
|
int nCamDefectCount = m_pInspectCamera[iCam]->GetDefectCount();
|
g_pLog->DisplayMessage(_T("[%d]Camera Defect Count : %d"), iCam, nCamDefectCount);
|
|
for(int iDefect=0; iDefect < nCamDefectCount ; iDefect++)
|
{
|
pDefect = m_pInspectCamera[iCam]->GetDefect(iDefect);
|
|
if(pDefect == NULL)
|
continue;
|
|
if(m_pGlassData->GetTotalDefectCount() >= MAX_DEFECT_COUNT_GLASS)
|
continue;
|
|
int nCamIdx = (pDefect->m_DefectInfo.m_nCamID < 0 || MAX_CAMERA_COUNT <= pDefect->m_DefectInfo.m_nCamID) ? 0 : pDefect->m_DefectInfo.m_nCamID;
|
int nScanIdx = (pDefect->m_DefectInfo.m_nScanIdx < 0 || MAX_SCAN_COUNT <= pDefect->m_DefectInfo.m_nScanIdx) ? 0 : pDefect->m_DefectInfo.m_nScanIdx;
|
|
if(pCamera[nCamIdx][nScanIdx] == NULL)
|
continue;
|
|
dScanRes = pCamera[nCamIdx][nScanIdx]->m_dScanResolution[nStageNo];
|
dConvRes = pCamera[nCamIdx][nScanIdx]->m_dConvResolution[nStageNo];
|
|
if (dScanRes <= 0.0 || dConvRes <= 0.0)
|
continue;
|
|
if(DefectProcess(pDefect, m_pInspectCamera[iCam], pCamera[nCamIdx][nScanIdx]) == FALSE)
|
continue;
|
|
if(DefectProcess_Judge(pDefect) == FALSE)
|
continue;
|
|
CDefect* pNewDefect = new CDefect;
|
*(pNewDefect) = *(pDefect);
|
|
if(m_pGlassData->SetDefect(pNewDefect) == FALSE)
|
{
|
delete pNewDefect;
|
continue;
|
}
|
}
|
}
|
|
g_pLog->DisplayMessage(_T("End of Post Defect Judge Procss.."));
|
}
|
|
void CPostProcess::SaveDefectImageNG()
|
{
|
g_pLog->DisplayMessage(_T("Save Defect Image NG.."));
|
|
if(m_pGlassData == NULL)
|
return;
|
|
MapDefectIt it;
|
MapDefect* pMapDefect = m_pGlassData->GetMapDefect_NG();
|
|
if(pMapDefect == NULL || 0 == pMapDefect->size())
|
return;
|
|
int nMaxChipSaveCount = 0;
|
int nMaxCrackSaveCount = 0;
|
int nMaxBurrSaveCount = 0;
|
int nMaxChamferSaveCount = 0;
|
int nMaxInChipSaveCount = 0;
|
int nMaxInCrackSaveCount = 0;
|
int nMaxInBurrSaveCount = 0;
|
int nMaxInChamferSaveCount = 0;
|
int nMaxTopCornerSaveCount = 0;
|
int nMaxBotCornerSaveCount = 0;
|
int nMaxCornerDimensionSaveCount = 0;
|
int nMaxDimensionSaveCount = 0;
|
int nMaxNotchSaveCount = 0;
|
int nMaxNotchDimensionSaveCount = 0;
|
int nMaxNotchChamferSaveCount = 0;
|
int nMaxNotchRadiusSaveCount = 0;
|
int nMaxUserDefectSaveCount = 0;
|
int nMaxMarkSaveCount = 0;
|
int nMaxExceptionSaveCount = 0;
|
int nMaxLicenseSaveCount = 0;
|
for (it = pMapDefect->begin(); it != pMapDefect->end(); it++)
|
{
|
if (0 == pMapDefect->size()) break;
|
|
CDefect* pDefect = static_cast<CDefect*>(it->second);
|
if(pDefect == NULL)
|
continue;
|
if(pDefect->m_DefectInfo.m_DefectLoc < DefectLoc_Chip || pDefect->m_DefectInfo.m_DefectLoc > DefectLoc_None)
|
continue;
|
if(pDefect->m_DefectInfo.m_nSideIdx < 0 || pDefect->m_DefectInfo.m_nSideIdx >= MAX_DIMENSION_COUNT)
|
continue;
|
|
CString strDefectType = g_strDefectType[pDefect->m_DefectInfo.m_DefectLoc];
|
if (strDefectType.Compare(_T("Chip")) == 0 && g_pBase->m_nMaxChipSaveCount != 0)
|
{
|
nMaxChipSaveCount++;
|
if (nMaxChipSaveCount > g_pBase->m_nMaxChipSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Crack")) == 0 && g_pBase->m_nMaxCrackSaveCount != 0)
|
{
|
nMaxCrackSaveCount++;
|
if (nMaxCrackSaveCount > g_pBase->m_nMaxCrackSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Burr")) == 0 && g_pBase->m_nMaxBurrSaveCount != 0)
|
{
|
nMaxBurrSaveCount++;
|
if (nMaxBurrSaveCount > g_pBase->m_nMaxBurrSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Chamfer")) == 0 && g_pBase->m_nMaxChamferSaveCount != 0)
|
{
|
nMaxChamferSaveCount++;
|
if (nMaxChamferSaveCount > g_pBase->m_nMaxChamferSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("In_Chip")) == 0 && g_pBase->m_nMaxInChipSaveCount != 0)
|
{
|
nMaxInChipSaveCount;
|
if (nMaxInChipSaveCount > g_pBase->m_nMaxInChipSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("In_Crack")) == 0 && g_pBase->m_nMaxInCrackSaveCount != 0)
|
{
|
nMaxInCrackSaveCount++;
|
if (nMaxInCrackSaveCount > g_pBase->m_nMaxInCrackSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("In_Burr")) == 0 && g_pBase->m_nMaxInBurrSaveCount != 0)
|
{
|
nMaxInBurrSaveCount++;
|
if (nMaxInBurrSaveCount > g_pBase->m_nMaxInBurrSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("In_Chamfer")) == 0 && g_pBase->m_nMaxInChamferSaveCount != 0)
|
{
|
nMaxInChamferSaveCount++;
|
if (nMaxInChamferSaveCount > g_pBase->m_nMaxInChamferSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Top_Corner")) == 0 && g_pBase->m_nMaxTopCornerSaveCount != 0)
|
{
|
nMaxTopCornerSaveCount++;
|
if (nMaxTopCornerSaveCount > g_pBase->m_nMaxTopCornerSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Bot_Corner")) == 0 && g_pBase->m_nMaxBotCornerSaveCount != 0)
|
{
|
nMaxBotCornerSaveCount++;
|
if (nMaxBotCornerSaveCount > g_pBase->m_nMaxBotCornerSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Corner_Dimension")) == 0 && g_pBase->m_nMaxCornerDimensionSaveCount != 0)
|
{
|
nMaxCornerDimensionSaveCount++;
|
if (nMaxCornerDimensionSaveCount > g_pBase->m_nMaxCornerDimensionSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Dimension")) == 0 && g_pBase->m_nMaxDimensionSaveCount != 0)
|
{
|
nMaxDimensionSaveCount++;
|
if (nMaxDimensionSaveCount > g_pBase->m_nMaxDimensionSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Notch")) == 0 && g_pBase->m_nMaxNotchSaveCount != 0)
|
{
|
nMaxNotchSaveCount++;
|
if (nMaxNotchSaveCount > g_pBase->m_nMaxNotchSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Notch_Dimension")) == 0 && g_pBase->m_nMaxNotchDimensionSaveCount != 0)
|
{
|
nMaxNotchDimensionSaveCount++;
|
if (nMaxNotchDimensionSaveCount > g_pBase->m_nMaxNotchDimensionSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Notch_Chamfer")) == 0 && g_pBase->m_nMaxNotchChamferSaveCount != 0)
|
{
|
nMaxNotchChamferSaveCount++;
|
if (nMaxNotchChamferSaveCount > g_pBase->m_nMaxNotchChamferSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Notch_Radius")) == 0 && g_pBase->m_nMaxNotchRadiusSaveCount != 0)
|
{
|
nMaxNotchRadiusSaveCount++;
|
if (nMaxNotchRadiusSaveCount > g_pBase->m_nMaxNotchRadiusSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("User_Defect")) == 0 && g_pBase->m_nMaxUserDefectSaveCount != 0)
|
{
|
nMaxUserDefectSaveCount++;
|
if (nMaxUserDefectSaveCount > g_pBase->m_nMaxUserDefectSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Mark")) == 0 && g_pBase->m_nMaxMarkSaveCount != 0)
|
{
|
nMaxMarkSaveCount++;
|
if (nMaxMarkSaveCount > g_pBase->m_nMaxMarkSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Exception")) == 0 && g_pBase->m_nMaxExceptionSaveCount != 0)
|
{
|
nMaxExceptionSaveCount++;
|
if (nMaxExceptionSaveCount > g_pBase->m_nMaxExceptionSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("License")) == 0 && g_pBase->m_nMaxLicenseSaveCount != 0)
|
{
|
nMaxLicenseSaveCount++;
|
if (nMaxLicenseSaveCount > g_pBase->m_nMaxLicenseSaveCount) continue;
|
}
|
|
CString strSaveImagePath;
|
CString strSaveImageDLPath;
|
//strSaveImagePath.Format(_T("%s\\%03d_%s_%s_%s.jpg"),m_strDefectFolder,pNewDefect->m_nIdx, g_pBase->m_strHPanelID, PANEL_SIDE[pNewDefect->m_DefectInfo.m_nSideIdx], strDefectType);
|
strSaveImagePath.Format(_T("%s\\%s_%s_%s_%d.jpg"),m_strDefectFolder, g_pBase->m_strHPanelID, PANEL_SIDE[pDefect->m_DefectInfo.m_nSideIdx], strDefectType, pDefect->m_nIdx);
|
strSaveImageDLPath.Format(_T("%s\\%s_%s_%s_%d.bmp"),m_strImageDLFolder, g_pBase->m_strHPanelID, PANEL_SIDE[pDefect->m_DefectInfo.m_nSideIdx], strDefectType, pDefect->m_nIdx);
|
CRect rectDefect;
|
rectDefect.left = DEFECTIMAGE_WIDTH/2 - pDefect->m_DefectInfo.m_rtDefectPos_pxl.Width()/2;
|
rectDefect.right = DEFECTIMAGE_WIDTH/2 + pDefect->m_DefectInfo.m_rtDefectPos_pxl.Width()/2;
|
rectDefect.top = DEFECTIMAGE_HEIGHT/2 - pDefect->m_DefectInfo.m_rtDefectPos_pxl.Height()/2;
|
rectDefect.bottom = DEFECTIMAGE_HEIGHT/2 + pDefect->m_DefectInfo.m_rtDefectPos_pxl.Height()/2;
|
|
CheckDirectory(strSaveImagePath);
|
CheckDirectory(strSaveImageDLPath);
|
strDLFile.Format(_T("%s"), strSaveImageDLPath);
|
// SaveDefectImage2(pNewDefect->m_Image,CSize(DEFECTIMAGE_WIDTH,DEFECTIMAGE_HEIGHT), rectDefect, strSaveImagePath);
|
SaveDefectImage_with_Title(pDefect, CSize(DEFECTIMAGE_WIDTH,DEFECTIMAGE_HEIGHT), rectDefect, strSaveImagePath);
|
|
pDefect->m_strSaveImagePath = strSaveImagePath;
|
}
|
|
g_pLog->DisplayMessage(_T("End of Save Defect Image NG.."));
|
}
|
|
void CPostProcess::SaveDefectImageOK()
|
{
|
g_pLog->DisplayMessage(_T("Save Defect Image OK.."));
|
|
if (m_pGlassData == NULL)
|
return;
|
|
Lock();
|
MapDefectIt it;
|
MapDefect* pMapDefect = m_pGlassData->GetMapDefect_OK();
|
Unlock();
|
|
if (pMapDefect == NULL || 0 == pMapDefect->size())
|
return;
|
|
int nMaxChipSaveCount = 0;
|
int nMaxCrackSaveCount = 0;
|
int nMaxBurrSaveCount = 0;
|
int nMaxChamferSaveCount = 0;
|
int nMaxInChipSaveCount = 0;
|
int nMaxInCrackSaveCount = 0;
|
int nMaxInBurrSaveCount = 0;
|
int nMaxInChamferSaveCount = 0;
|
int nMaxTopCornerSaveCount = 0;
|
int nMaxBotCornerSaveCount = 0;
|
int nMaxCornerDimensionSaveCount = 0;
|
int nMaxDimensionSaveCount = 0;
|
int nMaxNotchSaveCount = 0;
|
int nMaxNotchDimensionSaveCount = 0;
|
int nMaxNotchChamferSaveCount = 0;
|
int nMaxNotchRadiusSaveCount = 0;
|
int nMaxUserDefectSaveCount = 0;
|
int nMaxMarkSaveCount = 0;
|
int nMaxExceptionSaveCount = 0;
|
int nMaxLicenseSaveCount = 0;
|
for (it = pMapDefect->begin(); it != pMapDefect->end(); it++)
|
{
|
if (0 == pMapDefect->size()) break;
|
|
CDefect* pDefect = static_cast<CDefect*>(it->second);
|
if (pDefect == NULL)
|
continue;
|
if (pDefect->m_DefectInfo.m_nSideIdx < 0 || pDefect->m_DefectInfo.m_nSideIdx >= MAX_DIMENSION_COUNT)
|
continue;
|
if (pDefect->m_DefectInfo.m_DefectLoc != DefectLoc_Chip
|
&& pDefect->m_DefectInfo.m_DefectLoc != DefectLoc_In_Chip)
|
continue;
|
|
CString strDefectFolder;
|
strDefectFolder.Format(_T("%s\\IMG_DEFECT_OK\\%s\\%s"), PATH_INSPECTION_DATA, g_pBase->m_strLoadingDay, g_pBase->m_strHPanelID);
|
|
CString strDefectType = g_strDefectType[pDefect->m_DefectInfo.m_DefectLoc];
|
if (strDefectType.Compare(_T("Chip")) == 0 && g_pBase->m_nMaxChipSaveCount != 0)
|
{
|
nMaxChipSaveCount++;
|
if (nMaxChipSaveCount > g_pBase->m_nMaxChipSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Crack")) == 0 && g_pBase->m_nMaxCrackSaveCount != 0)
|
{
|
nMaxCrackSaveCount++;
|
if (nMaxCrackSaveCount > g_pBase->m_nMaxCrackSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Burr")) == 0 && g_pBase->m_nMaxBurrSaveCount != 0)
|
{
|
nMaxBurrSaveCount++;
|
if (nMaxBurrSaveCount > g_pBase->m_nMaxBurrSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Chamfer")) == 0 && g_pBase->m_nMaxChamferSaveCount != 0)
|
{
|
nMaxChamferSaveCount++;
|
if (nMaxChamferSaveCount > g_pBase->m_nMaxChamferSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("In_Chip")) == 0 && g_pBase->m_nMaxInChipSaveCount != 0)
|
{
|
nMaxInChipSaveCount;
|
if (nMaxInChipSaveCount > g_pBase->m_nMaxInChipSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("In_Crack")) == 0 && g_pBase->m_nMaxInCrackSaveCount != 0)
|
{
|
nMaxInCrackSaveCount++;
|
if (nMaxInCrackSaveCount > g_pBase->m_nMaxInCrackSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("In_Burr")) == 0 && g_pBase->m_nMaxInBurrSaveCount != 0)
|
{
|
nMaxInBurrSaveCount++;
|
if (nMaxInBurrSaveCount > g_pBase->m_nMaxInBurrSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("In_Chamfer")) == 0 && g_pBase->m_nMaxInChamferSaveCount != 0)
|
{
|
nMaxInChamferSaveCount++;
|
if (nMaxInChamferSaveCount > g_pBase->m_nMaxInChamferSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Top_Corner")) == 0 && g_pBase->m_nMaxTopCornerSaveCount != 0)
|
{
|
nMaxTopCornerSaveCount++;
|
if (nMaxTopCornerSaveCount > g_pBase->m_nMaxTopCornerSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Bot_Corner")) == 0 && g_pBase->m_nMaxBotCornerSaveCount != 0)
|
{
|
nMaxBotCornerSaveCount++;
|
if (nMaxBotCornerSaveCount > g_pBase->m_nMaxBotCornerSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Corner_Dimension")) == 0 && g_pBase->m_nMaxCornerDimensionSaveCount != 0)
|
{
|
nMaxCornerDimensionSaveCount++;
|
if (nMaxCornerDimensionSaveCount > g_pBase->m_nMaxCornerDimensionSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Dimension")) == 0 && g_pBase->m_nMaxDimensionSaveCount != 0)
|
{
|
nMaxDimensionSaveCount++;
|
if (nMaxDimensionSaveCount > g_pBase->m_nMaxDimensionSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Notch")) == 0 && g_pBase->m_nMaxNotchSaveCount != 0)
|
{
|
nMaxNotchSaveCount++;
|
if (nMaxNotchSaveCount > g_pBase->m_nMaxNotchSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Notch_Dimension")) == 0 && g_pBase->m_nMaxNotchDimensionSaveCount != 0)
|
{
|
nMaxNotchDimensionSaveCount++;
|
if (nMaxNotchDimensionSaveCount > g_pBase->m_nMaxNotchDimensionSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Notch_Chamfer")) == 0 && g_pBase->m_nMaxNotchChamferSaveCount != 0)
|
{
|
nMaxNotchChamferSaveCount++;
|
if (nMaxNotchChamferSaveCount > g_pBase->m_nMaxNotchChamferSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Notch_Radius")) == 0 && g_pBase->m_nMaxNotchRadiusSaveCount != 0)
|
{
|
nMaxNotchRadiusSaveCount++;
|
if (nMaxNotchRadiusSaveCount > g_pBase->m_nMaxNotchRadiusSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("User_Defect")) == 0 && g_pBase->m_nMaxUserDefectSaveCount != 0)
|
{
|
nMaxUserDefectSaveCount++;
|
if (nMaxUserDefectSaveCount > g_pBase->m_nMaxUserDefectSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Mark")) == 0 && g_pBase->m_nMaxMarkSaveCount != 0)
|
{
|
nMaxMarkSaveCount++;
|
if (nMaxMarkSaveCount > g_pBase->m_nMaxMarkSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("Exception")) == 0 && g_pBase->m_nMaxExceptionSaveCount != 0)
|
{
|
nMaxExceptionSaveCount++;
|
if (nMaxExceptionSaveCount > g_pBase->m_nMaxExceptionSaveCount) continue;
|
}
|
else if (strDefectType.Compare(_T("License")) == 0 && g_pBase->m_nMaxLicenseSaveCount != 0)
|
{
|
nMaxLicenseSaveCount++;
|
if (nMaxLicenseSaveCount > g_pBase->m_nMaxLicenseSaveCount) continue;
|
}
|
|
CString strSaveImagePath;
|
strSaveImagePath.Format(_T("%s\\%s_%s_%s[%d].jpg"), strDefectFolder, g_pBase->m_strHPanelID, PANEL_SIDE[pDefect->m_DefectInfo.m_nSideIdx], strDefectType, pDefect->m_nIdx);
|
|
CRect rectDefect;
|
rectDefect.left = DEFECTIMAGE_WIDTH / 2 - pDefect->m_DefectInfo.m_rtDefectPos_pxl.Width() / 2;
|
rectDefect.right = DEFECTIMAGE_WIDTH / 2 + pDefect->m_DefectInfo.m_rtDefectPos_pxl.Width() / 2;
|
rectDefect.top = DEFECTIMAGE_HEIGHT / 2 - pDefect->m_DefectInfo.m_rtDefectPos_pxl.Height() / 2;
|
rectDefect.bottom = DEFECTIMAGE_HEIGHT / 2 + pDefect->m_DefectInfo.m_rtDefectPos_pxl.Height() / 2;
|
|
CheckDirectory(strSaveImagePath);
|
|
int nMinSize_X = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[(int)pDefect->m_DefectInfo.m_DefectLoc].m_nMinSize_Filter_X_um;
|
int nMinSize_Y = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[(int)pDefect->m_DefectInfo.m_DefectLoc].m_nMinSize_Filter_Y_um;
|
nMinSize_X = nMinSize_X < 20 ? 20 : nMinSize_X;
|
nMinSize_Y = nMinSize_Y < 20 ? 20 : nMinSize_Y;
|
|
if (static_cast<int>(round(pDefect->m_dSizeX_um)) > nMinSize_X && static_cast<int>(round(pDefect->m_dSizeY_um)) > nMinSize_Y)
|
{
|
SaveDefectImage_with_Title(pDefect, CSize(DEFECTIMAGE_WIDTH, DEFECTIMAGE_HEIGHT), rectDefect, strSaveImagePath, cvScalar(0, 255, 0));
|
}
|
}
|
|
g_pLog->DisplayMessage(_T("End of Save Defect Image OK.."));
|
}
|
|
int CPostProcess::GetInspectionDefect()
|
{
|
if(m_pRecipe == NULL || m_pHardware == NULL)
|
return 0;
|
|
CHardwareSettings* pHard = m_pHardware;
|
|
CCameraSettings* pCamera[MAX_CAMERA_COUNT][MAX_SCAN_COUNT] = {};
|
|
for(int i=0; i<MAX_CAMERA_COUNT; i++)
|
for(int j=0; j<MAX_SCAN_COUNT; j++)
|
pCamera[i][j] = m_pHardware->GetCameraSettings(i, j);
|
|
double dScanRes = 0.;
|
double dConvRes = 0.;
|
|
int nStageNo = g_pBase->m_nStageNo;
|
|
if(nStageNo < 0 || nStageNo > 1)
|
nStageNo = 0;
|
|
CDefect* pDefect = NULL;
|
|
for(int iCam=0; iCam<pHard->GetCameraCount(); iCam++)
|
{
|
int nCamDefectCount = m_pInspectCamera[iCam]->GetDefectCount();
|
g_pLog->DisplayMessage(_T("[%d]Camera Defect Count : %d"), iCam, nCamDefectCount);
|
|
for(int iDefect=0; iDefect < nCamDefectCount ; iDefect++)
|
{
|
pDefect = m_pInspectCamera[iCam]->GetDefect(iDefect);
|
|
if(pDefect == NULL)
|
continue;
|
|
if(m_pGlassData->GetTotalDefectCount() >= MAX_DEFECT_COUNT_GLASS)
|
continue;
|
|
int nCamIdx = (pDefect->m_DefectInfo.m_nCamID < 0 || MAX_CAMERA_COUNT <= pDefect->m_DefectInfo.m_nCamID) ? 0 : pDefect->m_DefectInfo.m_nCamID;
|
int nScanIdx = (pDefect->m_DefectInfo.m_nScanIdx < 0 || MAX_SCAN_COUNT <= pDefect->m_DefectInfo.m_nScanIdx) ? 0 : pDefect->m_DefectInfo.m_nScanIdx;
|
|
if(pCamera[nCamIdx][nScanIdx] == NULL)
|
continue;
|
|
dScanRes = pCamera[nCamIdx][nScanIdx]->m_dScanResolution[nStageNo];
|
dConvRes = pCamera[nCamIdx][nScanIdx]->m_dConvResolution[nStageNo];
|
|
if (dScanRes <= 0.0 || dConvRes <= 0.0)
|
continue;
|
|
if(DefectProcess(pDefect, m_pInspectCamera[iCam], pCamera[nCamIdx][nScanIdx]) == FALSE)
|
continue;
|
|
if(DefectProcess_Judge(pDefect) == FALSE)
|
continue;
|
|
CDefect* pNewDefect = new CDefect;
|
*(pNewDefect) = *(pDefect);
|
|
if(m_pGlassData->SetDefect(pNewDefect) == FALSE)
|
{
|
delete pNewDefect;
|
continue;
|
}
|
|
if(pNewDefect->m_bJudge_NG == TRUE)
|
{
|
CString strDefectType = g_strDefectType[pNewDefect->m_DefectInfo.m_DefectLoc];
|
CString strSaveImagePath;
|
//strSaveImagePath.Format(_T("%s\\%03d_%s_%s_%s.jpg"),m_strDefectFolder,pNewDefect->m_nIdx, g_pBase->m_strHPanelID, PANEL_SIDE[pNewDefect->m_DefectInfo.m_nSideIdx], strDefectType);
|
strSaveImagePath.Format(_T("%s\\%s_%s_%d.jpg"),m_strDefectFolder, g_pBase->m_strHPanelID, PANEL_SIDE[pNewDefect->m_DefectInfo.m_nSideIdx], pNewDefect->m_nIdx);
|
|
CRect rectDefect;
|
rectDefect.left = DEFECTIMAGE_WIDTH/2 - pNewDefect->m_DefectInfo.m_rtDefectPos_pxl.Width()/2;
|
rectDefect.right = DEFECTIMAGE_WIDTH/2 + pNewDefect->m_DefectInfo.m_rtDefectPos_pxl.Width()/2;
|
rectDefect.top = DEFECTIMAGE_HEIGHT/2 - pNewDefect->m_DefectInfo.m_rtDefectPos_pxl.Height()/2;
|
rectDefect.bottom = DEFECTIMAGE_HEIGHT/2 + pNewDefect->m_DefectInfo.m_rtDefectPos_pxl.Height()/2;
|
|
CheckDirectory(strSaveImagePath);
|
// SaveDefectImage2(pNewDefect->m_Image,CSize(DEFECTIMAGE_WIDTH,DEFECTIMAGE_HEIGHT), rectDefect, strSaveImagePath);
|
SaveDefectImage_with_Title(pNewDefect, CSize(DEFECTIMAGE_WIDTH,DEFECTIMAGE_HEIGHT), rectDefect, strSaveImagePath);
|
|
pNewDefect->m_strSaveImagePath = strSaveImagePath;
|
}
|
}
|
}
|
|
return m_pGlassData->GetJudgeDefectCount();
|
}
|
|
BOOL CPostProcess::DefectProcess(CDefect* pDefect, CInspectCamera *pInspect, CCameraSettings* pCamera)
|
{
|
CGlassRecipe* pRecipe = m_pRecipe;
|
if(pRecipe == NULL)
|
return FALSE;
|
|
if(pCamera == NULL)
|
return FALSE;
|
|
double dScanRes = 0.,dConvRes = 0.;
|
int nMarginLeft;
|
int nStageNo = g_pBase->m_nStageNo;
|
|
if(nStageNo < 0 || nStageNo > 1)
|
nStageNo = 0;
|
|
dScanRes = pCamera->m_dScanResolution[nStageNo];
|
dConvRes = pCamera->m_dConvResolution[nStageNo];
|
nMarginLeft = pCamera->m_nMarginLeft;
|
|
if (dScanRes <= 0.0 || dConvRes <= 0)
|
return FALSE;
|
|
int nStartLine = m_pGlassData->GetSideData((DimensionDir) pDefect->m_DefectInfo.m_nSideIdx)->m_nGlassStartLine;
|
|
/*
|
pDefect->m_nUMOriginX = (int)((double) (pDefect->m_DefectInfo.m_ptDefectPos_pxl.y - nStartLine) * dScanRes);
|
pDefect->m_nUMOriginY = (int)((double) (pDefect->m_DefectInfo.m_ptDefectPos_pxl.x * dConvRes)); // 荐沥 鞘夸..
|
*/
|
|
CSIDE_PARM* pSideParam = &pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx];
|
|
if(DefectLoc_Chip <= pDefect->m_DefectInfo.m_DefectLoc && pDefect->m_DefectInfo.m_DefectLoc <= DefectLoc_In_Chamfer)
|
{
|
int nFirstAreaStart = nStartLine;
|
int nSecondAreaStart = nStartLine + pSideParam->m_nCenterJudgeArea_StartLine_To_Start_pxl;
|
int nThirdAreaStart = nStartLine + pSideParam->m_nCenterJudgeArea_StartLine_To_End_pxl;
|
|
if(pDefect->m_DefectInfo.m_rtDefectPos_pxl.top < nSecondAreaStart) pDefect->m_nJudgeArea = 0;
|
else if(pDefect->m_DefectInfo.m_rtDefectPos_pxl.top < nThirdAreaStart) pDefect->m_nJudgeArea = 1;
|
else pDefect->m_nJudgeArea = 2;
|
}
|
|
int nJudgeArea = pDefect->m_nJudgeArea;
|
|
pDefect->m_dSizeX_um = (int)((double)pDefect->m_DefectInfo.m_rtDefectPos_pxl.Width() * dConvRes);
|
pDefect->m_dSizeY_um = (int)((double)pDefect->m_DefectInfo.m_rtDefectPos_pxl.Height() * dScanRes);
|
|
switch(pDefect->m_DefectInfo.m_DefectLoc)
|
{
|
case DefectLoc_Chip:
|
pDefect->m_nJudge_X_um = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_Chip].m_nJudge_Size_Min_X_um[nJudgeArea];
|
pDefect->m_nJudge_Y_um = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_Chip].m_nJudge_Size_Min_Y_um[nJudgeArea];
|
pDefect->m_nJudge_Type = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_Chip].m_nJudge_Size_Min_OR_AND[nJudgeArea];
|
break;
|
case DefectLoc_Crack:
|
pDefect->m_nJudge_X_um = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_Crack].m_nJudge_Size_Min_X_um[nJudgeArea];
|
pDefect->m_nJudge_Y_um = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_Crack].m_nJudge_Size_Min_Y_um[nJudgeArea];
|
pDefect->m_nJudge_Type = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_Crack].m_nJudge_Size_Min_OR_AND[nJudgeArea];
|
break;
|
case DefectLoc_Burr:
|
pDefect->m_nJudge_X_um = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_Burr].m_nJudge_Size_Min_X_um[nJudgeArea];
|
pDefect->m_nJudge_Y_um = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_Burr].m_nJudge_Size_Min_Y_um[nJudgeArea];
|
pDefect->m_nJudge_Type = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_Burr].m_nJudge_Size_Min_OR_AND[nJudgeArea];
|
break;
|
case DefectLoc_Chamfer:
|
pDefect->m_nJudge_X_um = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_Chamfer].m_nJudge_Size_Min_X_um[nJudgeArea];
|
pDefect->m_nJudge_Y_um = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_Chamfer].m_nJudge_Size_Min_Y_um[nJudgeArea];
|
pDefect->m_nJudge_Type = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_Chamfer].m_nJudge_Size_Min_OR_AND[nJudgeArea];
|
break;
|
case DefectLoc_In_Chip:
|
pDefect->m_nJudge_X_um = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_In_Chip].m_nJudge_Size_Min_X_um[nJudgeArea];
|
pDefect->m_nJudge_Y_um = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_In_Chip].m_nJudge_Size_Min_Y_um[nJudgeArea];
|
pDefect->m_nJudge_Type = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_In_Chip].m_nJudge_Size_Min_OR_AND[nJudgeArea];
|
break;
|
case DefectLoc_In_Crack:
|
pDefect->m_nJudge_X_um = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_In_Crack].m_nJudge_Size_Min_X_um[nJudgeArea];
|
pDefect->m_nJudge_Y_um = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_In_Crack].m_nJudge_Size_Min_Y_um[nJudgeArea];
|
pDefect->m_nJudge_Type = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_In_Crack].m_nJudge_Size_Min_OR_AND[nJudgeArea];
|
break;
|
case DefectLoc_In_Burr:
|
pDefect->m_nJudge_X_um = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_In_Burr].m_nJudge_Size_Min_X_um[nJudgeArea];
|
pDefect->m_nJudge_Y_um = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_In_Burr].m_nJudge_Size_Min_Y_um[nJudgeArea];
|
pDefect->m_nJudge_Type = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_In_Burr].m_nJudge_Size_Min_OR_AND[nJudgeArea];
|
break;
|
case DefectLoc_In_Chamfer:
|
pDefect->m_nJudge_X_um = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_In_Chamfer].m_nJudge_Size_Min_X_um[nJudgeArea];
|
pDefect->m_nJudge_Y_um = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_In_Chamfer].m_nJudge_Size_Min_Y_um[nJudgeArea];
|
pDefect->m_nJudge_Type = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_InspectPrm[eSideInsType_In_Chamfer].m_nJudge_Size_Min_OR_AND[nJudgeArea];
|
break;
|
case DefectLoc_Top_Corner:
|
pDefect->m_nJudge_X_um = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_nTopCorner_Judge_Size_Min_X_um;
|
pDefect->m_nJudge_Y_um = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_nTopCorner_Judge_Size_Min_Y_um;
|
pDefect->m_nJudge_Type = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_nTopCorner_Judge_Size_Min_OR_AND;
|
break;
|
case DefectLoc_Bot_Corner:
|
pDefect->m_nJudge_X_um = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_nBottomCorner_Judge_Size_Min_X_um;
|
pDefect->m_nJudge_Y_um = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_nBottomCorner_Judge_Size_Min_Y_um;
|
pDefect->m_nJudge_Type = m_pRecipe->m_SideParam[pDefect->m_DefectInfo.m_nSideIdx].m_nBottomCorner_Judge_Size_Min_OR_AND;
|
break;
|
default:
|
break;
|
}
|
|
return TRUE;
|
}
|
|
void CPostProcess::CalcGlassSize()
|
{
|
return;
|
/*
|
int iCam,iScan;
|
CHardwareSettings *pHard = m_pHardware;
|
CCameraSettings *pCamera;
|
double dGlasssizeY[2],dGlasssizeX[2];
|
double dGlassSizeSumY[2],dGlassSizeCntY[2];
|
double dDist;
|
CAMERA_SCANDIR ScanDirection;
|
double dScanRes;
|
double dConvRes;
|
int nStageNo = g_pBase->m_nStageNo;
|
|
if(nStageNo < 0 || nStageNo > 1)
|
nStageNo = 0;
|
|
for(iCam=0;iCam<pHard->GetCameraCount();iCam++)
|
{
|
for(iScan=0;iScan<pHard->GetScanCount();iScan++)
|
{
|
pCamera = pHard->GetCameraSettings(iCam,iScan);
|
if(pCamera == NULL)
|
continue;
|
|
ZeroMemory(dGlasssizeY,sizeof(double)*2);
|
ZeroMemory(dGlasssizeX,sizeof(double)*2);
|
|
CSide_Data* pSideData = m_pGlassData->GetSideData(pCamera->m_eDimension);
|
|
dGlasssizeX[0] = pSideData->m_nGlassEdgeXPos[0];
|
dGlasssizeX[1] = pSideData->m_nGlassEdgeXPos[1];
|
dGlasssizeY[0] = pSideData->m_nGlassStartLine;
|
dGlasssizeY[1] = pSideData->m_nGlassEndLine;
|
|
dScanRes = pCamera->m_dScanResolution[nStageNo];
|
dConvRes = pCamera->m_dConvResolution[nStageNo];
|
|
dDist = sqrt(pow((dGlasssizeX[0]*dConvRes-dGlasssizeX[1]*dConvRes),2) + pow((dGlasssizeY[0]*dScanRes-dGlasssizeY[1]*dScanRes),2));
|
if(dDist > 0)
|
{
|
ScanDirection = pCamera->m_eScanDir;
|
dGlassSizeCntY[(int)ScanDirection]++;
|
dGlassSizeSumY[(int)ScanDirection] += dDist;
|
}
|
}
|
}
|
|
// Glass Size
|
for(int i=0;i<2;i++)
|
{
|
if(dGlassSizeCntY[i] > 0)
|
m_pResultData->m_dGlassSize[i] = dGlassSizeSumY[i]/dGlassSizeCntY[i];
|
}
|
*/
|
}
|
|
void CPostProcess::MergeDefect()
|
{
|
int iCam,iDefect,iDefectDest;
|
int nDefectCount;
|
CDefect *pDefect,*pDefectDest;
|
int nMergeDistX,nMergeDistY;
|
int nRemoveCount = 0;
|
CRect rect,rectOrg,rectTgt;
|
CHardwareSettings *pHard = m_pHardware;
|
CGlassRecipe *pGlsRcp = m_pRecipe;
|
|
if(pGlsRcp == NULL)
|
return;
|
|
nMergeDistX = nMergeDistY = 5;
|
|
for(iCam=0;iCam<pHard->GetCameraCount();iCam++)
|
{
|
nDefectCount = m_pInspectCamera[iCam]->GetDefectCount();
|
|
for(iDefect=0;iDefect<nDefectCount-1;iDefect++)
|
{
|
pDefect = m_pInspectCamera[iCam]->GetDefect(iDefect);
|
if(pDefect == NULL)
|
continue;
|
|
if(pDefect->m_bDefectMergeRemoved == TRUE)
|
continue;
|
|
//if(pDefect->m_DefectLoc == DefectLoc_Chamfer)
|
// continue;
|
|
rectOrg = pDefect->m_DefectInfo.m_rtDefectPos_pxl;
|
rectOrg.InflateRect(nMergeDistX,nMergeDistY);
|
|
for(iDefectDest=iDefect+1;iDefectDest<nDefectCount;iDefectDest++)
|
{
|
pDefectDest = m_pInspectCamera[iCam]->GetDefect(iDefectDest);
|
if(pDefectDest == NULL)
|
continue;
|
|
if(pDefectDest->m_DefectInfo.m_nScanIdx != pDefect->m_DefectInfo.m_nScanIdx)
|
continue;
|
|
if(pDefectDest->m_bDefectMergeRemoved == TRUE)
|
continue;
|
|
//if(pDefectDest->m_nCamDir != pDefect->m_nCamDir)
|
// continue;
|
|
//if(pDefectDest->m_DefectLoc == DefectLoc_Chamfer)
|
// continue;
|
|
if(pDefect->m_DefectInfo.m_DefectLoc != pDefectDest->m_DefectInfo.m_DefectLoc)
|
continue;
|
|
rectTgt = pDefectDest->m_DefectInfo.m_rtDefectPos_pxl;
|
|
if(rect.IntersectRect(rectOrg,rectTgt) == TRUE)
|
{
|
pDefect->m_DefectInfo.m_rtDefectPos_pxl.left = min(pDefect->m_DefectInfo.m_rtDefectPos_pxl.left, pDefectDest->m_DefectInfo.m_rtDefectPos_pxl.left);
|
pDefect->m_DefectInfo.m_rtDefectPos_pxl.top = min(pDefect->m_DefectInfo.m_rtDefectPos_pxl.top, pDefectDest->m_DefectInfo.m_rtDefectPos_pxl.top);
|
pDefect->m_DefectInfo.m_rtDefectPos_pxl.right = max(pDefect->m_DefectInfo.m_rtDefectPos_pxl.right, pDefectDest->m_DefectInfo.m_rtDefectPos_pxl.right);
|
pDefect->m_DefectInfo.m_rtDefectPos_pxl.bottom = max(pDefect->m_DefectInfo.m_rtDefectPos_pxl.bottom, pDefectDest->m_DefectInfo.m_rtDefectPos_pxl.bottom);
|
pDefect->m_DefectInfo.m_ptDefectPos_pxl = pDefect->m_DefectInfo.m_rtDefectPos_pxl.CenterPoint();
|
pDefect->m_DefectInfo.m_nBlobCount = pDefect->m_DefectInfo.m_nBlobCount + pDefectDest->m_DefectInfo.m_nBlobCount;
|
pDefect->m_DefectInfo.m_nGray_Max = max(pDefect->m_DefectInfo.m_nGray_Max, pDefectDest->m_DefectInfo.m_nGray_Max);
|
pDefect->m_DefectInfo.m_nGray_Min = min(pDefect->m_DefectInfo.m_nGray_Min, pDefectDest->m_DefectInfo.m_nGray_Min);
|
pDefect->m_DefectInfo.m_nGray_Sum = pDefect->m_DefectInfo.m_nGray_Sum + pDefectDest->m_DefectInfo.m_nGray_Sum;
|
pDefect->m_DefectInfo.m_dGray_Avg = (pDefect->m_DefectInfo.m_dGray_Avg + pDefectDest->m_DefectInfo.m_dGray_Avg)/2.0;
|
|
pDefectDest->m_bDefectMergeRemoved = TRUE;
|
nRemoveCount++;
|
}
|
}
|
}
|
}
|
|
g_pLog->DisplayMessage(_T("Defect Merge Count : %d"), nRemoveCount);
|
}
|
|
BOOL CPostProcess::CreateDataDirectory()
|
{
|
CheckDirectory(PATH_INSPECTION_DATA);
|
m_strResultFolder.Format(_T("%s\\DATA_RESULT"),PATH_INSPECTION_DATA);
|
CheckDirectory(m_strResultFolder);
|
m_strDefectFolder.Format(_T("%s\\IMG_DEFECT\\%s\\%s"),PATH_INSPECTION_DATA,g_pBase->m_strLoadingDay,g_pBase->m_strHPanelID);
|
DeleteFolder(m_strDefectFolder);
|
CheckDirectory(m_strDefectFolder,TRUE);
|
m_strImageDLFolder.Format(_T("%s\\IMG_DEFECT_DL\\%s\\%s"), PATH_INSPECTION_DATA, g_pBase->m_strLoadingDay, g_pBase->m_strHPanelID);
|
DeleteFolder(m_strImageDLFolder);
|
CheckDirectory(m_strImageDLFolder, TRUE);
|
m_strSplineFolder.Format(_T("%s\\SPLINE\\%s\\%s"),PATH_INSPECTION_DATA,g_pBase->m_strLoadingDay,g_pBase->m_strHPanelID);
|
CheckDirectory(m_strSplineFolder);
|
m_strFullImgeFolder.Format(_T("%s\\IMG_FULL\\%s\\%s"),PATH_INSPECTION_DATA,g_pBase->m_strLoadingDay,g_pBase->m_strHPanelID);
|
CheckDirectory(m_strFullImgeFolder);
|
m_strImageMarkFolder.Format(_T("%s\\IMG_MARK\\%s\\%s"),PATH_INSPECTION_DATA,g_pBase->m_strLoadingDay,g_pBase->m_strHPanelID);
|
CheckDirectory(m_strImageMarkFolder);
|
|
return TRUE;
|
}
|
|
BOOL CPostProcess::DeleteFolder(const CString &strFolder)
|
{
|
SHFILEOPSTRUCT FileOp = {0};
|
TCHAR szTemp[MAX_PATH];
|
|
wcscpy_s(szTemp, MAX_PATH, strFolder);
|
szTemp[strFolder.GetLength() + 1] = NULL; // NULL巩磊啊 滴俺 甸绢啊具 茄促.
|
|
FileOp.hwnd = NULL;
|
FileOp.wFunc = FO_DELETE;
|
FileOp.pFrom = NULL;
|
FileOp.pTo = NULL;
|
FileOp.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI; // 犬牢皋矫瘤啊 救哆档废 汲沥
|
FileOp.fAnyOperationsAborted = false;
|
FileOp.hNameMappings = NULL;
|
FileOp.lpszProgressTitle = NULL;
|
FileOp.pFrom = szTemp;
|
|
SHFileOperation(&FileOp);
|
|
return true;
|
}
|
|
BOOL CPostProcess::CheckDirectory(const TCHAR szPathName[], BOOL bDelete)
|
{
|
CFileFind finder;
|
CString strTemp;
|
CString strDir = szPathName;
|
int nPos;
|
|
BOOL bExist = finder.FindFile(szPathName);
|
|
if(bDelete == TRUE)
|
{
|
DeleteFolder(szPathName);
|
bExist = FALSE;
|
}
|
|
if (bExist == FALSE)
|
{
|
nPos = strDir.Find(_T("\\"));
|
nPos = strDir.Find(_T("\\"), nPos+1);
|
while(nPos > 0)
|
{
|
strTemp = strDir.Mid(0,nPos);
|
if(0 < strTemp.GetLength())
|
{
|
if(CString("\\") == strTemp.GetAt(strTemp.GetLength()-1))
|
{
|
nPos = strDir.Find(_T("\\"), nPos+1);
|
continue;
|
}
|
}
|
if (finder.FindFile(strTemp) == FALSE)
|
{
|
if(::CreateDirectory(strTemp, NULL) == FALSE)
|
{
|
strTemp.Format(_T("[%s]Folder Create Fail. "), szPathName);
|
|
//LogMessage(strTemp, 2);
|
return FALSE;
|
}
|
}
|
nPos = strDir.Find(_T("\\"), nPos+1);
|
}
|
}
|
return TRUE;
|
}
|
|
CString CPostProcess::GetResultPath(EM_RESULT_PATH ePath)
|
{
|
CString str;
|
|
switch(ePath)
|
{
|
case EM_RESULT_FILE: str=m_strResultFolder; break;
|
case EM_RESULT_DEFECT: str=m_strDefectFolder; break;
|
case EM_RESULT_FULL: str=m_strFullImgeFolder; break;
|
case EM_RESULT_MARK: str=m_strImageMarkFolder; break;
|
}
|
|
return str;
|
}
|
|
int CPostProcess::MeasrueCutLineResult(DimensionDir dir)
|
{
|
if (m_pGlassData == NULL || m_pGlassData->GetGlassRecipe() == NULL)
|
return 0;
|
|
double dSun = 0;
|
int nCount = m_pGlassData->GetGlassRecipe()->m_SideParam[dir].m_nSideDimensionCount;
|
if (nCount > 0)
|
{
|
for (int i = 0; i < nCount; i++)
|
{
|
dSun += (m_pGlassData->GetSideData(dir)->m_dSideMeasrue_CutLine_Result_mm[i] + m_pGlassData->GetSideData(dir)->m_dSideMeasrue_CutLine_Offset_mm[i]);
|
}
|
return ((int)(dSun * 1000 / nCount));
|
}
|
return 0;
|
}
|