Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 颜色检测与分析_Delphi_Image Processing_Delphi Xe3 - Fatal编程技术网

Delphi 颜色检测与分析

Delphi 颜色检测与分析,delphi,image-processing,delphi-xe3,Delphi,Image Processing,Delphi Xe3,我试图分析一个.Jpeg图像600x600,但这样做我想让它告诉我,红色值高于230,绿色值高于200。 现在我正在进行这个项目,但是迭代整个图像需要很长时间,并且得到了奇怪的像素颜色值(color=+inttostr(RGB))。 谁能帮我一把吗 type PRGBTripleArray = ^TRGBTripleArray; TRGBTripleArray = array[0..4095] of TRGBTriple; procedure TForm2.Button1Click(S

我试图分析一个.Jpeg图像600x600,但这样做我想让它告诉我,红色值高于230,绿色值高于200。 现在我正在进行这个项目,但是迭代整个图像需要很长时间,并且得到了奇怪的像素颜色值(
color=+inttostr(RGB)
)。 谁能帮我一把吗

type
  PRGBTripleArray = ^TRGBTripleArray;
  TRGBTripleArray = array[0..4095] of TRGBTriple;

procedure TForm2.Button1Click(Sender: TObject);
var
  RGB: Byte;
  X, Y: Integer;
  R, G, B: Byte;
  Bitmap1: TBitmap;
  ColorRGB: LongInt;
  Pixels: PRGBTripleArray;
begin
  Memo1.Lines.Clear;
  Bitmap1 := TBitmap.Create;
  try
    Bitmap1.Assign(Image1.Picture.Graphic);

    for Y := 0 to Bitmap1.Height - 1 do
    begin
      Pixels:= Bitmap1.ScanLine[Y];

      Memo1.Lines.Add('======================');
      Memo1.Lines.Add('Line # ' + IntToStr(Y));
      Memo1.Lines.Add('======================');

      for X := 0 to Bitmap1.Width - 1 do
      begin
        ColorRGB := ColorToRGB(Bitmap1.Canvas.Pixels[x, y]);
        R := GetRValue(ColorRGB);
        G := GetGValue(ColorRGB);
        B := GetBValue(ColorRGB);
        RGB:= R*G*B;

        Memo1.Lines.Add(
                'line='    + IntToStr(Y)
              + ' row='    + IntToStr(X)
              + ' Colour=' + IntToStr(RGB)
              + ' Red='    + IntToStr (R) // red
              + ' Green='  + IntToStr (G) // blue
              + ' Blue='   + IntToStr (B) // green
        )
      end;
    end;
  finally
    Bitmap1.free;
  end;
end;

end.

如果要记录位图的每个像素(红色通道值大于230,绿色通道值大于200),可以使用以下命令。不要忘记对
TMemo.line
使用
BeginUpdate
EndUpdate
对锁定可能的频繁更新

无论如何,您仍然在混合使用两种位图像素访问技术。不要使用
Canvas.Pixels
进行大像素数组操作;效率很低。仅使用
扫描线

type
  PRGBTripleArray = ^TRGBTripleArray;
  TRGBTripleArray = array[0..4095] of TRGBTriple;

procedure TForm1.Button1Click(Sender: TObject);
var
  C: TColor;
  X: Integer;
  Y: Integer;
  Bitmap: TBitmap;
  Pixels: PRGBTripleArray;
begin
  Bitmap := TBitmap.Create;
  try
    Bitmap.Assign(Image1.Picture.Graphic);

    Memo1.Lines.BeginUpdate;
    try
      for Y := 0 to Bitmap.Height - 1 do
      begin
        Pixels := Bitmap.ScanLine[Y];
        for X := 0 to Bitmap.Width - 1 do
        begin
          if (Pixels[X].rgbtRed > 230) and (Pixels[X].rgbtGreen > 200) then
          begin
            C := RGB(
              Pixels[X].rgbtRed,
              Pixels[X].rgbtGreen,
              Pixels[X].rgbtBlue
            );
            Memo1.Lines.Add(
              '===============' + sLineBreak +
              'Pixel[' + IntToStr(X) + '; ' + IntToStr(Y) + ']' + sLineBreak +
              'Color: ' + ColorToString(C) + sLineBreak +
              'Red channel: ' + IntToStr(Pixels[X].rgbtRed) + sLineBreak +
              'Green channel: ' + IntToStr(Pixels[X].rgbtGreen) + sLineBreak +
              'Blue channel: ' + IntToStr(Pixels[X].rgbtBlue)
            );
          end;
        end;
      end;
    finally
      Memo1.Lines.EndUpdate;
    end;
  finally
    Bitmap.Free;
  end;
end;

我没有得到RGB:=R*G*B完全正确。你为什么要计算乘积?!此外,您可能需要设置像素格式。RGB值中的颜色从[0到16581375(255*255*255)]不等,我不应该使用该产品
R*G*B
,但如果有时值为0,解决方案是什么?@AndreasRejbrand我如何设置像素格式?至少您使用的是
Byte
数据类型,逻辑上超过255的最大值。最好描述一下你要做什么。我完全不符合“我想让它告诉我哪里的红色值高于230,哪里的绿色值高于200”的描述。您想记录红色值大于230、绿色值大于200的每个像素吗?是的,我错过了对像素[]数组的引用。我希望我们从来没有这样暴露过像素<代码>重复('=',15)未声明identifier@Ammadeux:将
StrUtils
添加到
uses
子句中。效果很好,速度很快。尽管如此,如何获得颜色值,而不是
color:$002CD2FB
您是指
t颜色的十进制表示形式吗?如果是这样,那么使用
IntToStr(Integer(C))
。谢谢TLama,我想怎么做就怎么做。