Porównać dwie bitmapy

0

Czesc. Napisalem taka funkcje, porwnoje ona dwie bitmapy i jesli sa roznice to okresla w jakim polu (prostokat) znajduja sie roznice. Dziala rewelacyjnie. Ale przy bitmapach o rozdzielczosci 1152x864 czas wykonywania funkcji to srednio 2,5 sekundy a to dla mnie stanowczo za duzo. Czy ktos ma propozycje jak jeszcze mozna porownac bitmaapy? Oczywiscie z okresleniem zakresu od x-x i od y-y róznic.

function GetDifference(Img1, Img2:TImage; var XStart, XStop, YStart, YStrop:integer):boolean;
var
  x, y:integer;
  TheSame:boolean;
begin
  TheSame:=true;
  for y:=0 to Img1.Picture.Bitmap.Height do for x:=0 to Img1.Picture.Bitmap.Width do begin
    if Img1.picture.Bitmap.Canvas.Pixels[x,y]<>Img2.picture.Bitmap.Canvas.Pixels[x,y] then begin
      if TheSame or (XStart>X) then XStart:=X;
      if TheSame or (XStop<X) then XStop:=X;
      if TheSame or (YStart>Y) then YStart:=Y;
      if TheSame or (YStrop<Y) then YStrop:=Y;
      TheSame:=false;
    end;
  end;
  result:=not TheSame;
end;
0

ScanLine.

0

wlasnie wiem, ale nie umiem uzywac scanline, nie wiem jak pobrac ktory pixel sie rozni itd

0
function GetDifference(Img1, Img2:TImage; var XStart, XStop, YStart, YStrop:integer):boolean;
var
  Pixel1:^TrgbTriple;
  Pixel2:^TrgbTriple;
  x, y:integer;
  TheSame:boolean;
begin
Img1.Picture.Bitmap.PixelFormat:=pf24bit;
Img2.Picture.Bitmap.PixelFormat:=pf24bit;
  TheSame:=true;
  for y:=0 to Img1.Picture.Bitmap.Height -1  do 
begin
Pixel1:=Img1.Picture.Bitmap.ScanLine[y];
Pixel2:=Img2.Picture.Bitmap.ScanLine[y];

for x:=0 to Img1.Picture.Bitmap.Width-1 do 
begin

    if  (Pixel1.RgbtRed<>Pixel2.RgbtRed) or
        (Pixel1.RgbtGreen<>Pixel2.RgbtGreen)or
        (Pixel1.RgbtBlue<>Pixel2.RgbtBlue) then
begin
      if TheSame or (XStart>X) then XStart:=X;
      if TheSame or (XStop<X) then XStop:=X ;
      if TheSame or (YStart>Y) then YStart:=Y;
      if TheSame or (YStrop<Y) then YStrop:=Y;
      TheSame:=false;
    end;
inc(Pixel1);
inc(Pixel2);
  end;
  result:=not TheSame;
end;
end;
0

wwwoooooww 8-O

czas wykonania za pomoca mojej funkcji: 2,654 sekundy.
czas wykonania twojej funkcji: 0,016 sekundy!!!!

Jestes wielki Piotrekdp. :-DDDD

Ogromne dzieki!!! [browar]

0

proponuję od razu do FAQ dorzucić

0

A byłby ktoś w stanie przetłumaczyć to na c++
Pozdrawiam

0

nie sprawdzałem czy się kompiluje

bool GetDifference(TImage Img1, TImage Img2, int &XStart, int &XStop, int &YStart, int &YStrop)
{
    TrgbTriple* Pixel1, *Pixel2;
    int x, y;
    bool TheSame;

    Img1->Picture->Bitmap->PixelFormat = pf24bit;
    Img2->Picture->Bitmap->PixelFormat = pf24bit;
    TheSame = true;

    for(y=0; y<Img1->Picture->Bitmap->Height; ++y)
    {
        Pixel1 =Img1->Picture->Bitmap->ScanLine[y];
        Pixel2 =Img2->Picture->Bitmap->ScanLine[y];

        for( x=0; x<Img1->Picture->Bitmap->Width; ++x)
        {

            if( (Pixel1->RgbtRed!=Pixel2->RgbtRed) ||
                (Pixel1->gbtGreen!=Pixel2->RgbtGreen)||
                (Pixel1->RgbtBlue!=Pixel2->RgbtBlue) )
            {

            if ((TheSame) || (XStart>X)) XStart=X;
            if ((TheSame) || (XStop <X)) XStop =X;
            if ((TheSame) || (YStart>Y)) YStart=Y;
            if ((TheSame) || (YStrop<Y)) YStrop=Y;
            TheSame=false;
            }
        ++Pixel1;
        ++Pixel2;
        }
    }
    return !TheSame;
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1