線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2332
推到 Plurk!
推到 Facebook!

動態影像處理

尚未結案
無聊的阿狼
一般會員


發表:9
回覆:6
積分:3
註冊:2005-09-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-11-22 21:57:25 IP:140.128.xxx.xxx 未訂閱
想請教各位大大 用VFW擷取影像,然後做前後兩張相減,以下是小弟的程式和結果,不但不是出現我想要的結果,而且播放的速度變的“非常非常”的慢,偶爾還會當機 想請各位大大幫忙     #include #pragma hdrstop #include #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { TCanvas *csBuf = new TCanvas; HDC hDC = GetDC(Panel1->Handle); csBuf->Handle = hDC; Graphics::TBitmap *CapImg1 = new Graphics::TBitmap(); CapImg1->Width = Panel1->Width; CapImg1->Height = Panel1->Height; Graphics::TBitmap *CapImg2 = new Graphics::TBitmap(); CapImg2->Width = Panel1->Width; CapImg2->Height = Panel1->Height; Graphics::TBitmap *CapImg3 = new Graphics::TBitmap(); CapImg3->Width = Panel1->Width; CapImg3->Height = Panel1->Height; CapImg2->Assign(CapImg1); CapImg1->Canvas->CopyRect(Rect(0, 0, CapImg1->Width, CapImg1->Height),csBuf, Rect(0, 0, Panel1->Width, Panel1->Height)); int x,y; int r1,r2,r3,g1,g2,g3,b1,b2,b3; int show1,show2,show3; Byte *ptr1,*ptr2,*ptr3; for ( y = 0; y < CapImg1->Height; y++) { ptr1 = (Byte *)CapImg1->ScanLine[y]; ptr2 = (Byte *)CapImg2->ScanLine[y]; ptr3 = (Byte *)CapImg3->ScanLine[y]; for ( x = 0; x < CapImg1->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); ptr3[x*3]=(Byte)show3; ptr3[x*3+1]=(Byte)show3; ptr3[x*3+2]=(Byte)show3; Image1->Canvas->Draw(0,0,CapImg3); } } ReleaseDC(0, hDC); delete CapImg3; Form1->DoubleBuffered=true; //讓畫面不再閃爍 } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { HWND hCapWnd; hCapWnd=capCreateCaptureWindow("My Capture Window", WS_VISIBLE | WS_CHILD ,0, 0, 320, 240,Panel1->Handle, 0); //設定CaptureWindows capDriverConnect (hCapWnd, 0); //與驅動程式連結 capPreviewRate(hCapWnd,40); //每秒影像變化張數 capPreview(hCapWnd,1); } //---------------------------------------------------------------------------
taishyang
站務副站長


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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-11-23 00:22:41 IP:218.168.xxx.xxx 未訂閱
您好:    PO程式碼的方式與版規說明請參考下面連結,煩請修改謝謝您的配合 >
chilly0783
一般會員


發表:10
回覆:6
積分:8
註冊:2005-09-27

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-11-23 01:15:24 IP:59.113.xxx.xxx 未訂閱
下面這篇跟你的很像,你可以參考一下    http://delphi.ktop.com.tw/topic.php?TOPIC_ID=78538
poaivy
中階會員


發表:40
回覆:78
積分:53
註冊:2004-08-09

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-11-24 21:52:13 IP:140.117.xxx.xxx 未訂閱
你好: Graphics::TBitmap *CapImg1 = new Graphics::TBitmap(); Graphics::TBitmap *CapImg2 = new Graphics::TBitmap(); 你在程式中的TIMER一直在NEW新的TBitmap() 卻沒有看見你有做DELETE的動作 不知道是否因為這樣拖慢你整個速度呢? 發表人 - poaivy 於 2005/11/24 21:56:00
系統時間:2024-05-12 8:22:31
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!