请问下,
opencv  mat 与 delphi  Tbitmap如何转换?
自己尝试了下,在C++里,把mat与windos的Hbitmap进行了转换。
可是在delphi上,Tbitmap与Hbitmap如何转换,不知道怎么实现啊

解决方案 »

  1.   


    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;
      

  2.   

    貌似你也是要用到delphi做一些图像处理的事情。以后多多交流呀。