摄像头捕捉视频的问题...(100分)

  • 主题发起人 主题发起人 Endo
  • 开始时间 开始时间
E

Endo

Unregistered / Unconfirmed
GUEST, unregistred user!
从网络下载了一个 vfw.pas (video for windows)
里面有带一个Demo 我想改用线程实现 为什么老是出错?如下:
Variable required

源码如下:
unit U_SendVideoThread;

interface
uses
classes, {Sockets,} U_XML, SysUtils, IdBaseComponent, IdComponent, IdUDPBase,
IdUDPClient, U_vfw, Jpeg, Graphics,
forms, windows, mmsystem;

type
TBitMap_tmp = class(TBitmap) //防止和windows中的 TBitMap 冲突
end;


type
TSendVideoThread = class(TThread)
private
IdUDPClient: TIdUDPClient;
//StatuStr: string;
Ftimeout: integer;
Fsleeptime: integer;
protected
procedure execute;
override;
function FrameCallBack(hWnd: HWND;
lpVHdr: PVIDEOHDR): LongInt;stdcall;
procedure SendVideo;
public
constructor create(hostip, hostport: string;
sleeptime, timeout: integer);
virtual;
destructor destroy;
override;
end;

implementation

uses U_Main, U_GlobalVar;

{ TSendVideoThread }


constructor TSendVideoThread.create(hostip, hostport: string;
sleeptime, timeout: integer);
begin

inherited create(True);
FreeOnTerminate := True;
IdUDPClient := TIdUDPClient.create(nil);
IdUDPClient.Host := HostIp;
IdUDPClient.Port := StrToInt(HostPort);
fsleeptime := sleeptime;
ftimeout := timeout;
Resume;
end;


destructor TSendVideoThread.destroy;
begin

FreeAndNil(IdUDPClient);
inherited;
end;


procedure TSendVideoThread.execute;
begin

inherited;
while not Terminateddo

begin

try
Synchronize(SendVideo);
except
//
end;

sleep(fsleeptime);
end;

end;


function TSendVideoThread.FrameCallBack(hWnd: HWND;
lpVHdr: PVIDEOHDR): LongInt;
var hd:Thandle;
jpg:TJpegImage;
memStream :TMemoryStream;
Bitmap:TBitMap_tmp;
begin

//将数据显在Image,
//Bitmap := Graphics.TBitmap.Create;
Bitmap:=TBitMap_tmp.Create;
Bitmap.Width :=BMPINFO.bmiHeader.biWidth;
// New size of Bitmap
Bitmap.Height:=BMPINFO.bmiHeader.biHeight;
hd:= DrawDibOpen;
DrawDibDraw(hd,Bitmap.canvas.handle,0,0,BMPINFO.BmiHeader.biwidth,BMPINFO.bmiheader.biheight,@BMPINFO.bmiHeader,
lpVHdr^.lpData,0,0,BMPINFO.bmiHeader.biWidth,BMPINFO.bmiHeader.biheight,0);
DrawDibClose(hd);
//发送数据
memStream := TMemoryStream.Create;
jpg := TJpegImage.Create;
jpg.Assign(Bitmap);
jpg.CompressionQuality := 10;
//jpg压缩质量
jpg.JPEGNeeded;
jpg.Compress;
jpg.SaveToStream(memStream);
jpg.Free;
//因为UDP数据包有大小限制,这里如果超出部分,就没有传输,完全可以发几次发出去
F_Main.IdUDPClient.BroadcastEnabled:=true;//用广播功能
if memStream.Size>F_Main.IdUDPClient.BufferSize then

//向192.168.0.X网段广播,端口 9001
F_Main.IdUDPClient.SendBuffer(HostIP,HostPort,memStream.Memory^,F_Main.IdUDPClient.BufferSize)
else

F_Main.IdUDPClient.SendBuffer(HostIP,HostPort,memStream.Memory^,memStream.Size);
memStream.Free;
Bitmap.Free;
end;


procedure TSendVideoThread.SendVideo;
begin

CapWnd := capCreateCaptureWindow('我的窗口',
WS_VISIBLE or WS_CHILD,//窗口样式
0, //X坐标
0, //Y坐标
F_Main.panel1.Width, //窗口宽
F_Main.panel1.Height, //窗口高
F_Main.panel1.handle, //窗口句柄
0);
//通常为0
if CapWnd = 0 then
exit;
//定义帧捕捉回调函数
//************************************** 以下这句出错 编译通不过*******************************
capSetCallbackOnFrame(CapWnd,@FrameCallBack);
CapParms.dwRequestMicroSecPerFrame:=1;
CapParms.fLimitEnabled:=FALSE;
CapParms.fCaptureAudio:=FALSE;
CapParms.fMCIControl:=FALSE;
CapParms.fYield:=TRUE;
CapParms.vKeyAbort:=VK_ESCAPE;
CapParms.fAbortLeftMouse:=False;
CapParms.fAbortRightMouse:=FALSE;
//让设置生效
CapCaptureSetSetup(capWnd,@CapParms,sizeof(TCAPTUREPARMS));
CapPreviewRate(capWnd,33);
//设置预览视频的频率
CapCaptureSequenceNoFile(capWnd);
//如果要捕获视频流,则要使用函数来指定不生成文件,不然会自动生成AVI文件
CapDriverConnect(CapWnd,0);
//连接摄像头设备,第二个参数是个序号,当系统中装有多个显示驱动程序时,其值分别依次为0到总个数如果有多个摄像头,那么就是0->1->2
capGetVideoFormat(capWnd, @BMPINFO,sizeof(TBitmapInfo));
//取得视频图像数据头
CapPreviewScale(capWnd,TRUE);
//是否缩放
CapOverlay(capWnd,true);
//指定是否使用叠加模式,true为使用,否则为false
CapPreview(capWnd,true);
end;


end.
 
http://www.codesearch.com.cn
中国最大得源代码搜索引擎
 
capSetCallbackOnFrame(CapWnd[red],@FrameCallBack[/red]);
@FrameCallBack这个是回调函数
不能放在
function TSendVideoThread.FrameCallBack(hWnd: HWND;
lpVHdr: PVIDEOHDR): LongInt 线程里
而且发送最好也别放在回调函数中。在回调函数中通过休息传出
帧地址在另外的函数中发送
 
接受答案了.
 
后退
顶部