相机Raw8 BayerGB8 转 pf24bit Bitmap Delphi

    OpenCV4.7.0    BayerGB8    转 pf24bit Bitmap
    https://github.com/Laex/Delphi-OpenCV-Class       
    引用单元 cpp.utils, cv.resource, cv.opencv;    

// 将BayerGB8转换为pf24bit的TBitmap
procedure TBopixelAPI.BayerGB8ToBitmap24(const BayerGBData: Pointer; Width, Height: Integer; var Bitmap: TBitmap);
var
  src, dst: TMat;
  x, y, w: Integer;
  Line: pbytearray;//PRGBQuad;
  bmp:TBitmap;
begin
  bmp := Bitmap;
  src := TMat.mat(Height, Width, CV_8UC1, BayerGBData);
  dst := TMat.mat(Height, Width, CV_8UC3);
  // 转换BayerGB到BGR
  cvtColor(src, dst, COLOR_BayerGB2BGR);

  //imwrite(ExtractFilePath(Application.ExeName) + '\logdata\cv_8uc4.bmp', dst);

  var pData: pbytearray;
  pData := pbytearray(dst.data);
  TParallel.for (0, Height - 1,
    procedure(row: Integer)
    var
      p, qLocal: PByteArray;
      col: Integer;
    begin
      p := bmp.ScanLine[row];//ps[row];
      qLocal := pData; // 假设q指向每行开始的位置,你可能需要根据实际情况调整这里
      IntPtr(qLocal) := IntPtr(qLocal) + row * Width * 3; // 调整qLocal指向当前行的开始
      for col := 0 to Width - 1 do
      begin
        p[0] := qLocal[2]; // R
        p[1] := qLocal[1]; // G
        p[2] := qLocal[0]; // B
        IntPtr(p) := IntPtr(p) + 3;
        IntPtr(qLocal) := IntPtr(qLocal) + 3;
      end;
    end);

  (*
  var pData: PByte; //pbytearray;
  pData := PByte(dst.data);
  w := 3 * Bitmap.Width;
  w := (w and 3);
  if w > 0 then w := 4 - w;
  for y := 0 to dst.rows - 1 do
  begin
    Line := Bitmap.ScanLine[y];
    for x := 0 to dst.cols - 1 do
    begin
      Line[0] := pData^; Inc(pData);
      Line[1] := pData^; Inc(pData);
      Line[2] := pData^; Inc(pData);
      IntPtr(Line) := IntPtr(Line) + 3;
    end;
    IntPtr(Line) := IntPtr(Line) + w;
  end;
  *)
  src.Release;
  dst.Release;
  // 现在dst包含BGR格式的图像数据,将其复制到TBitmap
  //BitmapCopyFromMem(dst.data, Width, Height, Bitmap);
end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值