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;