在delphi中 如何实现 USB摄像头捕获视频显示? delphi中USB摄像头捕获视频显示程序 思路 或是有源码可以参考最好 不胜感激~~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls,Directshow9;type TForm1 = class(TForm) Button1: TButton; Panel1: TPanel; Button2: TButton; Button3: TButton; Button4: TButton; Button5: TButton; Button6: TButton; Button7: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button5Click(Sender: TObject); procedure Panel1Click(Sender: TObject); procedure Button6Click(Sender: TObject); procedure Button7Click(Sender: TObject); private { Private declarations } hWndC : THandle; //定义捕捉窗句柄 public { Public declarations } end;var Form1: TForm1;const WM_CAP_START = WM_USER;const WM_CAP_STOP = WM_CAP_START + 68;const WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10;const WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11;const WM_CAP_SAVEDIB = WM_CAP_START + 25;const WM_CAP_GRAB_FRAME = WM_CAP_START + 60;const WM_CAP_SEQUENCE = WM_CAP_START + 62;const WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20;const WM_CAP_SEQUENCE_NOFILE =WM_CAP_START+ 63;const WM_CAP_SET_OVERLAY =WM_CAP_START+ 51;const WM_CAP_SET_PREVIEW =WM_CAP_START+ 50;const WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START +6;const WM_CAP_SET_CALLBACK_ERROR=WM_CAP_START +2;const WM_CAP_SET_CALLBACK_STATUSA= WM_CAP_START +3;const WM_CAP_SET_CALLBACK_FRAME= WM_CAP_START +5;const WM_CAP_SET_SCALE=WM_CAP_START+ 53;const WM_CAP_SET_PREVIEWRATE=WM_CAP_START+ 52;const WM_CAP_DLG_VIDEOFORMAT =WM_CAP_START+ 41;const WM_CAP_DLG_VIDEOSOURCE =WM_CAP_START+ 42; //1066 打开属性设置对话框,设置对比度、亮度等。const WM_CAP_DLG_VIDEODISPLAY = WM_CAP_START + 43;//const WM_CAP_SET_SCALE =WM_CAP_START+ 53; //设置刻度 function capCreateCaptureWindowA(lpszWindowName : PCHAR; dwStyle : longint;x : integer;y : integer;nWidth : integer; nHeight : integer;ParentWin : HWND;nId : integer): HWND; STDCALL EXTERNAL 'AVICAP32.DLL';implementation{$R *.dfm}//uses Directshow9;function devwdm_SetVideoStandard(nID:longlong;VideoStandard:LONGLONG):LONGLONG;stdcall;external 'devwdm.dll';function devwdm_InitCard(nID:longlong;handle:THandle;nWidth:integer;nHeight:integer):LONGLONG;stdcall;external 'devwdm.dll';function devwdm_StartVideoPreview(nID:longlong):LONGLONG;stdcall;external 'devwdm.dll';procedure TForm1.Button1Click(Sender: TObject);begin //使用Tpanel控件来创建捕捉窗口hWndC:=CapCreateCaptureWindowA ('My Own Capture Window',WS_CHILD or WS_VISIBLE, //窗口样式Panel1.Left,//X坐标Panel1.Top,//Y坐标panel1.Width, //窗口宽panel1.Height, //窗口高Form1.Handle, //窗口句柄0); //一般为0if hWndC <> 0 thenbeginSendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);//捕捉一个视频流SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0); //得到一个设备错误SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0); //得到一个设备状态SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0);//将一个捕捉窗口与一个设备驱动相关联SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0);SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0);SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0);SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0);end;end;procedure TForm1.Button2Click(Sender: TObject);beginif hWndC <> 0 thenbeginSendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0); //将捕捉窗同驱动器断开hWndC := 0;end;//close;end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);beginif hWndC <> 0 thenbeginSendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0); //将捕捉窗同驱动器断开end;end;procedure TForm1.Button3Click(Sender: TObject);beginif hWndC <> 0 thenbeginSendMessage(hWndC,WM_CAP_FILE_SET_CAPTURE_FILEA,0,Longint(pchar('d:\test.avi')));// 录成AVISendMessage(hWndC, WM_CAP_SEQUENCE, 0, 0);end;end;procedure TForm1.Button4Click(Sender: TObject);beginif hWndC <> 0 thenbeginSendMessage(hWndC, WM_CAP_STOP, 0, 0);end;end;procedure TForm1.Button5Click(Sender: TObject);beginif hWndC <> 0 thenbeginSendMessage(hWndC,WM_CAP_SAVEDIB,0,longint(pchar('D:\test.bmp')));//截图end;end;procedure TForm1.Panel1Click(Sender: TObject);beginpanel1.Height:=Panel1.Height+10;Panel1.Width:=Panel1.Width+10;end;procedure TForm1.Button6Click(Sender: TObject);//var CaptureParms :CAPTUREPARMS ;beginSendMessage(hWndC, WM_CAP_DLG_VIDEOSOURCE, 0, 0);end;procedure TForm1.Button7Click(Sender: TObject);beginSendMessage(hWndC, WM_CAP_DLG_VIDEOFORMAT, 0, 0);end;end. 谢谢大家 三楼的jianaixhb能麻烦你给把源码给我发邮箱里吗?我没有找到资源下载 可以用directx库写,也可以用opencv库,还可以用做好的控件dspack,控件可以到www.2ccc.com下载,里面有demo,很容易就可以看懂 各位大侠帮忙看看,谢谢! 求delphi源代码!!! 关于写服务的.SERVICE delphi7中的指针问题 “缺少更新或刷新的键列信息”是什么含义? 请高手指教:QReport支持打印分页吗?打印超长表格时该怎么作? 如何写一个不使用SOCKET控件的SOCKET程序?请各位帮忙。 delphi的FORM中如何处理字幕在移动过程中出现的屏幕抖动? 请问有人会不会呀!!! 尽可能出高分求教高手!可另加分。-- 关于WebBrowser的问题, IdHTTP的使用问题? delphi 调用 vc的dll 提示 无效指针操作或内存错误(含delphi 和vc的dll源码)问题解决分数倾囊相送
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,Directshow9;type
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Panel1Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
private
{ Private declarations }
hWndC : THandle; //定义捕捉窗句柄
public
{ Public declarations }
end;var
Form1: TForm1;
const WM_CAP_START = WM_USER;
const WM_CAP_STOP = WM_CAP_START + 68;
const WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10;
const WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11;
const WM_CAP_SAVEDIB = WM_CAP_START + 25;
const WM_CAP_GRAB_FRAME = WM_CAP_START + 60;
const WM_CAP_SEQUENCE = WM_CAP_START + 62;
const WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20;
const WM_CAP_SEQUENCE_NOFILE =WM_CAP_START+ 63;
const WM_CAP_SET_OVERLAY =WM_CAP_START+ 51;
const WM_CAP_SET_PREVIEW =WM_CAP_START+ 50;
const WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START +6;
const WM_CAP_SET_CALLBACK_ERROR=WM_CAP_START +2;
const WM_CAP_SET_CALLBACK_STATUSA= WM_CAP_START +3;
const WM_CAP_SET_CALLBACK_FRAME= WM_CAP_START +5;
const WM_CAP_SET_SCALE=WM_CAP_START+ 53;
const WM_CAP_SET_PREVIEWRATE=WM_CAP_START+ 52;
const WM_CAP_DLG_VIDEOFORMAT =WM_CAP_START+ 41;
const WM_CAP_DLG_VIDEOSOURCE =WM_CAP_START+ 42; //1066 打开属性设置对话框,设置对比度、亮度等。
const WM_CAP_DLG_VIDEODISPLAY = WM_CAP_START + 43;
//const WM_CAP_SET_SCALE =WM_CAP_START+ 53; //设置刻度 function capCreateCaptureWindowA(lpszWindowName : PCHAR;
dwStyle : longint;x : integer;y : integer;nWidth : integer;
nHeight : integer;ParentWin : HWND;nId : integer): HWND;
STDCALL EXTERNAL 'AVICAP32.DLL';
implementation{$R *.dfm}
//uses Directshow9;function devwdm_SetVideoStandard(nID:longlong;VideoStandard:LONGLONG):LONGLONG;stdcall;external 'devwdm.dll';
function devwdm_InitCard(nID:longlong;handle:THandle;nWidth:integer;nHeight:integer):LONGLONG;stdcall;external 'devwdm.dll';
function devwdm_StartVideoPreview(nID:longlong):LONGLONG;stdcall;external 'devwdm.dll';procedure TForm1.Button1Click(Sender: TObject);
begin
//使用Tpanel控件来创建捕捉窗口
hWndC:=CapCreateCaptureWindowA ('My Own Capture Window',WS_CHILD or WS_VISIBLE, //窗口样式
Panel1.Left,//X坐标
Panel1.Top,//Y坐标
panel1.Width, //窗口宽
panel1.Height, //窗口高
Form1.Handle, //窗口句柄
0); //一般为0
if hWndC <> 0 then
beginSendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);
//捕捉一个视频流
SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0); //得到一个设备错误
SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0); //得到一个设备状态
SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0);
//将一个捕捉窗口与一个设备驱动相关联
SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0);
SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0);
SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0);
SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0);
end;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
if hWndC <> 0 then
begin
SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0); //将捕捉窗同驱动器断开
hWndC := 0;
end;
//close;
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if hWndC <> 0 then
begin
SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0); //将捕捉窗同驱动器断开
end;
end;procedure TForm1.Button3Click(Sender: TObject);
begin
if hWndC <> 0 then
begin
SendMessage(hWndC,WM_CAP_FILE_SET_CAPTURE_FILEA,0,Longint(pchar('d:\test.avi')));// 录成AVI
SendMessage(hWndC, WM_CAP_SEQUENCE, 0, 0);
end;
end;procedure TForm1.Button4Click(Sender: TObject);
begin
if hWndC <> 0 then
begin
SendMessage(hWndC, WM_CAP_STOP, 0, 0);
end;
end;procedure TForm1.Button5Click(Sender: TObject);
begin
if hWndC <> 0 then
begin
SendMessage(hWndC,WM_CAP_SAVEDIB,0,longint(pchar('D:\test.bmp')));//截图
end;
end;procedure TForm1.Panel1Click(Sender: TObject);
begin
panel1.Height:=Panel1.Height+10;
Panel1.Width:=Panel1.Width+10;
end;procedure TForm1.Button6Click(Sender: TObject);
//var CaptureParms :CAPTUREPARMS ;
begin
SendMessage(hWndC, WM_CAP_DLG_VIDEOSOURCE, 0, 0);
end;procedure TForm1.Button7Click(Sender: TObject);
begin
SendMessage(hWndC, WM_CAP_DLG_VIDEOFORMAT, 0, 0);
end;end.