From aa2c9d14b1b4058639d938ef7f943c7c7fc7c210 Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期四, 14 八月 2025 14:57:08 +0800
Subject: [PATCH] 1. 离线全部执行和在线执行时可以选择启用或禁用侧面检功能
---
EdgeInspector_App/InterfaceManager.cpp | 189 ++++++++++++++++++++++++++++------------------
1 files changed, 114 insertions(+), 75 deletions(-)
diff --git a/EdgeInspector_App/InterfaceManager.cpp b/EdgeInspector_App/InterfaceManager.cpp
index c1ef81f..34ff381 100644
--- a/EdgeInspector_App/InterfaceManager.cpp
+++ b/EdgeInspector_App/InterfaceManager.cpp
@@ -1,4 +1,4 @@
-#include "StdAfx.h"
+锘�#include "StdAfx.h"
#include "InterfaceManager.h"
#include "MulticamControl.h"
#include "RadientControl.h"
@@ -150,7 +150,7 @@
return 0;
}
-// End Signal阑 PLC俊辑 肋 给罐酒辑 Retry 持菌澜
+// End Signal闃� PLC淇婅緫 鑲� 缁欑綈閰掕緫 Retry 鎸佽弻婢�
void CInterfaceManager::PLCSignalRetry(SEND_MESSAGE_SECTION emSection,InspectToControlSignal emSendSignal,enInterface_Send_Control emControlSignal)
{
if(m_HardwareRecipe.m_nPLCSignalRetry <= 0)
@@ -505,7 +505,7 @@
m_PostProcess.SetView((void*) m_pView);
m_PostProcess.RunPostProcessing();
- // 馆靛矫 Scan End 脚龋 焊郴扁 傈俊 秦拎具茄促... Scan End 脚龋 焊尘锭 Loading捞 肯丰 救登搁 救焊郴瘤霸 阜囚乐澜..
+ // 棣嗛潧鐭� Scan End 鑴氶緥 鐒婇兇鎵� 鍌堜繆 绉︽嫀鍏疯寗淇�... Scan End 鑴氶緥 鐒婂皹閿� Loading鎹� 鑲赴 鏁戠櫥鎼� 鏁戠剨閮寸槫闇� 闃滃洑涔愭緶..
m_bGlassLoadingEnd = FALSE;
m_bPLCGlassLoading = FALSE;
@@ -581,13 +581,13 @@
DWORD dwTick = GetTickCount();
g_pLog->DisplayMessage(_T("Full Image Save Start"));
- int iCam,iScan;
- CHardwareSettings *pHard = &m_HardwareRecipe;
- CCameraSettings *pCamera;
- CGlassRecipe *pGlsRcp = &m_GlassRecipe;
- CString strFolder,strFileJpg,strPanelID;
- pINSPECTFULLIMAGE_BUFFER pBuffer;
- int nQuality = pHard->m_nSaveImageQuality;
+ int iCam, iScan;
+ CHardwareSettings* pHard = &m_HardwareRecipe;
+ CCameraSettings* pCamera;
+ CGlassRecipe* pGlsRcp = &m_GlassRecipe;
+ CString strFolder, strFileJpg, strPanelID;
+ pINSPECTFULLIMAGE_BUFFER pBuffer;
+ int nQuality = pHard->m_nSaveImageQuality;
if (nQuality < 0 || nQuality > 100) {
nQuality = 30;
@@ -601,24 +601,24 @@
strPanelID = _T("TestGlass");
}
- for(iCam=0;iCam<pHard->GetCameraCount();iCam++) {
- for(iScan=0;iScan<MAX_SCAN_COUNT;iScan++) {
- pCamera = pHard->GetCameraSettings(iCam,iScan);
+ for (iCam = 0; iCam < pHard->GetCameraCount(); iCam++) {
+ for (iScan = 0; iScan < MAX_SCAN_COUNT; iScan++) {
+ pCamera = pHard->GetCameraSettings(iCam, iScan);
if (pCamera == NULL) {
continue;
}
- pBuffer = m_pInspect[iCam]->GetFullImgBuffer(iScan);
+ pBuffer = m_pInspect[iCam]->GetFullImgBuffer(iScan);
if (pBuffer == NULL) {
continue;
}
g_pLog->DisplayMessage(_T("Sava %s iCam=%d, iScan=%d, szImage.cx=%ld, pBuffer->szImage.cy=%ld"), PANEL_SIDE[pCamera->m_eDimension], iCam, iScan, pBuffer->szImage.cx, pBuffer->szImage.cy);
- if(pBuffer->pImage != NULL && pBuffer->szImage.cx > 100 && pBuffer->szImage.cy > 100) {
- strFileJpg.Format(_T("%s\\%s_%s_%s.jpg"),strFolder, strPanelID, PANEL_SIDE[pCamera->m_eDimension],g_pBase->m_strLoadingTime);
+ if (pBuffer->pImage != NULL && pBuffer->szImage.cx > 100 && pBuffer->szImage.cy > 100) {
+ strFileJpg.Format(_T("%s\\%s_%s_%s.jpg"), strFolder, strPanelID, PANEL_SIDE[pCamera->m_eDimension], g_pBase->m_strLoadingTime);
SaveFullImageModern(strFileJpg, pBuffer->pImage, pBuffer->szImage.cx, pBuffer->szImage.cy, (int)pCamera->m_eDimension, 0, nQuality);
- }
+ }
}
}
g_pLog->DisplayMessage(_T("Full Image Save Completed : Time[%d]"),GetTickCount()-dwTick);
@@ -868,10 +868,15 @@
g_pStatus->m_iScanIdx = 1;
- AfxBeginThread(ScanStartCam_0,this);
- AfxBeginThread(ScanStartCam_1,this);
- AfxBeginThread(ScanStartCam_2,this);
- AfxBeginThread(ScanStartCam_3,this);
+ AfxBeginThread(ScanStartCam_0, this);
+ AfxBeginThread(ScanStartCam_1, this);
+ AfxBeginThread(ScanStartCam_2, this);
+ AfxBeginThread(ScanStartCam_3, this);
+
+ if (m_HardwareRecipe.m_bUseRipInspection) {
+ AfxBeginThread(ScanStartCam_4, this);
+ AfxBeginThread(ScanStartCam_5, this);
+ }
AfxBeginThread(CheckScanStart,this);
}
@@ -884,10 +889,15 @@
g_pStatus->m_iScanIdx = 0;
- AfxBeginThread(ScanStartCam_0,this);
- AfxBeginThread(ScanStartCam_1,this);
- AfxBeginThread(ScanStartCam_2,this);
- AfxBeginThread(ScanStartCam_3,this);
+ AfxBeginThread(ScanStartCam_0, this);
+ AfxBeginThread(ScanStartCam_1, this);
+ AfxBeginThread(ScanStartCam_2, this);
+ AfxBeginThread(ScanStartCam_3, this);
+
+ if (m_HardwareRecipe.m_bUseRipInspection) {
+ AfxBeginThread(ScanStartCam_4, this);
+ AfxBeginThread(ScanStartCam_5, this);
+ }
AfxBeginThread(CheckScanStart,this);
@@ -901,20 +911,16 @@
UINT CInterfaceManager::CheckScanStart(LPVOID pParam)
{
- CInterfaceManager *pInter = static_cast<CInterfaceManager*>(pParam);
+ CInterfaceManager *pInter = static_cast<CInterfaceManager*>(pParam);
+ double CurTime = GetTickCount();
- double CurTime = GetTickCount();
-
- do
- {
- if (GetTickCount() - CurTime > 10000)
- {
+ do {
+ if (GetTickCount() - CurTime > 10000) {
g_pLog->DisplayMessage(_T("Scan Start Ack TimeOut : Scan %d-%d"),g_pStatus->m_iScanIdx,pInter->m_nScanStartCount);
break;
}
- if(pInter->m_nScanStartCount == MAX_CAMERA_COUNT)
- {
+ if(pInter->m_nScanStartCount == MAX_CAMERA_COUNT) {
g_pLog->DisplayMessage(_T("Scan Start Ack Ok : Scan %d-%d"),g_pStatus->m_iScanIdx,pInter->m_nScanStartCount);
break;
}
@@ -923,13 +929,11 @@
} while (1);
g_pLog->DisplayMessage(_T("Scan Start Ack Signal Send : Scan %d-%d"),g_pStatus->m_iScanIdx,pInter->m_nScanStartCount);
- if(g_pStatus->m_iScanIdx == 0)
- {
+ if(g_pStatus->m_iScanIdx == 0) {
if(pInter->m_pThread_SendMSG != NULL)
pInter->m_pThread_SendMSG->AddSendMSG(SEND_MESSAGE_CONTROLSIGNAL,IToC_Ack_LongScanStartSuccess,TRUE);
}
- else
- {
+ else {
if(pInter->m_pThread_SendMSG != NULL)
pInter->m_pThread_SendMSG->AddSendMSG(SEND_MESSAGE_CONTROLSIGNAL,IToC_Ack_ShortScanStartSuccess,TRUE);
}
@@ -956,21 +960,19 @@
int nPeriod = m_HardwareRecipe.m_nFreerunPeriod;
int nExposureTime = m_HardwareRecipe.m_nFreerunExposureTime;
- CCameraSettings *pCamSettings = m_HardwareRecipe.GetCameraSettings(iCam,g_pStatus->m_iScanIdx);
-
- g_pStatus->SetGrabFrametoScan(g_pStatus->m_iScanIdx,pCamSettings->m_nGrabFrameCount);
- if(m_pGrabber[iCam] != NULL)
- {
- m_pGrabber[iCam]->GrabScanStart(g_pStatus->m_iScanIdx,bFreerun,nPeriod,nExposureTime);
+ CCameraSettings* pCamSettings = m_HardwareRecipe.GetCameraSettings(iCam, g_pStatus->m_iScanIdx);
+ g_pStatus->SetGrabFrametoScan(iCam, g_pStatus->m_iScanIdx, pCamSettings->m_nGrabFrameCount);
+ if(m_pGrabber[iCam] != NULL) {
+ m_pGrabber[iCam]->GrabScanStart(g_pStatus->m_iScanIdx, bFreerun, nPeriod, nExposureTime);
+ g_pLog->DisplayMessage(_T("Cam %d Scan %d Grab Start : GrabFrameCount %d"), iCam, g_pStatus->m_iScanIdx, pCamSettings->m_nGrabFrameCount);
+ g_pLog->DisplayMessage(_T("Cam %d Scan %d Grab Start : bFreerun %d, nPeriod %d, nExposureTime %d"),iCam, g_pStatus->m_iScanIdx, bFreerun, nPeriod, nExposureTime);
}
- if(m_pInspect[iCam] != NULL)
- {
+ if(m_pInspect[iCam] != NULL) {
m_pInspect[iCam]->SetSimulation(FALSE);
m_pInspect[iCam]->SetViewScanHWnd(m_pView->GetViewScanHWnd());
- if(m_pInspect[iCam]->ScanStart(g_pStatus->m_iScanIdx) == FALSE)
- {
+ if(m_pInspect[iCam]->ScanStart(g_pStatus->m_iScanIdx) == FALSE) {
g_pLog->DisplayMessage(_T("Cam %d Scan %d Start Fail"),iCam,g_pStatus->m_iScanIdx);
}
}
@@ -1013,6 +1015,24 @@
CInterfaceManager *pInter = static_cast<CInterfaceManager*>(pParam);
pInter->ScanStartCamera(3);
+
+ return 0;
+}
+
+UINT CInterfaceManager::ScanStartCam_4(LPVOID pParam)
+{
+ CInterfaceManager* pInter = static_cast<CInterfaceManager*>(pParam);
+
+ pInter->ScanStartCamera(4);
+
+ return 0;
+}
+
+UINT CInterfaceManager::ScanStartCam_5(LPVOID pParam)
+{
+ CInterfaceManager* pInter = static_cast<CInterfaceManager*>(pParam);
+
+ pInter->ScanStartCamera(5);
return 0;
}
@@ -1213,7 +1233,7 @@
if(!m_strReserveRecipe.IsEmpty())
{
g_pLog->DisplayMessage(_T("Apply reserve Recipe Loading - [%s]"), m_strReserveRecipe);
- if (LoadGlassRecipe(m_strReserveRecipe,TRUE)) // 鞍篮 Recipe扼档 利侩 抗距登绢 乐栏搁 促矫 肺爹茄促.
+ if (LoadGlassRecipe(m_strReserveRecipe,TRUE)) // 闉嶇 Recipe鎵兼。 鍒╀京 鎶楄窛鐧荤虎 涔愭爮鎼� 淇冪煫 鑲虹埞鑼勪績.
{
g_pLog->DisplayMessage(_T("Apply reserve Recipe Loading - [%s] : Success"), m_strReserveRecipe);
}
@@ -1227,7 +1247,7 @@
return FALSE;
}
- if (strRcp.CompareNoCase(m_GlassRecipe.GetRecipeName()) != 0) // strRecipeName 官差搁 肺爹茄促.
+ if (strRcp.CompareNoCase(m_GlassRecipe.GetRecipeName()) != 0) // strRecipeName 瀹樺樊鎼� 鑲虹埞鑼勪績.
{
if (LoadGlassRecipe(strRcp,TRUE) == FALSE)
{
@@ -1393,7 +1413,7 @@
BlVision_GetVisionRecipe()->setRecipeType(EI_VISION_RECIPE);
BlVision_GetVisionRecipe()->init();
- for (int i = 0; i < nCount; i++) { //设置分辨率
+ for (int i = 0; i < nCount; i++) { //璁剧疆鍒嗚鲸鐜�
DimensionDir eDir = (DimensionDir)(i);
CBlSideData *pSide = BlVision_GetVisionRecipe()->getSideData(eDir);
@@ -1443,7 +1463,7 @@
g_pLog->DisplayMessage( _T("CreateCamera Start!"));
//////////////////////////////////////////////////////////////////////////
- // Camera Handle 积己.
+ // Camera Handle 绉繁.
int iCam;
BOOL bRet = TRUE;
@@ -1486,8 +1506,7 @@
Param.nScanCount = g_pBase->m_nScanCount;
Param.nBoardIdx = g_pBase->m_nBoardID[iCam];
Param.nBoardCh = g_pBase->m_nBoardCh[iCam];
- Param.nImgFlipX = 0;
- Param.nBoardCh = 0;
+ Param.nImgFlipX = 0;
Param.nCameraIdx = iCam;
Param.nCameraScan = 0;
@@ -1540,7 +1559,7 @@
int nErrorCode;
int nBoardId = iCam;
- // B5 4龋扁 悸泼
+ // B5 4榫嬫墎 鎮告臣
g_pBase->m_strSBKLine = m_HardwareRecipe.GetLineID();
g_pBase->m_strSBKLine.Append(_T("#"));
@@ -1566,8 +1585,9 @@
Param.nBoardIdx = nBoardId;
}
- if(Param.nBoardIdx < 0)
+ if (Param.nBoardIdx < 0) {
Param.nBoardIdx = nBoardId;
+ }
g_pLog->DisplayMessage( _T("Grabber Board ID[%d-%d]-Init"), Param.nBoardIdx, iCam);
@@ -1821,33 +1841,46 @@
{
g_pStatus->CheckDirectory(strPath);
- BYTE* pBitBuffer;
- FIBITMAP *bitmap = NULL;
-
CString strSavePath = strPath;
strSavePath += _T(".jpg");
- bitmap = FreeImage_Allocate(IMAGE_WIDTH, nLineCnt,8);
- pBitBuffer = FreeImage_GetBits(bitmap);
- if(pBitBuffer == NULL) {
- FreeImage_Unload(bitmap);
- return FALSE;
- }
+ Lock();
+ FIBITMAP* bitmap = nullptr;
+ int nImageWidth = IMAGE_WIDTH;
+ if (iSide > DIMENSION_D_DN) {
+ nImageWidth = IMAGE_WIDTH / 2;
+ }
+ bitmap = FreeImage_Allocate(nImageWidth, nLineCnt, 8);
- LPBYTE lpImg = GetGrabBuffer((DimensionDir)iSide,ptStart.y);
- if (lpImg == NULL) {
+ if (bitmap == NULL) {
+ Unlock();
return FALSE;
}
- CopyMemory(pBitBuffer, lpImg, IMAGE_WIDTH * nLineCnt);
+ BYTE* pBitBuffer = FreeImage_GetBits(bitmap);
+ if (pBitBuffer == NULL) {
+ FreeImage_Unload(bitmap);
+ Unlock();
+ return FALSE;
+ }
+
+ LPBYTE lpImg = GetGrabBuffer((DimensionDir)iSide, ptStart.y);
+ if (lpImg == NULL) {
+ Unlock();
+ return FALSE;
+ }
+
+ CopyMemory(pBitBuffer, lpImg, nImageWidth * nLineCnt);
USES_CONVERSION;
char str_filename[1024];
sprintf_s(str_filename, "%s", W2A(strSavePath));
FreeImage_FlipVertical(bitmap);
- FreeImage_Save(FIF_JPEG, bitmap, str_filename,JPEG_FULLIMAGE_RATE);
- FreeImage_Unload(bitmap);
+ FreeImage_Save(FIF_JPEG, bitmap, str_filename, JPEG_FULLIMAGE_RATE);
+ FreeImage_Unload(bitmap);
+
+ Unlock();
return TRUE;
}
@@ -1869,6 +1902,8 @@
double tmp = 70 / 100.0;
double dRatio = 1. - tmp;
dRatio = dRatio - 0.01 < 0.0 ? 1.0 : dRatio;
+
+ g_pLog->DisplayMessage(_T("Save Full Image Start(%s, %s, %d, %d, %d)"), strPath, PANEL_SIDE[iSide], nStartY, nImgHeight, nQuality);
#if 0
IplImage* pImg = cvCreateImageHeader(cvSize(nImgWidth, nImgHeight), 8, 1);
@@ -1903,15 +1938,16 @@
cvReleaseImage(&pImgNew);
cvReleaseImageHeader(&pImg);
#else
- // 原始图像数据转 cv::Mat
+ Lock();
+ // 鍘熷鍥惧儚鏁版嵁杞� cv::Mat
cv::Mat origin(nImgHeight, nImgWidth, CV_8UC1, lpOrigin + (nImgWidth * nStartY));
- // 缩放图像
+ // 缂╂斁鍥惧儚
cv::Size szNew(static_cast<int>(nImgWidth * dRatio), static_cast<int>(nImgHeight * dRatio));
cv::Mat resized;
cv::resize(origin, resized, szNew, 0, 0, cv::INTER_LINEAR);
- // 设置 JPEG 压缩参数
+ // 璁剧疆 JPEG 鍘嬬缉鍙傛暟
std::vector<int> params = {
cv::IMWRITE_JPEG_QUALITY,
nQuality
@@ -1921,9 +1957,12 @@
std::string strFilename = W2A(strPath);
if (!cv::imwrite(strFilename, resized, params)) {
+ Unlock();
g_pLog->DisplayMessage(_T("Save Full Image Fail(%s, %s, %d), imwrite failed"), strPath, PANEL_SIDE[iSide], nStartY);
return FALSE;
}
+
+ Unlock();
#endif
g_pLog->DisplayMessage(_T("Save Full Image Success(%s, %s, %d, %d, %d)"), strPath, PANEL_SIDE[iSide], nStartY, nImgHeight, nQuality);
@@ -2020,7 +2059,7 @@
strPath.Append(_T("_NG"));
}
#else
- // 加载灰度图像
+ // 鍔犺浇鐏板害鍥惧儚
std::string strFilename = CT2A(strPath);
cv::Mat img = cv::imread(strFilename, cv::IMREAD_GRAYSCALE);
@@ -2048,7 +2087,7 @@
nHeight = img.rows;
}
else {
- // 按比例缩放
+ // 鎸夋瘮渚嬬缉鏀�
const double dRatio = 1.0 - static_cast<double>(IMAGE_COMPRESSRATIO) / 100.0;
int newWidth = static_cast<int>(img.cols / dRatio);
int newHeight = static_cast<int>(img.rows / dRatio);
--
Gitblit v1.9.3