帮我将一个delphi代码修改成vb代码,图片相识度的代码
这是我找到的一个delphi判断2张图片相识度的代码,自己水平不够,请高手修改下,看看可以转成VB代码不,谢谢!
代码如下:
function BitmapDifference(BmpA, BmpB: TBitmap): single;stdcall;
var
x, y: integer;
P, Q: PByte;
Diff: int64;
begin
if not assigned(BmpA) or not assigned(BmpB)
or (BmpA.PixelFormat <> pf24bit) or (BmpB.PixelFormat <> pf24bit)
or (BmpA.Width <> BmpB.Width) or (BmpA.Height <> BmpB.Height)
or (BmpA.Width * BmpA.Height = 0) then
raise Exception.Create('Cannot compare bitmaps');
Diff := 0;
for y := 0 to BmpA.Height - 1 do begin
P := BmpA.Scanline[y];
Q := BmpB.Scanline[y];
for x := 0 to BmpA.Width - 1 do begin
Diff := Diff + Sqr(P^ - Q^); inc(P); inc(Q);
Diff := Diff + Sqr(P^ - Q^); inc(P); inc(Q);
Diff := Diff + Sqr(P^ - Q^); inc(P); inc(Q);
end;
end;
Result := Sqrt(Diff / (BmpA.Width * BmpA.Height));
end;
[解决办法]
http://download.csdn.net/detail/tztz520/3683609