Показать сообщение отдельно
  #4  
Старый 02.06.2016, 13:03
stlcrash stlcrash вне форума
Прохожий
 
Регистрация: 27.01.2012
Сообщения: 4
Репутация: 10
По умолчанию

Работает, но появилась проблемка. Если
filterVoter.Checked filtersilver.Checked False
То работает как и раньше. Но стоит только изменить один из фильтров на True, начинает думать по 10 секунд...

Код:
//сравнение 2 пикселей полученных с помощью ScanLine
function Same(t1,t2:TRGBTriple):Boolean;
begin
  result := (t1.r=t2.r) and (t1.g=t2.g) and (t1.b=t2.b);
end;

function IsColorDiff_InRange(t1: TRGBTriple; rMin, rMax, gMin, gMax, bMin, bMax: Byte): Boolean;
begin
result:=
      (t1.r In [rMin..rMax])
      and
      (t1.g In [gMin..gMax])
      and
      (t1.b In [bMin..bMax]);
end;

//Img1-img2
procedure TForm1.FindDiff;
var x,y:integer;
  p1,p2:TRGBTriple;
  a1,a2,a3:PRGBTripleArray;
  res:TBitmap;
  paintOver:boolean;
const
  w:TRGBTriple=(b:255;g:255;r:255);
begin
  res:=TBitmap.Create;
  res.PixelFormat := pf24bit;
  res.Width := bmp1.Width;
  res.height:=bmp1.height;
  for y:=0 to bmp1.Height-1 do
  begin
    a1:=PRGBTripleArray(bmp1.ScanLine[y]);
    a2:=PRGBTripleArray(bmp2.ScanLine[y]);
    a3:=PRGBTripleArray(res.ScanLine[y]);
    for x := 0 to bmp1.width-1 do
    begin
      p1:=a1[x];
      p2:=a2[x];
      if not same(p1,p2) then
      begin
        paintOver:=true;
        if filterVoter.Checked then if IsColorDiff_InRange(p2, Filter1Rmin.Value, Filter1Rmax.Value, Filter1Gmin.Value, Filter1Gmax.Value, Filter1Bmin.Value, Filter1Bmax.Value) then paintOver:=false;
        if (filtersilver.Checked) and (paintOver) then if IsColorDiff_InRange(p2, Filter2Rmin.Value, Filter2Rmax.Value, Filter2Gmin.Value, Filter2Gmax.Value, Filter2Bmin.Value, Filter2Bmax.Value) then paintOver:=false;
        if paintOver then a3[x]:=p2 else a3[x]:=w;
      end
      else
        a3[x]:=w;//закрашиваем пиксель в белый цвет
    end;
  end;
  img1.width:=res.Width;
  img1.Height:=res.Height;
  img1.Picture.Assign(res);
  Detect(res,((HeightWidth.Value*HeightWidth.Value) div 100)*BWPorog.Position);
  res.Free;
end;
Ответить с цитированием