全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:3092
推到 Plurk!
推到 Facebook!

關於sobel邊緣偵測的問題

答題得分者是:taishyang
dicky9055
一般會員


發表:20
回覆:48
積分:18
註冊:2006-08-02

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-05-03 22:28:56 IP:211.76.xxx.xxx 訂閱
下面是我參考站上大大所寫的程式
但不知為何..我將p1改成動態陣列時卻會出現記憶體存取錯誤的問題
麻煩各大大告知一下
謝謝
原始程式
<textarea class="cpp" rows="10" cols="60" name="code">int p1[640][480]; int __fastcall TForm1::Gx(int i,int j) { int p[10]; p[1]=p1[i-1][j-1]; p[2]=p1[i][j-1]; p[3]=p1[i 1][j-1]; p[4]=p1[i-1][j]; p[5]=p1[i][j]; p[6]=p1[i 1][j]; p[7]=p1[i-1][j 1]; p[8]=p1[i][j 1]; p[9]=p1[i 1][j 1]; int GX=((p[7] (p[8]*2) p[9])-(p[1] (p[2]*2) p[3])); if (GX>255) return 255; else return (abs(GX)); } //--------------------------------------------------------------------------- int __fastcall TForm1::Gy(int i,int j) { int p[10]; p[1]=p1[i-1][j-1]; p[2]=p1[i][j-1]; p[3]=p1[i 1][j-1]; p[4]=p1[i-1][j]; p[5]=p1[i][j]; p[6]=p1[i 1][j]; p[7]=p1[i-1][j 1]; p[8]=p1[i][j 1]; p[9]=p1[i 1][j 1]; int GY=((p[3] (p[6]*2) p[9])-(p[1] (p[4]*2) p[7])); if (GY>255) return 255; else return (abs(GY)); } void __fastcall TForm1::N3Click(TObject *Sender) { if (Image1->Picture->Bitmap->Empty==true) ShowMessage("請載入圖檔!!"); Graphics::TBitmap *Bmp = new Graphics::TBitmap(); Byte *ptr; Bmp->Assign(Image1->Picture->Bitmap ); for (int i=0;iHeight;i ) { ptr=(Byte*)Bmp->ScanLine[i]; for (int j=0;jWidth; j ) { p1[j][i]=ptr[j*3]; } } for (int i=0;iHeight;i ) { ptr=(Byte*)Bmp->ScanLine[i]; for (int j=0;jWidth; j ) { if ((Gx(j,i) Gy(j,i))>255) { ptr[j*3]=255; ptr[j*3 1]=255; ptr[j*3 2]=255; } else { ptr[j*3]=Gx(j,i) Gy(j,i); ptr[j*3 1]=Gx(j,i) Gy(j,i); ptr[j*3 2]=Gx(j,i) Gy(j,i); } } } Image1->Picture->Assign(Bmp); delete Bmp; } </textarea> 我修改後的程式 <textarea class="cpp" rows="10" cols="60" name="code">int __fastcall TForm1::Gx(int i,int j) { int p[10]; p[1]=ptemp[i-1][j-1]; p[2]=ptemp[i][j-1]; p[3]=ptemp[i 1][j-1]; p[4]=ptemp[i-1][j]; p[5]=ptemp[i][j]; p[6]=ptemp[i 1][j]; p[7]=ptemp[i-1][j 1]; p[8]=ptemp[i][j 1]; p[9]=ptemp[i 1][j 1]; int GX=((p[7] (p[8]*2) p[9])-(p[1] (p[2]*2) p[3])); if (GX>255) return 255; else return (abs(GX)); } int __fastcall TForm1::Gy(int i,int j) { int p[10]; p[1]=ptemp[i-1][j-1]; p[2]=ptemp[i][j-1]; p[3]=ptemp[i 1][j-1]; p[4]=ptemp[i-1][j]; p[5]=ptemp[i][j]; p[6]=ptemp[i 1][j]; p[7]=ptemp[i-1][j 1]; p[8]=ptemp[i][j 1]; p[9]=ptemp[i 1][j 1]; int GY=((p[3] (p[6]*2) p[9])-(p[1] (p[4]*2) p[7])); if (GY>255) return 255; else return (abs(GY)); } void __fastcall TForm1::N3Click(TObject *Sender) { if (Image1->Picture->Bitmap->Empty==true) ShowMessage("請載入圖檔!!"); Graphics::TBitmap *Bmp = new Graphics::TBitmap(); Byte *ptr; Bmp->Assign(Image1->Picture->Bitmap ); ptemp=new int*[Image1->Height]; for (int i=0;iHeight;i ) ptemp[i]=new int[Image1->Width]; for (int i=0;iHeight;i ) { ptr=(Byte*)Bmp->ScanLine[i]; for (int j=0;jWidth; j ) { ptemp[j][i]=ptr[j*3]; } } for (int i=0;iHeight;i ) { ptr=(Byte*)Bmp->ScanLine[i]; for (int j=0;jWidth; j ) { if ((Gx(j,i) Gy(j,i))>255) { ptr[j*3]=255; ptr[j*3 1]=255; ptr[j*3 2]=255; } else { ptr[j*3]=Gx(j,i) Gy(j,i); ptr[j*3 1]=Gx(j,i) Gy(j,i); ptr[j*3 2]=Gx(j,i) Gy(j,i); } } } Image1->Picture->Assign(Bmp); delete Bmp; } </textarea> 修改後會有記憶體存取錯誤的問題麻煩各大大告知一下謝謝
編輯記錄
dicky9055 重新編輯於 2007-05-03 22:54:51, 註解 無‧
taishyang 重新編輯於 2007-05-04 09:40:58, 註解 將文章分類成[問題]‧
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-05-04 09:54:27 IP:122.124.xxx.xxx 未訂閱
你似乎產生的是480*640而不是640*480
且資料型態可以改用BYTE
dicky9055
一般會員


發表:20
回覆:48
積分:18
註冊:2006-08-02

發送簡訊給我
#3 引用回覆 回覆 發表時間:2007-05-04 20:17:28 IP:211.76.xxx.xxx 訂閱
嗯..
果然是這個問題
謝大大了
===================引 用 taishyang 文 章===================
你似乎產生的是480*640而不是640*480
且資料型態可以改用BYTE
系統時間:2024-05-02 23:49:21
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!