1,183
社区成员
发帖
与我相关
我的任务
分享
function PIplImage2bitmap(p_image:PIplImage): TBitmap;
var
bmp: Tbitmap;
step: integer;
i,j: integer;
p:PbyteArray;
begin
bmp:= Tbitmap.create;
bmp.Width := p_image^.width;
bmp.Height := p_image^.height;
bmp.PixelFormat := pf24bit;
step:= p_image^.widthStep;
for i := 0 to bmp.Height -1 do
begin
p := bmp.ScanLine[i];
for j := 0 to bmp.Width - 1 do
begin
move(PByteArray(p_image^.imageData)^[step*i],p^[0] ,step);
end;
end;
result := bmp;
end;
function bitmap2PIplImage(p_bmp:TBitmap): PIplImage;
var
image: PIplImage;
step: integer;
i,j: integer;
p:PbyteArray;
p2: pointer;
begin
//result := nil;
if p_bmp <> nil then
begin
if p_bmp.PixelFormat = pf24bit then
begin
image := cvCreateImage(CvSize(p_bmp.Width,p_bmp.Height),IPL_DEPTH_8U,3);
step:= image^.widthStep;
p2 := image^.imageData;
for i := 0 to p_bmp.Height -1 do
begin
p := p_bmp.ScanLine[i];
move(p^[0],P2^,step);
PAnsiChar(p2) := PAnsiChar(p2) + step;
end;
result := image;
end
else
begin
raise exception.create('This pixelFormat is not implemented!');
end;
end
else
raise exception.create('p_bmp not assigned in function bitmap2cv!');
end;