影像細化的問題 |
答題得分者是:m58610
|
RK
一般會員 發表:4 回覆:5 積分:1 註冊:2004-11-02 發送簡訊給我 |
我的程式主要是想抓圖形的對稱軸..
但是空白的地方卻會跑出不想要的線條..
試了很久..真的是想不到問題出在那裡..懇請各位前輩賜教..
void __fastcall TForm1::Button5Click(TObject *Sender) { Byte *ptr, *tptr; Byte *lptr, *rptr, *midptr; int left, right; int Lpoint, Rpoint, midpoint; Graphics::TBitmap *TheBitmap, *TempBitmap; TheBitmap=Image1->Picture->Bitmap; TempBitmap= new Graphics::TBitmap(); TempBitmap->Assign(TheBitmap); for (int y=0; y < TheBitmap->Height; y++) { ptr = (Byte*)TheBitmap->ScanLine[y]; tptr = (Byte*)TempBitmap->ScanLine[y]; for (int x=0; x < TheBitmap->Width; x++) { left=x-1; right=x+1; if (left<0) left=TheBitmap->Width -1; if (right==TheBitmap->Width) right=0; if (ptr[left] == 255 && ptr[x] == 0 && ptr[right] == 0) { Lpoint = x; } if (ptr[left] == 0 && ptr[x] == 0 && ptr[right] == 255) { Rpoint = x; } tptr[x] = 255; } // end x midpoint = (Lpoint+Rpoint)/2; tptr[midpoint] = 0; }// end y TheBitmap->Assign(TempBitmap); delete TempBitmap; }發表人 - RK 於 2005/06/16 23:18:08 |
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
m58610
初階會員 發表:22 回覆:83 積分:36 註冊:2003-09-07 發送簡訊給我 |
RK你好
程式裡看了一下感覺似乎是對的
所以我也看了好多次才想到有問題
以你的程式來看..你似乎是假設所有Y軸都有中點
但是在圖片中的上面似乎不是...
所以在上面哪一段空白時...也會計算midpoint = (Lpoint Rpoint)/2;..
但是又因為空白所以Lpoint與Rpoint都沒有被程式輸入數值...
所以midpoint也不知道被算成多少...
我的建議是可以在掃描每一行Y時...先給Lpoint與Rpoint一個負值..
那如果整行都空白時..midpoint也會被計算成負值...
用一個if去判斷midpoint再決定是否要讓tptr[midpoint] = 0;
這樣應該就沒問題了
|
RK
一般會員 發表:4 回覆:5 積分:1 註冊:2004-11-02 發送簡訊給我 |
首先感謝前輩的回應!! 其實我也知道問題是應該出在空白的地方,midpoint不知道值為多少.. 剛試過先設midpoint為負值..還是不行.. 先前試過..加上一個bool變數black來做判斷..可是tptr[midpoint] = 0卻沒作用..是那裡錯了呢?
void __fastcall TForm1::Button5Click(TObject *Sender) { Byte *ptr, *tptr; Byte *lptr, *rptr, *midptr; int left, right; int Lpoint, Rpoint, midpoint; bool black; Graphics::TBitmap *TheBitmap, *Temp1Bitmap; TheBitmap=Image1->Picture->Bitmap; Temp1Bitmap= new Graphics::TBitmap(); Temp1Bitmap->Assign(TheBitmap); for (int y=0; y < TheBitmap->Height; y ) { ptr = (Byte*)TheBitmap->ScanLine[y]; tptr = (Byte*)Temp1Bitmap->ScanLine[y]; black == false; for (int x=0; x < TheBitmap->Width; x ) { left=x-1; right=x 1; if (left<0) left=TheBitmap->Width -1; if (right==TheBitmap->Width) right=0; if (ptr[left] == 255 && ptr[x] == 0 && ptr[right] == 0) { Lpoint = x; black == true; } if (ptr[left] == 0 && ptr[x] == 0 && ptr[right] == 255) { Rpoint = x; } tptr[x] = 255; } // end x if (black == true) { midpoint = (Lpoint Rpoint)/2; tptr[midpoint] = 0; } }// end y TheBitmap->Assign(Temp1Bitmap); delete Temp1Bitmap; } |
RK
一般會員 發表:4 回覆:5 積分:1 註冊:2004-11-02 發送簡訊給我 |
改成用int變數就可以了...真是不太懂QQ..
不過還是感謝大大的賜教!!
void __fastcall TForm1::Button5Click(TObject *Sender) { Byte *ptr, *tptr; Byte *lptr, *rptr, *midptr; int left, right; int Lpoint, Rpoint, midpoint; int black; Graphics::TBitmap *TheBitmap, *Temp1Bitmap; TheBitmap=Image1->Picture->Bitmap; Temp1Bitmap= new Graphics::TBitmap(); Temp1Bitmap->Assign(TheBitmap); for (int y=0; y < TheBitmap->Height; y ) { ptr = (Byte*)TheBitmap->ScanLine[y]; tptr = (Byte*)Temp1Bitmap->ScanLine[y]; black = 0; for (int x=0; x < TheBitmap->Width; x ) { left=x-1; right=x 1; if (left<0) left=TheBitmap->Width -1; if (right==TheBitmap->Width) right=0; if (ptr[left] == 255 && ptr[x] == 0 && ptr[right] == 0) { Lpoint = x; black = 1; } if (ptr[left] == 0 && ptr[x] == 0 && ptr[right] == 255) { Rpoint = x; } tptr[x] = 255; } // end x if (black == 1) { midpoint = (Lpoint Rpoint)/2; tptr[midpoint] = 0; } }// end y TheBitmap->Assign(Temp1Bitmap); delete Temp1Bitmap; } |
RK
一般會員 發表:4 回覆:5 積分:1 註冊:2004-11-02 發送簡訊給我 |
|
m58610
初階會員 發表:22 回覆:83 積分:36 註冊:2003-09-07 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |