1) 我的第一張圖是Golden Sample, 第二張圖是欲與Golden Sample比對的圖, 要知道這張圖和Golden Sample的差異, 15秒的原因是因為每15秒CCD就會取像並且產生一張新的圖, 這張圖就是要和Golden Sample比對的圖, 時間夠不夠, 我也在研究要怎麼樣才能在15秒內把程式跑完, 再做精簡
3) 程式碼如下, 寫得很笨, 不要笑我
void __fastcall TfrmInspection::TimerAutoModeTimer(TObject *Sender)
{
JudgeThread = new TJudgeThread(false);
}
void __fastcall TJudgeThread::Execute()
{
SetName();
//---- Place thread code here ----
while (!Terminated)
{
DIR *dir;
struct dirent *entry;
if ((dir=opendir(DIR_IMAGE_SOURCE)) == NULL)
{
frmLog->memoEvent->Lines->Add("Income image directory is not found.");
frmInspection->m_nThreadStatus = 100;
return;
}
sGoldenImageName = DIR_IMAGE_GOLDEN;
sGoldenImageName = g_RecipeInfo.sRecipeName;
sGoldenImageName = ".bmp";
while ((entry=readdir(dir)) != NULL)
{
if ((strcmp(entry->d_name,".")==0) | (strcmp(entry->d_name,"..")==0) | (ExtractFileExt(entry->d_name) != ".bmp"))
{
continue;
}
sIncomeImageName = DIR_IMAGE_SOURCE; // from c:\image
sIncomeImageName = entry->d_name;
sWHMImageName = DIR_IMAGE_WAREHOUSE;
sWHMImageName = entry->d_name;
sInspectImageName = DIR_IMAGE_INSPECTION;
sInspectImageName = entry->d_name;
frmInspection->stImageGenTime->Caption = "No define";
frmInspection->stImageMoveIn->Caption = Now().FormatString("yyyy-mm-dd hh:mm:ss");
frmInspection->imgInspection->Picture->LoadFromFile(sIncomeImageName);
frmInspection->sgImageInfo->Cells[1][1] = AnsiString(entry->d_name);
frmInspection->sgImageInfo->Cells[1][2] = g_RecipeInfo.sRecipeName;
frmInspection->sgImageInfo->Cells[1][3] = IntToStr(frmInspection->imgInspection->Picture->Width) " pixels / " IntToStr(frmInspection->imgInspection->Picture->Height) " pixels";
frmInspection->sgImageInfo->Cells[1][4] = g_RecipeInfo.sRecipeName ".bmp";
frmInspection->sgImageInfo->Cells[1][5] = "2006-09-04 20:20:50";
AnsiString sCounter = "";
int nCounterSum = 0;
AnsiString sImage = "";;
int nCounter = 0;
reg->RootKey = HKEY_LOCAL_MACHINE;
reg->OpenKey("Software\\ChipMOS\\AutoVI", false);
sCounter = reg->ReadString("SampleCounter");
if (sCounter.IsEmpty())
{
reg->WriteString("SampleCounter", "00000");
sCounter = "00000";
}
nCounterSum = sCounter.ToInt();
nCounterSum ;
nCounter = nCounterSum/10000;
sImage = DIR_ICON IntToStr(nCounter) ".bmp";
frmInspection->imgCounter1->Picture->LoadFromFile(sImage);
nCounter = (nCounterSum000)/1000;
sImage = DIR_ICON IntToStr(nCounter) ".bmp";
frmInspection->imgCounter2->Picture->LoadFromFile(sImage); // 4-
nCounter = (nCounterSum00)/100;
sImage = DIR_ICON IntToStr(nCounter) ".bmp";
frmInspection->imgCounter3->Picture->LoadFromFile(sImage); // 3-digit
nCounter = (nCounterSum0)/10;
sImage = DIR_ICON IntToStr(nCounter) ".bmp";
frmInspection->imgCounter4->Picture->LoadFromFile(sImage); // 2-digit
sImage = DIR_ICON IntToStr(nCounterSum) ".bmp";
frmInspection->imgCounter5->Picture->LoadFromFile(sImage); // 1-digit (right)
sCounter = IntToStr(nCounterSum);
reg->WriteString("SampleCounter", sCounter);
reg->CloseKey();
frmInspection->m_nThreadStatus = 50;
MakeSobelThresholdImage(sIncomeImageName, sInspectImageName);
FindTopLeft(0, sInspectImageName);
FindTopLeft(1, sGoldenImageName);
if (CompareWithSourceImage(sInspectImageName, sGoldenImageName) == 0)
{
closedir(dir);
frmInspection->m_nThreadStatus = 0;
return;
}
frmInspection->m_nThreadStatus = 1;
frmInspection->stImageMoveOut->Caption = Now().FormatString("yyyy-mm-dd hh:mm:ss");
if (FileExists(sWHMImageName))
{
remove(sWHMImageName.c_str());
}
MoveFile(sIncomeImageName.c_str(), sWHMImageName.c_str());
Sleep(50);
if (FileExists(sIncomeImageName))
{
remove(sIncomeImageName.c_str());
}
remove(m_sBuf.c_str());
}
closedir(dir);
frmInspection->m_nThreadStatus = -1;
}
}
//---------------------------------------------------------------------------
void __fastcall TJudgeThread::MakeSobelThresholdImage(AnsiString sIncomeImage, AnsiString sInspectImageName)
{
frmImage->imgSrc->Picture->Bitmap->LoadFromFile(sIncomeImage);
frmImage->imgSrc->Width = frmImage->imgSrc->Picture->Width;
frmImage->imgSrc->Picture->Bitmap->Canvas->Lock();
frmImage->imgDst->Picture->Bitmap->PixelFormat = pf8bit;
frmImage->imgDst->Width = frmImage->imgSrc->Width;
frmImage->imgDst->Height = frmImage->imgSrc->Height;
frmImage->imgDst->Picture->Bitmap->Canvas->Lock();
int p[10] = {0};
int GS;
int nWidthStart;
int nWidthEnd;
int nHeightStart;
int nHeightEnd;
nWidthStart = g_RecipeInfo.ScopeRange[0][0].x;
nWidthEnd = g_RecipeInfo.ScopeRange[0][1].x;
nHeightStart = g_RecipeInfo.ScopeRange[0][0].y;
nHeightEnd = g_RecipeInfo.ScopeRange[0][1].y;
for (int y=nHeightStart; y<=nHeightEnd; y )
{
for (int x=nWidthStart; x<=nWidthEnd; x )
{
p[1] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y-1] & 0x000000ff);
p[2] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y-1] & 0x000000ff);
p[3] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y-1] & 0x000000ff);
p[4] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y] & 0x000000ff);
p[5] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y] & 0x000000ff);
p[6] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y] & 0x000000ff);
p[7] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y 1] & 0x000000ff);
p[8] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y 1] & 0x000000ff);
p[9] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y 1] & 0x000000ff);
GS = (abs((p[3] 2*p[6] p[9])-(p[1] 2*p[4] p[7])) abs((p[7] 2*p[8] p[9])-(p[1] 2*p[2] p[3])))/2;
GS >= 80 ? GS = 255 : GS = 0;
frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x][y] = (TColor)RGB(GS,GS,GS);
}
}
if (g_RecipeInfo.ScopeRange[1][0].x != 0)
{
nWidthStart = g_RecipeInfo.ScopeRange[1][0].x;
nWidthEnd = g_RecipeInfo.ScopeRange[1][1].x;
nHeightStart = g_RecipeInfo.ScopeRange[1][0].y;
nHeightEnd = g_RecipeInfo.ScopeRange[1][1].y;
for (int y=nHeightStart; y<=nHeightEnd; y )
{
for (int x=nWidthStart; x<=nWidthEnd; x )
{
p[1] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y-1] & 0x000000ff);
p[2] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y-1] & 0x000000ff);
p[3] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y-1] & 0x000000ff);
p[4] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y] & 0x000000ff);
p[5] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y] & 0x000000ff);
p[6] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y] & 0x000000ff);
p[7] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y 1] & 0x000000ff);
p[8] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y 1] & 0x000000ff);
p[9] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y 1] & 0x000000ff);
GS = (abs((p[3] 2*p[6] p[9])-(p[1] 2*p[4] p[7])) abs((p[7] 2*p[8] p[9])-(p[1] 2*p[2] p[3])))/2;
GS >= 80 ? GS = 255 : GS = 0;
frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x][y] = (TColor)RGB(GS,GS,GS);
}
}
}
if (g_RecipeInfo.ScopeRange[2][0].x != 0)
{
nWidthStart = g_RecipeInfo.ScopeRange[2][0].x;
nWidthEnd = g_RecipeInfo.ScopeRange[2][1].x;
nHeightStart = g_RecipeInfo.ScopeRange[2][0].y;
nHeightEnd = g_RecipeInfo.ScopeRange[2][1].y;
for (int y=nHeightStart; y<=nHeightEnd; y )
{
for (int x=nWidthStart; x<=nWidthEnd; x )
{
p[1] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y-1] & 0x000000ff);
p[2] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y-1] & 0x000000ff);
p[3] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y-1] & 0x000000ff);
p[4] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y] & 0x000000ff);
p[5] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y] & 0x000000ff);
p[6] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y] & 0x000000ff);
p[7] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y 1] & 0x000000ff);
p[8] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y 1] & 0x000000ff);
p[9] = (frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y 1] & 0x000000ff);
GS = (abs((p[3] 2*p[6] p[9])-(p[1] 2*p[4] p[7])) abs((p[7] 2*p[8] p[9])-(p[1] 2*p[2] p[3])))/2;
GS >= 80 ? GS = 255 : GS = 0;
frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x][y] = (TColor)RGB(GS,GS,GS);
}
}
}
frmImage->imgDst->Picture->SaveToFile(sInspectImageName);
frmImage->imgDst->Picture->Bitmap->Canvas->Unlock();
frmImage->imgSrc->Picture->Bitmap->Canvas->Unlock();
}
//---------------------------------------------------------------------------
void __fastcall TJudgeThread::FindTopLeft(int nPicID, AnsiString sImageFile)
{
if (nPicID == 1)
frmImage->imgSrc->Picture->Bitmap->LoadFromFile(sImageFile); //golden
else
frmImage->imgDst->Picture->Bitmap->LoadFromFile(sImageFile);
int nValue = 0;
for (int y=g_RecipeInfo.ScopeRange[0][0].y; y<=g_RecipeInfo.ScopeRange[0][1].y; y )
{
for (int x=g_RecipeInfo.ScopeRange[0][0].x; x<=g_RecipeInfo.ScopeRange[0][1].x; x )
{
nValue = GetRValue(frmImage->imgSrc->Canvas->Pixels[x][y]);
if (nValue == 255)
{
tpTopLeft[nPicID][0].x = x;
tpTopLeft[nPicID][0].y = y;
break;
}
}
}
nValue = 0;
if (g_RecipeInfo.ScopeRange[1][0].x != 0)
{
for (int y=g_RecipeInfo.ScopeRange[1][0].y; y<=g_RecipeInfo.ScopeRange[1][1].y; y )
{
for (int x=g_RecipeInfo.ScopeRange[1][0].x; x<=g_RecipeInfo.ScopeRange[1][1].x; x )
{
nValue = GetRValue(frmImage->imgSrc->Canvas->Pixels[x][y]);
if (nValue == 255)
{
tpTopLeft[nPicID][1].x = x;
tpTopLeft[nPicID][1].y = y;
break;
}
}
}
}
nValue = 0;
if (g_RecipeInfo.ScopeRange[2][0].x != 0)
{
for (int y=g_RecipeInfo.ScopeRange[2][0].y; y<=g_RecipeInfo.ScopeRange[2][1].y; y )
{
for (int x=g_RecipeInfo.ScopeRange[2][0].x; x<=g_RecipeInfo.ScopeRange[2][1].x; x )
{
nValue = GetRValue(frmImage->imgSrc->Canvas->Pixels[x][y]);
if (nValue == 255)
{
tpTopLeft[nPicID][2].x = x;
tpTopLeft[nPicID][2].y = y;
break;
}
}
}
}
}
//---------------------------------------------------------------------------
int __fastcall TJudgeThread::CompareWithSourceImage(AnsiString sInspImageName, AnsiString sGoldenImageName)
{
frmImage->imgSrc->Picture->Bitmap->LoadFromFile(sGoldenImageName);
frmImage->imgDst->Picture->Bitmap->LoadFromFile(sInspImageName);
int nWidthStart;
int nWidthEnd;
int nHeightStart;
int nHeightEnd;
int nSrc[25] = {0};
int nDst[25] = {0};
int nSubSrc = 0;
int nSubDst = 0;
long nPercentSrc;
long nPercentDst;
long nRslt;
int nDistX = tpTopLeft[0][0].x - tpTopLeft[1][0].x;
int nDistY = tpTopLeft[0][0].y - tpTopLeft[1][0].y;
nWidthStart = g_RecipeInfo.ScopeRange[0][0].x;
nWidthEnd = g_RecipeInfo.ScopeRange[0][1].x;
nHeightStart = g_RecipeInfo.ScopeRange[0][0].y;
nHeightEnd = g_RecipeInfo.ScopeRange[0][1].y;
int nJudge = 1;
for (int y=(nHeightStart 2); y<=(nHeightEnd-2); y =5)
{
for (int x=(nWidthStart 2); x<=(nWidthEnd-2); x =5)
{
nSrc[0] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-2][y-2]);
nSrc[1] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y-2]);
nSrc[2] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y-2]);
nSrc[3] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y-2]);
nSrc[4] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 2][y-2]);
nSrc[5] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-2][y-1]);
nSrc[6] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y-1]);
nSrc[7] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y-1]);
nSrc[8] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y-1]);
nSrc[9] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 2][y-1]);
nSrc[10] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-2][y]);
nSrc[11] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y]);
nSrc[12] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y]);
nSrc[13] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y]);
nSrc[14] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 2][y]);
nSrc[15] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-2][y 1]);
nSrc[16] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y 1]);
nSrc[17] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y 1]);
nSrc[18] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y 1]);
nSrc[19] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 2][y 1]);
nSrc[20] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-2][y 2]);
nSrc[21] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y 2]);
nSrc[22] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y 2]);
nSrc[23] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y 2]);
nSrc[24] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 2][y 2]);
nDst[0] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-2-nDistX][y-2-nDistY]);
nDst[1] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-1-nDistX][y-2-nDistY]);
nDst[2] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-nDistX][y-2-nDistY]);
nDst[3] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 1-nDistX][y-2-nDistY]);
nDst[4] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 2-nDistX][y-2-nDistY]);
nDst[5] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-2-nDistX][y-1-nDistY]);
nDst[6] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-1-nDistX][y-1-nDistY]);
nDst[7] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-nDistX][y-1-nDistY]);
nDst[8] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 1-nDistX][y-1-nDistY]);
nDst[9] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 2-nDistX][y-1-nDistY]);
nDst[10] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-2-nDistX][y-nDistY]);
nDst[11] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-1-nDistX][y-nDistY]);
nDst[12] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-nDistX][y-nDistY]);
nDst[13] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 1-nDistX][y-nDistY]);
nDst[14] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 2-nDistX][y-nDistY]);
nDst[15] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-2-nDistX][y 1-nDistY]);
nDst[16] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-1-nDistX][y 1-nDistY]);
nDst[17] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-nDistX][y 1-nDistY]);
nDst[18] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 1-nDistX][y 1-nDistY]);
nDst[19] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 2-nDistX][y 1-nDistY]);
nDst[20] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-2-nDistX][y 2-nDistY]);
nDst[21] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-1-nDistX][y 2-nDistY]);
nDst[22] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-nDistX][y 2-nDistY]);
nDst[23] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 1-nDistX][y 2-nDistY]);
nDst[24] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 2-nDistX][y 2-nDistY]);
nSubSrc = 0;
nSubDst = 0;
for (int x=0; x<25; x )
{
if (nSrc[x] == 255)
{
nSubSrc ;
}
if (nDst[x] == 255)
{
nSubDst ;
}
}
nSubSrc > 12 ? nPercentSrc = nSubSrc/25 : nPercentSrc = (25-nSubSrc)/25;
nSubDst > 12 ? nPercentDst = nSubDst/25 : nPercentDst = (25-nSubDst)/25;
nPercentSrc > nPercentDst ? nRslt = nPercentDst/nPercentSrc : nRslt = nPercentSrc/nPercentDst;
if (nRslt < 0.6)
{
nJudge = 0;
break;
}
}
}
if (nJudge == 0)
{
return 0;
}
if (g_RecipeInfo.ScopeRange[1][0].x != 0)
{
nWidthStart = g_RecipeInfo.ScopeRange[1][0].x;
nWidthEnd = g_RecipeInfo.ScopeRange[1][1].x;
nHeightStart = g_RecipeInfo.ScopeRange[1][0].y;
nHeightEnd = g_RecipeInfo.ScopeRange[1][1].y;
nDistX = tpTopLeft[0][1].x - tpTopLeft[1][1].x;
nDistY = tpTopLeft[0][1].y - tpTopLeft[1][1].y;
for (int y=(nHeightStart 2); y<=(nHeightEnd-2); y =5)
{
for (int x=(nWidthStart 2); x<=(nWidthEnd-2); x =5)
{
nSrc[0] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-2][y-2]);
nSrc[1] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y-2]);
nSrc[2] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y-2]);
nSrc[3] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y-2]);
nSrc[4] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 2][y-2]);
nSrc[5] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-2][y-1]);
nSrc[6] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y-1]);
nSrc[7] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y-1]);
nSrc[8] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y-1]);
nSrc[9] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 2][y-1]);
nSrc[10] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-2][y]);
nSrc[11] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y]);
nSrc[12] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y]);
nSrc[13] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y]);
nSrc[14] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 2][y]);
nSrc[15] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-2][y 1]);
nSrc[16] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y 1]);
nSrc[17] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y 1]);
nSrc[18] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y 1]);
nSrc[19] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 2][y 1]);
nSrc[20] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-2][y 2]);
nSrc[21] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y 2]);
nSrc[22] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y 2]);
nSrc[23] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y 2]);
nSrc[24] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 2][y 2]);
nDst[0] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-2-nDistX][y-2-nDistY]);
nDst[1] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-1-nDistX][y-2-nDistY]);
nDst[2] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-nDistX][y-2-nDistY]);
nDst[3] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 1-nDistX][y-2-nDistY]);
nDst[4] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 2-nDistX][y-2-nDistY]);
nDst[5] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-2-nDistX][y-1-nDistY]);
nDst[6] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-1-nDistX][y-1-nDistY]);
nDst[7] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-nDistX][y-1-nDistY]);
nDst[8] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 1-nDistX][y-1-nDistY]);
nDst[9] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 2-nDistX][y-1-nDistY]);
nDst[10] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-2-nDistX][y-nDistY]);
nDst[11] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-1-nDistX][y-nDistY]);
nDst[12] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-nDistX][y-nDistY]);
nDst[13] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 1-nDistX][y-nDistY]);
nDst[14] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 2-nDistX][y-nDistY]);
nDst[15] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-2-nDistX][y 1-nDistY]);
nDst[16] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-1-nDistX][y 1-nDistY]);
nDst[17] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-nDistX][y 1-nDistY]);
nDst[18] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 1-nDistX][y 1-nDistY]);
nDst[19] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 2-nDistX][y 1-nDistY]);
nDst[20] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-2-nDistX][y 2-nDistY]);
nDst[21] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-1-nDistX][y 2-nDistY]);
nDst[22] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-nDistX][y 2-nDistY]);
nDst[23] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 1-nDistX][y 2-nDistY]);
nDst[24] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 2-nDistX][y 2-nDistY]);
nSubSrc = 0;
nSubDst = 0;
for (int x=0; x<25; x )
{
if (nSrc[x] == 255)
{
nSubSrc ;
}
if (nDst[x] == 255)
{
nSubDst ;
}
}
nSubSrc > 12 ? nPercentSrc = nSubSrc/25 : nPercentSrc = (25-nSubSrc)/25;
nSubDst > 12 ? nPercentSrc = nSubSrc/25 : nPercentSrc = (25-nSubSrc)/25;
nPercentSrc > nPercentDst ? nRslt = nPercentDst/nPercentSrc : nRslt = nPercentSrc/nPercentDst;
if (nRslt < 0.6)
{
nJudge = 0;
break;
}
}
}
if (nJudge == 0)
{
return 0;
}
}
if (g_RecipeInfo.ScopeRange[2][0].x != 0)
{
nWidthStart = g_RecipeInfo.ScopeRange[2][0].x;
nWidthEnd = g_RecipeInfo.ScopeRange[2][1].x;
nHeightStart = g_RecipeInfo.ScopeRange[2][0].y;
nHeightEnd = g_RecipeInfo.ScopeRange[2][1].y;
nDistX = tpTopLeft[0][2].x - tpTopLeft[1][2].x;
nDistY = tpTopLeft[0][2].y - tpTopLeft[1][2].y;
for (int y=(nHeightStart 2); y<=(nHeightEnd-2); y =5)
{
for (int x=(nWidthStart 2); x<=(nWidthEnd-2); x =5)
{
nSrc[0] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-2][y-2]);
nSrc[1] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y-2]);
nSrc[2] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y-2]);
nSrc[3] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y-2]);
nSrc[4] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 2][y-2]);
nSrc[5] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-2][y-1]);
nSrc[6] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y-1]);
nSrc[7] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y-1]);
nSrc[8] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y-1]);
nSrc[9] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 2][y-1]);
nSrc[10] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-2][y]);
nSrc[11] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y]);
nSrc[12] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y]);
nSrc[13] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y]);
nSrc[14] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 2][y]);
nSrc[15] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-2][y 1]);
nSrc[16] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y 1]);
nSrc[17] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y 1]);
nSrc[18] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y 1]);
nSrc[19] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 2][y 1]);
nSrc[20] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-2][y 2]);
nSrc[21] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x-1][y 2]);
nSrc[22] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x][y 2]);
nSrc[23] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 1][y 2]);
nSrc[24] = GetRValue(frmImage->imgSrc->Picture->Bitmap->Canvas->Pixels[x 2][y 2]);
nDst[0] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-2-nDistX][y-2-nDistY]);
nDst[1] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-1-nDistX][y-2-nDistY]);
nDst[2] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-nDistX][y-2-nDistY]);
nDst[3] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 1-nDistX][y-2-nDistY]);
nDst[4] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 2-nDistX][y-2-nDistY]);
nDst[5] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-2-nDistX][y-1-nDistY]);
nDst[6] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-1-nDistX][y-1-nDistY]);
nDst[7] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-nDistX][y-1-nDistY]);
nDst[8] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 1-nDistX][y-1-nDistY]);
nDst[9] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 2-nDistX][y-1-nDistY]);
nDst[10] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-2-nDistX][y-nDistY]);
nDst[11] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-1-nDistX][y-nDistY]);
nDst[12] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-nDistX][y-nDistY]);
nDst[13] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 1-nDistX][y-nDistY]);
nDst[14] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 2-nDistX][y-nDistY]);
nDst[15] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-2-nDistX][y 1-nDistY]);
nDst[16] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-1-nDistX][y 1-nDistY]);
nDst[17] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-nDistX][y 1-nDistY]);
nDst[18] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 1-nDistX][y 1-nDistY]);
nDst[19] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 2-nDistX][y 1-nDistY]);
nDst[20] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-2-nDistX][y 2-nDistY]);
nDst[21] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-1-nDistX][y 2-nDistY]);
nDst[22] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x-nDistX][y 2-nDistY]);
nDst[23] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 1-nDistX][y 2-nDistY]);
nDst[24] = GetRValue(frmImage->imgDst->Picture->Bitmap->Canvas->Pixels[x 2-nDistX][y 2-nDistY]);
nSubSrc = 0;
nSubDst = 0;
for (int x=0; x<25; x )
{
if (nSrc[x] == 255)
{
nSubSrc ;
}
if (nDst[x] == 255)
{
nSubDst ;
}
}
nSubSrc > 12 ? nPercentSrc = nSubSrc/25 : nPercentSrc = (25-nSubSrc)/25;
nSubDst > 12 ? nPercentSrc = nSubSrc/25 : nPercentSrc = (25-nSubSrc)/25;
nPercentSrc > nPercentDst ? nRslt = nPercentDst/nPercentSrc : nRslt = nPercentSrc/nPercentDst;
if (nRslt < 0.6)
{
nJudge = 0;
break;
}
}
}
if (nJudge == 0)
{
return 0;
}
}
return 1;
}
//---------------------------------------------------------------------------
===================引 用 文 章===================
你好,請問 :
1/ 為何想在15秒內做完? 時間夠嗎?
2/Timer本身就是一種thread,理論上應該不會跑的時候就當死,除非timer裡的code花很多很多的時間。
3/ 可是你又一定要15秒完成? 這樣有矛盾。方便把Timer 裡的code貼一下嗎?