opencv mat 与 delphi Tbitmap如何转换

徐大大平凡之路 2017-12-19 01:52:42
请问下,
opencv mat 与 delphi Tbitmap如何转换?
自己尝试了下,在C++里,把mat与windos的Hbitmap进行了转换。
可是在delphi上,Tbitmap与Hbitmap如何转换,不知道怎么实现啊
...全文
1499 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
貌似你也是要用到delphi做一些图像处理的事情。以后多多交流呀。
  • 打赏
  • 举报
回复
谢谢你的回复啊。。。感谢感谢
mdejtod 2017-12-20
  • 打赏
  • 举报
回复

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;

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