Floating point overflow |
答題得分者是:arisaka_matsuri
|
jenglin
一般會員 發表:45 回覆:32 積分:15 註冊:2006-10-08 發送簡訊給我 |
各位前輩好:
以下程式碼執行時出現Floating point overflow,顯示這行有問題c = (F[x i][y j] - f)*(F[x i][y j] - f); 請問有人知道錯在哪嗎? [code cpp] void __fastcall TForm1::Button2Click(TObject *Sender) { Graphics::TBitmap *bmp1=new Graphics::TBitmap(); Graphics::TBitmap *bmp2=new Graphics::TBitmap(); bmp2->PixelFormat=pf24bit; bmp2->Assign(Image2->Picture->Bitmap); bmp2->Width=Image2->Width; bmp2->Height=Image2->Height; bmp1->Assign(Image1->Picture->Bitmap); bmp1->PixelFormat=pf24bit; bmp1->Width=Image1->Width; bmp1->Height=Image1->Height; M=Image1->Height; N=Image1->Width; K=Image2->Height; L=Image2->Width; double w=0; static double G[48][48]; Byte *ptr; for(int y=0; y { ptr = (Byte*)bmp2->ScanLine[y]; for(int x=0; x w = (double)(ptr[x] ptr[x 1] ptr[x 2])/3; G[x/3][y] = (double)(ptr[x] ptr[x 1] ptr[x 2])/3; } } w /= ( K*L ); static double F[320][240]; static double C[320-48][240-48]={0}; for(int y=0; y ptr = (Byte*)bmp1->ScanLine[y]; for(int x=0; x } double a=0; double b=0; double c=0; double f=0; double max=0; for(int j=0; j<(M-K);j ) { for(int i=0; i<(N-L);i ) { f=0; for(int y=j; y<(j K); y ) { for(int x=i; x<(i L); x ) f =F[x][y]; f/=(K*L); } for(int y=-48;y<=48;y ) { for(int x=-48;x<=48;x ) { a = (G[x][y] - w)*(F[x i][y j] - f); b = (G[x][y] - w)*(G[x][y] - w); c = (F[x i][y j] - f)*(F[x i][y j] - f); } } C[i][j] = a/( sqrt(b)*sqrt(c) 0.00001 ); // if(C[i][j]>=max) max=C[i][j]; } } Memo1->Lines->Add("收尋完成!!"); Memo1->Lines->Add("相關係數="); Memo1->Lines->Add(max); for(int j=0; j<240-48; j ) for(int i=0; i<320-48; i ) if(C[i][j] >= 0.9) { Image1->Canvas->Brush->Style=bsClear; Image1->Canvas->Pen->Color=clRed; Image1->Canvas->Rectangle(i,j,i 48,j 48); } } [/code] |
arisaka_matsuri
高階會員 發表:25 回覆:205 積分:231 註冊:2003-10-19 發送簡訊給我 |
陣列索引值小於零
參考你貼上的程式碼#49~57 x, y 出現負值並當作G[ ]與F[ ]的索引值 當然會出問題
編輯記錄
arisaka_matsuri 重新編輯於 2008-02-18 14:52:01, 註解 無‧
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |