Basler相机拍图转成Halcon的HObject

  • Post author:
  • Post category:其他


相机是Basler一款网口的灰度相机,将byte[]转成HObject类型,关键步骤如下:

// Basler相机抓图
IGrabResult grabResult = camera.StreamGrabber.RetrieveResult(5000, TimeoutHandling.ThrowException);
using (grabResult)
{
 	if (grabResult.GrabSucceeded)
 	{
 		//相机像素数据
 		byte[] buffer = grabResult.PixelData as byte[];
 		//锁定像素数据
		GCHandle hand= GCHandle.Alloc(buffer, GCHandleType.Pinned);
		//获取像素数据的指针
		IntPtr pr = hand.AddrOfPinnedObject();
		HalconDotNet.HObject image;
		//转成灰度图HOjbect
		HalconDotNet.HOperatorSet.GenImage1(out image, new HalconDotNet.HTuple("byte"), 		grabResult.Width, grabResult.Height, pr);
		//释放内存
		if(hand.IsAllocated)hand.Free();
		//显示图片
		HalconDotNet.HOperatorSet.DispImage(image, HWindowControl.HalconWindow);
	}
	else
	{throw new Exception("No image grabbed.")}
}
camera.StreamGrabber.Stop();
camera.Close();



版权声明:本文为weixin_43490307原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。