View Full Version : Comparing a bitmap to a bitmap
Toby1
08-18-2012, 08:15 PM
How can I compare a bitmap to another bitmap?
Le Jingle
08-18-2012, 08:23 PM
Compare as in this?
function CalculatePixelShift(Bmp1, Bmp2: Integer; CompareBox: TBox): Integer;
^ will measure the change from 1 bitmap to another.
If no, more information as to what you wish to do with the bitmaps would help to aide in finding something to compare the bitmaps.
Toby1
08-18-2012, 08:40 PM
thanks for help. +rep
Chewar
08-18-2012, 08:42 PM
Compare as in this?
function CalculatePixelShift(Bmp1, Bmp2: Integer; CompareBox: TBox): Integer;
^ will measure the change from 1 bitmap to another.
If no, more information as to what you wish to do with the bitmaps would help to aide in finding something to compare the bitmaps.
Thank you.. I'm trying this function out atm, I wish the docs were a bit more complete. The thing is we want to compare a bitmap to a part of another bitmap (second bitmap being bigger in width and height).
Bump.
What are these bitmaps you are trying to compare? It may be possible that there is an easier way to do this using functions/other features of the include. Without us knowing what you are trying to do it is difficult to make a suggestion.
Wizzup?
08-19-2012, 08:43 AM
Thank you.. I'm trying this function out atm, I wish the docs were a bit more complete. The thing is we want to compare a bitmap to a part of another bitmap (second bitmap being bigger in width and height).
My suggestion:
Set the larger bitmap as a target, use FindBitmapDeformedToleranceIn with the smaller bitmap in a part to see how much they match.
http://docs.villavu.com/simba/scriptref/bitmaps.html#finddeformedbitmaptolerancein
Flight
08-19-2012, 12:37 PM
My suggestion:
Set the larger bitmap as a target, use FindBitmapDeformedToleranceIn with the smaller bitmap in a part to see how much they match.
http://docs.villavu.com/simba/scriptref/bitmaps.html#finddeformedbitmaptolerancein
Now there's a good idea. I see loading the big bitmap and setting it as the target (then finding the small bitmap within the large) is really straight forward, but how would we set our original target back after comparing the two bitmaps? Getting the original target ID and setting that ID back, that I don't know how to do.
I can see where this would lead to a similar SPS.
Now there's a good idea. I see loading the big bitmap and setting it as the target (then finding the small bitmap within the large) is really straight forward, but how would we set our original target back after comparing the two bitmaps? Getting the original target ID and setting that ID back, that I don't know how to do.
I can see where this would lead to a similar SPS.
FindAndSetTarget? Never use it before though so i'm not sure if that's what you are looking for.
Brandon
08-19-2012, 02:42 PM
I can't get the goto to work. If you do though, this should work.
Function FindBitmapInBitmap(BMP, BitmapToFind: Integer; var P: TPoint; Area: TBox; Tolerance: Integer): Boolean;
var
BmpW, BmpH, DX, DY, I, J, X, Y, W, H: Integer;
FindColours, SearchColours: T2DIntegerArray;
Label Skip;
begin
GetBitmapSize(BMP, W, H);
GetBitmapSize(BitmapToFind, BmpW, BmpH);
SearchColours := GetBitmapAreaColors(BMP, 0, 0, W, H);
FindColours := GetBitmapAreaColors(BitmapToFind, 0, 0, BmpW, BmpH);
BmpW := BmpW - 1;
BmpH := BmpH - 1;
dX := (Area.X2 - Area.X1) - BmpW;
dY := (Area.Y2 - Area.Y1) - BmpH;
For I := 0 To DY Do
For J := 0 To DX Do
begin
For Y := 0 To BmpH Do
For X := 0 To BmpW Do
begin
if (FindColours[Y][X] <> 0) then
if (Not SimilarColors(FindColours[Y][X], SearchColours[Y + I][X + J], Tolerance)) then
GoTo Skip;
end;
P := Point(J + Area.X1, I + Area.Y1);
Resul:= True;
Exit;
Skip:
continue;
end;
P(-1, -1);
Result := False;
end;
I can't get the goto to work. If you do though, this should work.
Function FindBitmapInBitmap(BMP, BitmapToFind: Integer; var P: TPoint; Area: TBox; Tolerance: Integer): Boolean;
var
BmpW, BmpH, DX, DY, I, J, X, Y, W, H: Integer;
FindColours, SearchColours: T2DIntegerArray;
Label Skip;
begin
GetBitmapSize(BMP, W, H);
GetBitmapSize(BitmapToFind, BmpW, BmpH);
SearchColours := GetBitmapAreaColors(BMP, 0, 0, W, H);
FindColours := GetBitmapAreaColors(BitmapToFind, 0, 0, BmpW, BmpH);
BmpW := BmpW - 1;
BmpH := BmpH - 1;
dX := (Area.X2 - Area.X1) - BmpW;
dY := (Area.Y2 - Area.Y1) - BmpH;
For I := 0 To DY Do
For J := 0 To DX Do
begin
For Y := 0 To BmpH Do
For X := 0 To BmpW Do
begin
if (FindColours[Y][X] <> 0) then
if (Not SimilarColors(FindColours[Y][X], SearchColours[Y + I][X + J], Tolerance)) then
GoTo Skip;
end;
P := Point(J + Area.X1, I + Area.Y1);
Resul:= True;
Exit;
Skip:
continue;
end;
P(-1, -1);
Result := False;
end;
You cant call goto within a loop. Easiest way to do it would be to set a boolean to true then break out of the loop first, then check the boolean and call goto.
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.