dspack捕获摄像头图像差异对比,以下我的代码,感觉效率太低,请高手指点一二!(50分)

  • 主题发起人 主题发起人 tl_lyq
  • 开始时间 开始时间
T

tl_lyq

Unregistered / Unconfirmed
GUEST, unregistred user!
1、差异好象一直都存在。除非用手挡住镜头。
2、如果多个摄像头的话,是否效率太低。请指点。

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, DSPack,directshow9, ComCtrls;

type
TForm1 = class(TForm)
FilterGraph1: TFilterGraph;
Filter1: TFilter;
Button3: TButton;
SampleGrabber1: TSampleGrabber;
DSVideoWindowEx21: TDSVideoWindowEx2;
Button4: TButton;
p1: TProgressBar;
Label1: TLabel;
procedure Button3Click(Sender: TObject);
procedure SampleGrabber1Buffer(sender: TObject; SampleTime: Double;
pBuffer: Pointer; BufferLen: Integer);
procedure Button4Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
b1, b2: TBitmap;
implementation

{$R *.dfm}

procedure TForm1.Button3Click(Sender: TObject);
begin
with FilterGraph1 as ICaptureGraphBuilder2 do
RenderStream(@PIN_CATEGORY_PREVIEW, nil, Filter1 as IBaseFilter, SampleGrabber1 as IBaseFilter, DSVideoWindowEx21 as IbaseFilter);
FilterGraph1.Play;
end;

procedure TForm1.SampleGrabber1Buffer(sender: TObject; SampleTime: Double;
pBuffer: Pointer; BufferLen: Integer);
var
c1, c2: PByte;
x, y, i,
different: Integer;
begin
try
b2.Assign(b1);
SampleGrabber1.GetBitmap(b1);
Assert(b1.PixelFormat = b2.PixelFormat);
different := 0;
for y := 0 to b1.Height - 1 do
begin
c1 := b1.Scanline[y];
c2 := b2.Scanline[y];
for x := 0 to b1.Width - 1 do
for i := 0 to 3 do // 1, to 4, dep. on pixelformat
begin
Inc(different, Integer(c1^ <> c2^));
Inc(c1);
Inc(c2);
end;
end;
if different / p1.max *100>50 then label1.Caption :='报警'
else
label1.Caption :='';
p1.Position :=different ;
except end;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
filtergraph1.Active :=false;
filtergraph1.Stop;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
b1:=tbitmap.Create ;
b2:=tbitmap.Create ;
end;

end.
 
我感觉应该有个差异范围,因为有的时候虽然我们眼睛感觉不到,但可能捕捉到的图像会变化(比如灯光影响。。)
 
后退
顶部