影像相減的時間問題之Timer |
尚未結案
|
qemoumou
一般會員 發表:8 回覆:5 積分:2 註冊:2005-11-05 發送簡訊給我 |
我參考 http://delphi.ktop.com.tw/topic.php?topic_id=26723
希望能由WebCam擷取圖像來做前景背景的區分
當我載入一張背景、一張有目標物+背景的圖
利用一個按鈕
能夠成功的分辨出 該目標物
但是當我將程式碼
放入Timer元件底下
跑出來就是一片空白....想請大大們救救我
void __fastcall TForm1::Timer1Timer(TObject *Sender) { capFileSaveDIB(ghCapWnd1,"picture1.bmp"); capFileSaveDIB(ghCapWnd1,"picture2.bmp"); Image1->Picture->LoadFromFile("picture1.bmp"); Image2->Picture->LoadFromFile("picture2.bmp"); Graphics::TBitmap *Bitmap1=new Graphics::TBitmap; Graphics::TBitmap *Bitmap2=new Graphics::TBitmap; Graphics::TBitmap *Bitmap3=new Graphics::TBitmap; int Width,Height,b1,g1,r1,b2,g2,r2,x,y,show1,show2,show3; Byte *ptr1,*ptr2,*ptr3; Bitmap1= Image1->Picture->Bitmap; Bitmap2= Image2->Picture->Bitmap; Bitmap3= Image2->Picture->Bitmap; for ( y = 0; y < Bitmap1->Height; y++) { ptr1 = (Byte *)Bitmap1->ScanLine[y]; ptr2 = (Byte *)Bitmap2->ScanLine[y]; ptr3 = (Byte *)Bitmap3->ScanLine[y]; for ( x = 0; x < Bitmap1->Width; x++) { b1=ptr1[x*3]; g1=ptr1[x*3+1]; r1=ptr1[x*3+2]; b2=ptr2[x*3]; g2=ptr2[x*3+1]; r2=ptr2[x*3+2]; show1=(0.299*r1+0.587*g1+0.114*b1); show2=(0.299*r2+0.587*g2+0.114*b2); show3=abs(show1-show2); if (show3>100) { } else { show3=255; } ptr3[x*3]=(Byte)show3; ptr3[x*3+1]=(Byte)show3; ptr3[x*3+2]=(Byte)show3; } } Image3->Picture->Assign(Bitmap2); } |
無故障
一般會員 發表:17 回覆:69 積分:17 註冊:2004-03-11 發送簡訊給我 |
|
n890377
一般會員 發表:17 回覆:16 積分:21 註冊:2006-07-13 發送簡訊給我 |
這2張圖看起來都是一樣的圖,如果你是把這2張相減當然是空白 如果不是的話:以下的code你參考一下 我都是習慣這樣寫 而且我的相減是可以跑出來 Bitmap3= Image2->Picture->Bitmap; if (show3<threshold)
else
threshold會影響你的結果 你再試看看要調多少
------
. |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |