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

webcam影像顯示於Image1??

尚未結案
cls9215
一般會員


發表:18
回覆:28
積分:9
註冊:2004-12-21

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-01-03 13:31:33 IP:61.70.xxx.xxx 未訂閱
我是想要將用vfw所擷取的影像秀在Image1上,參考了前輩的做法,但是不行...是不是還缺少什麼呢?? //---------------------------------------------------------------------------    #include  #pragma hdrstop #include "Unit1.h" #include "vfw.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- LPVIDEOHDR VideoStr; HWND ghCapWnd; __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { int i; String msg=""; capCreateCaptureWindow("My Capture Window", WS_CHILD | WS_VISIBLE,0, 0,352,288,ghCapWnd, 0); //³]©wCaptureWindows Panel1->Width=352; Panel1->Height=288; i=int(capDriverConnect (ghCapWnd, 0)); //»PÅX°Êµ{¦¡³sµ² if (i==1) msg="webcam ¤w³s½u!!"; else msg="webcam³s½u¥¢±Ñ!!"; ShowMessage(msg); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { capPreview(ghCapWnd,true); //§ì¨ú¼v¹³¥X²{¦bµøµ¡¤¤ capPreviewScale(ghCapWnd,true); //¨Ï¼v¹³©µ¦ù¨ì©Ò³]©wªºµøµ¡¤j¤p capPreviewRate(ghCapWnd, 1000/30); //¨C¬í¼v¹³ÅܤƱi¼Æ } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { String msg2="WebCam¤w°±¤îÂ^¨ú!!"; capPreview(ghCapWnd,false); ShowMessage(msg2); Close(); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button3Click(TObject *Sender) { capSetCallbackOnFrame (ghCapWnd, &FrameCallBack); } //--------------------------------------------------------------------------- LRESULT CALLBACK FrameCallBack( HWND hwnd, Longint lpvhdr ) { static BITMAPINFOHEADER BitmapHead; static BITMAPINFO BitmapInfo; static BITMAPFILEHEADER BitmapFileHead; CAPSTATUS status; int BIHsize, byte; Byte *ptr; TMemoryStream *stream = new TMemoryStream; VideoStr=LPVIDEOHDR(lpvhdr); capGetStatus( ghCapWnd, &status, sizeof(status) ) ; BIHsize=capGetVideoFormatSize( ghCapWnd ); capGetVideoFormat( ghCapWnd, &BitmapHead, BIHsize); BitmapInfo.bmiHeader=BitmapHead; stream->Size=sizeof(BitmapFileHead) sizeof(BitmapHead) BitmapHead.biSizeImage; BitmapFileHead.bfType=0x4D42; BitmapFileHead.bfSize=stream->Size; BitmapFileHead.bfOffBits=sizeof(BitmapFileHead) sizeof(BitmapHead); // ???imagedata?? stream->Position=0; stream->WriteBuffer( &BitmapFileHead, sizeof(BitmapFileHead) ); stream->WriteBuffer( &BitmapInfo, sizeof(BitmapInfo) ); (void*)ptr=stream->Memory; ptr = BitmapFileHead.bfOffBits; Move( VideoStr->lpData, ptr, BitmapHead.biSizeImage); stream->Position=0; Form1->Image1->Picture->Bitmap->LoadFromStream( stream ); delete( stream ); capSetCallbackOnFrame (ghCapWnd, NULL); return(0); } 編譯後會出現: [C Error] Unit1.cpp(50): E2451 Undefined symbol 'FrameCallBack' 是什麼原因呢?? 或是有提供vfw擷取影像至Image1的程式可以下載來參考??(之前看有些網友說可以下載的到??)
KENI_LIN
中階會員


發表:86
回覆:267
積分:90
註冊:2004-05-31

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-01-04 08:22:20 IP:61.66.xxx.xxx 未訂閱
你少加一個定義,麻煩你在TForm1 *Form1;底下再加以下這一組: LRESULT CALLBACK FrameCallBack(HWND,Longint);//宣告callbackonframe函式    這樣應該就沒問題了!! 寒窗苦讀十年書;只待今朝狀元時!~~ ︵ / / ︵ ( ∩ ∩ ) ○ ︶ ○
------
Keni Lin
cls9215
一般會員


