• 大恒IFrameData & IImageData转bmp & HObject & Mat


    大恒工业相机采集的帧数据转为其他8bit图像格式

    回调采集图像的数据类型为IFrameData,单帧采集的数据类型为IImageData,两者的区别为IImageData类多了一个**Destroy()**方法
    在这里插入图片描述

    C#

    转为bmp格式

    //黑白相机
    public static Bitmap Tobmp(IImageData)
    {
     int m_width = (int)IImageData.GetWidth();
     int m_height = (int)IImageData.GetHeight();
     IntPtr pBufferMono = IImageData.GetBuffer();
     Bitmap bmp = new Bitmap(m_width, m_height, m_width, System.Drawing.Imaging.PixelFormat.Format8bppIndexed,pBufferMono);
     //添加调色板
     ColorPalette palette;
     palette = bmp.Palette;
     int i = 0;
     for (i = 0; i <= 255; i++)
        palette.Entries[i] = System.Drawing.Color.FromArgb(i, i, i);
     bmp.Palette = palette;
     return bmp;
    }
    //彩色相机
    public static Bitmap Tobmp(IImageData)
    {
     int m_width = (int)IImageData.GetWidth();
     int m_height = (int)IImageData.GetHeight();
     IntPtr pBufferColor = IImageData.ConvertToRGB24(GX_VALID_BIT_LIST.GX_BIT_0_7, GX_BAYER_CONVERT_TYPE_LIST.GX_RAW2RGB_NEIGHBOUR, false);
     Bitmap bmp = new Bitmap(m_width, m_height, m_width * 3, System.Drawing.Imaging.PixelFormat.Format24bppRgb, pBufferColor);
     return bmp;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25

    转为Halcon的HObject格式

    //黑白相机
    public static HObject ToHObject(IImageData)
    {
     int m_width = (int)IImageData.GetWidth();
     int m_height = (int)IImageData.GetHeight();
     HOperatorSet.GenImage1(out HObject ho_image, "byte", m_width, m_height,  IImageData.GetBuffer());
     return ho_image;
    }
    //彩色相机
    public static HObject ToHObject(IImageData)
    {
     int m_width = (int)IImageData.GetWidth();
     int m_height = (int)IImageData.GetHeight();
     IntPtr pBufferColor = IImageData.ConvertToRGB24(GX_VALID_BIT_LIST.GX_BIT_0_7, GX_BAYER_CONVERT_TYPE_LIST.GX_RAW2RGB_NEIGHBOUR, false);
     HOperatorSet.GenImageInterleaved(out HObject ho_image, pBufferColor, "bgr", m_height, m_height, -1, "byte", m_width, m_height, 0, 0, -1, 0);
     return ho_image;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    转为OpenCVSharp的Mat格式

    //黑白相机
    public static Mat ToMat(IImageData)
    {
     int height = (int)IImageData.GetHeight();
     int width = (int)IImageData.GetWidth();
     byte[] m_byMonoBuffer = new byte[width  * height];
     Marshal.Copy(IImageData.GetBuffer(), m_byMonoBuffer, 0, width * height);
     Mat image = new Mat(height, width, MatType.CV_8UC1, m_byMonoBuffer);   
     return image;  
    }
    //彩色相机
    public static Mat ToMat(IImageData)
    {
     int height = (int)IImageData.GetHeight();
     int width = (int)IImageData.GetWidth();
     IntPtr pBufferColor = IImageData.ConvertToRGB24(GX_VALID_BIT_LIST.GX_BIT_0_7, GX_BAYER_CONVERT_TYPE_LIST.GX_RAW2RGB_NEIGHBOUR, false);
     byte[] m_byColorBuffer = new byte[(width * 3) * height];
     Marshal.Copy(pBufferColor, m_byColorBuffer, 0, (width * 3) * height);
     Mat image = new Mat(height, width, MatType.CV_8UC3, m_byColorBuffer);  
     return image; 
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
  • 相关阅读:
    算法 day29 回溯5
    浏览器内写代码,微软发布 VS Code Server!
    RSA非对称加密算法中的密钥对生成与传输
    蒋鑫鸿:9.10国际黄金原油最新外盘行情趋势点评附解一套技术指导
    iOS pod repo push 报错 ld: file not found: libarclite_iphoneos.a 问题解决方案
    AD9371 官方例程
    SpringBoot项目中使用Swagger2及注解解释(详细)
    Linux系统编程(一)——环境搭建
    leetcode 54. 螺旋矩阵
    静态 友元 常量
  • 原文地址:https://blog.csdn.net/qq_35044766/article/details/132197052