大恒工业相机采集的帧数据转为BMP与Halcon的HObject图像格式(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;
}

二、转为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_width, m_height, -1, "byte", m_width, m_height, 0, 0, -1, 0);
 return ho_image;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值