發表:18
回覆:28
積分:9
註冊:2004-12-21

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-01-06 12:44:20 IP:61.70.xxx.xxx 未訂閱
//---------------------------------------------------------------------------    #include  #pragma hdrstop #include "Unit2.h" #include "vfw.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; LRESULT CALLBACK FrameCallBack(HWND,Longint);//«Å§icallbackonframe¨ç¦¡ //--------------------------------------------------------------------------- LPVIDEOHDR VideoStr; HWND ghCapWnd; __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { int i; String msg=""; hCapWnd=capCreateCaptureWindow("My Capture Window", WS_CHILD | WS_VISIBLE,0, 0,352,288,ghCapWnd, 0); //³]©wCaptureWindows i=int(capDriverConnect (ghCapWnd, 0)); //»PÅX°Êµ{¦¡³sµ² if (i=1) msg="webcam ¤w³s½u!!"; else msg="webcam³s½u¥¢±Ñ!!"; ShowMessage(msg); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { capPreview(ghCapWnd,true); //§ì¨ú¼v¹³¥X²{¦bµøµ¡¤¤ FrameCallBack(ghCapWnd,1000); capPreviewScale(ghCapWnd,true); //¨Ï¼v¹³©µ¦ù¨ì©Ò³]©wªºµøµ¡¤j¤p capPreviewRate(ghCapWnd, 1000/30); //¨C¬í¼v¹³ÅܤƱi¼Æ } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { String msg2="WebCam¤w°±¤îÂ^¨ú!!"; capPreview(ghCapWnd,false); ShowMessage(msg2); Close(); } //--------------------------------------------------------------------------- LRESULT CALLBACK FrameCallBack( HWND hwnd, Longint lpvhdr ) { static BITMAPINFOHEADER BitmapHead; static BITMAPINFO BitmapInfo; static BITMAPFILEHEADER BitmapFileHead; CAPSTATUS status; int BIHsize, byte; Byte *ptr; TMemoryStream *stream = new TMemoryStream; VideoStr=LPVIDEOHDR(lpvhdr); capGetStatus( ghCapWnd, &status, sizeof(status) ) ; BIHsize=capGetVideoFormatSize( ghCapWnd ); capGetVideoFormat( ghCapWnd, &BitmapHead, BIHsize); BitmapInfo.bmiHeader=BitmapHead; stream->Size=sizeof(BitmapFileHead) sizeof(BitmapHead) BitmapHead.biSizeImage; BitmapFileHead.bfType=0x4D42; BitmapFileHead.bfSize=stream->Size; BitmapFileHead.bfOffBits=sizeof(BitmapFileHead) sizeof(BitmapHead); // ???imagedata?? stream->Position=0; stream->WriteBuffer( &BitmapFileHead, sizeof(BitmapFileHead) ); stream->WriteBuffer( &BitmapInfo, sizeof(BitmapInfo) ); (void*)ptr=stream->Memory; ptr = BitmapFileHead.bfOffBits; Move( VideoStr->lpData, ptr, BitmapHead.biSizeImage); stream->Position=0; Form1->Image1->Picture->Bitmap->LoadFromStream( stream ); delete( stream ); capSetCallbackOnFrame (ghCapWnd, NULL); return(0); } 加上函數的宣告後,就可以執行了....但是當我按下button1要執行影像擷取時,會出現有關memory的錯誤,我想是不是函式呼叫的參數數入錯誤了?? 另外我想請教,"LRESULT CALLBACK"是什麼樣的資料型態??什麼時候可以用??
KENI_LIN
中階會員


發表:86
回覆:267
積分:90
註冊:2004-05-31

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-01-06 18:13:51 IP:220.228.xxx.xxx 未訂閱
"LRESULT CALLBACK"主要是定義長變數&FrameCallBack,當然是做影像擷取時使用! 我注意一下你的程式,雖然和你同樣用> #> #> //--------------------------------------------------------------------------- #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
------
Keni Lin
cls9215
一般會員


發表:18
回覆:28
積分:9
註冊:2004-12-21

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-01-08 13:23:36 IP:61.70.xxx.xxx 未訂閱
KENI LIN大大....真的太感謝您了....我會試試看的...若有不了解 的地方,還希望您能不吝賜教!!!
wccheng
一般會員


發表:5
回覆:4
積分:1
註冊:2005-06-11

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-06-12 03:52:59 IP:61.66.xxx.xxx 未訂閱
引言: "LRESULT CALLBACK"主要是定義長變數&FrameCallBack,當然是做影像擷取時使用! 我注意一下你的程式,雖然和你同樣用> #> #> //--------------------------------------------------------------------------- #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>< face="Verdana, Arial, Helvetica"> 你好,我執行button4功能時會出錯,請問這是什麼原因?謝謝你的答覆。 發表人 - wccheng 於 2005/06/12 03:54:46 發表人 - wccheng 於 2005/06/12 03:56:07
系統時間:2024-05-02 6:28:07
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!