無聊的阿狼
一般會員
發表:9 回覆:6 積分:3 註冊:2005-09-13
發送簡訊給我
|
想請教各位大大
用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);
}
//---------------------------------------------------------------------------
|