Onnx部署深度神经网络时,入口参数为System.Drawing.Image类
项目中采用halcon库来从相机采集图片
所以中间需要实现HImage和Image的转换
代码如下
public Bitmap HimageToImage(HImage hImage)
{
HTuple hred, hgreen, hblue, type, width, height;
if (int.Parse(hImage.CountChannels().ToString()) == 1)
{
hImage = hImage.Compose3(hImage, hImage);
}
try
{
HOperatorSet.GetImagePointer3(hImage, out hred, out hgreen, out hblue, out type, out width, out height);
Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppRgb);
Rectangle rect = new Rectangle(0, 0, width, height);
BitmapData bitmapData = bitmap.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
int imglength = width * height;
unsafe
{
byte* bptr = (byte*)bitmapData.Scan0;
byte* r = ((byte*)hred.L);
byte* g = ((byte*)hgreen.L);
byte* b = ((byte*)hblue.L);
for (int i = 0; i < imglength; i+

该代码段展示了如何在C#中将Halcon的HImage对象转换为System.Drawing.Image,以便在ONNX部署深度神经网络时使用。通过Halcon库获取相机图片,然后利用HOperatorSet.GetImagePointer3进行颜色通道提取,最终将数据写入Bitmap对象,完成转换。
最低0.47元/天 解锁文章
1139

被折叠的 条评论
为什么被折叠?



