comparar duas imagens

Delphi

20/08/2003

estou tentando fazer um detector de movimento baseado em uma webcam. preciso saber como fazer para que quando alguem passa pela frente da webcam meu programa emita um som ou coisa do tipo.

o unico jeito que eu acho possivel fazer isso é comparar duas imagens. se uma for diferente da outra matematicamente significa que passou alguem.

alguem poderia me ajudar a descobrir como eu posso fazer para comparar duas imagens????


Killedsoul

Killedsoul

Curtidas 0

Respostas

Cebikyn

Cebikyn

20/08/2003

Deve funcionar:

var
  b1, b2: TBitmap;
  c1, c2: PByte;
  x, y, i,
  different, BytesPerPixel: Integer;
  // Se different for diferente de 0, as imagens são diferentes
begin
  b1 := Image1.Picture.Bitmap;
  b2 := Image2.Picture.Bitmap;
  Assert(b1.PixelFormat = b2.PixelFormat);
  different := 0;
  case b1.PixelFormat of
    pf1bit, pf4bit, pf8bit: BytesPerPixel := 1;
    pf15bit, pf16bit: BytesPerPixel := 2;
    pf24bit: BytesPerPixel := 3;
    pf32bit: BytesPerPixel := 4;
  end;
  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 BytesPerPixel - 1 do
      begin
        Inc(different, Integer(c1^ <> c2^));
        Inc(c1);
        Inc(c2);
      end;
  end;
end;



GOSTEI 0
POSTAR