請問下,
opencv mat 與 delphi Tbitmap如何轉換?
自己嘗試了下,在C++里,把mat與windos的Hbitmap進行了轉換。
可是在delphi上,Tbitmap與Hbitmap如何轉換,不知道怎么實作啊
uj5u.com熱心網友回復:
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;
uj5u.com熱心網友回復:
謝謝你的回復啊。。。感謝感謝uj5u.com熱心網友回復:
貌似你也是要用到delphi做一些影像處理的事情。以后多多交流呀。轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/46028.html
上一篇:JAVA復習之java語言基礎
