Basler相机获取的图片流转为Halcon中图片格式HImage

Lizhifun 2017-08-08 04:48:45
请问各位大神,怎么把Basler相机获取的图片流转为Halcon中图片格式HImage呢,语言用的是C#;
相机返回的结果有两种,一种是Basler自定义的返回结果,一种是图片的像素数组


附源码:


// Create a camera object that selects the first camera device found.
// More constructors are available for selecting a specific camera device.
using (Camera camera = new Camera())
{
// Print the model name of the camera.
camera_info.Text=camera.CameraInfo[CameraInfoKey.ModelName];

// Set the acquisition mode to free running continuous acquisition when the camera is opened.
camera.CameraOpened += Configuration.AcquireContinuous;

// Open the connection to the camera device.
camera.Open();

// The parameter MaxNumBuffer can be used to control the amount of buffers
// allocated for grabbing. The default value of this parameter is 10.
camera.Parameters[PLCameraInstance.MaxNumBuffer].SetValue(5);
// Start grabbing.
camera.StreamGrabber.Start();

// Grab a number of images.
for (int i = 0; i < 10; ++i)
{
// Wait for an image and then retrieve it. A timeout of 5000 ms is used.
IGrabResult grabResult = camera.StreamGrabber.RetrieveResult(5000, TimeoutHandling.ThrowException);
using (grabResult)
{
// Image grabbed successfully?
if (grabResult.GrabSucceeded)
{

ImagePersistence.Save(ImageFileFormat.Bmp, "C:\\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".bmp", grabResult);
// Access the image data.
buffer = grabResult.PixelData as byte[];

// Display the grabbed image.
//ImageWindow.DisplayImage(0, grabResult);

}
else
{
MessageBox.Show(grabResult.ErrorCode+","+grabResult.ErrorDescription);
}
}
}
//将获得的图片转换为Halcon对象
HImageConvertFromBytes(buffer);

// Stop grabbing.
camera.StreamGrabber.Stop();
// Close the connection to the camera device.
camera.Dispose();
camera.Close();

}
...全文
3406 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Joey luang 2021-03-23
  • 打赏
  • 举报
回复
引用 7 楼 weixin_42881431 的回复:
	try
{
// This smart pointer will receive the grab result data.
CGrabResultPtr ptrGrabResultLeft;
mCamera->RetrieveResult( 5000, ptrGrabResultLeft, TimeoutHandling_ThrowException);//获取结果

// Image grabbed successfully?
if (ptrGrabResultLeft->GrabSucceeded())
{
// Access the image data.
const uint8_t *pImageBuffer = (uint8_t *) ptrGrabResultLeft->GetBuffer();//获取图像在内存中的地址
GenImage1(pDstImg,"byte",(Hlong)ptrGrabResult->GetWidth(),(Hlong)ptrGrabResult->GetHeight(),(Hlong)pImageBuffer);//直接用halcon算子转化为HObject 格式 (此算子只适用单个通道)
}
}
catch (...)
{
return FALSE;
}
return TRUE;

3通道的genImage3怎么转
为何码 2018-12-15
  • 打赏
  • 举报
回复
	try
	{
		// This smart pointer will receive the grab result data.
		CGrabResultPtr ptrGrabResultLeft;
		mCamera->RetrieveResult( 5000, ptrGrabResultLeft, TimeoutHandling_ThrowException);//获取结果

		// Image grabbed successfully?
		if (ptrGrabResultLeft->GrabSucceeded())
		{
			// Access the image data.         
			const uint8_t *pImageBuffer = (uint8_t *) ptrGrabResultLeft->GetBuffer();//获取图像在内存中的地址
			GenImage1(pDstImg,"byte",(Hlong)ptrGrabResult->GetWidth(),(Hlong)ptrGrabResult->GetHeight(),(Hlong)pImageBuffer);//直接用halcon算子转化为HObject 格式	(此算子只适用单个通道)
		}
	}
	catch (...)
	{
		return FALSE;
	}
	return TRUE;
li15850220086 2017-11-20
  • 打赏
  • 举报
回复
结帖吧, 我给你一个联系方式,保证你解决。私聊我。。。
Allblus 2017-11-20
  • 打赏
  • 举报
回复
顶,我也在搞这个。
  • 打赏
  • 举报
回复
楼主我最近也在做这个相机,请问下你的图像是怎么保存的 ,
ImagePersistence.Save(ImageFileFormat.Bmp, "C:\\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".bmp", grabResult);
我的dll里面没有这个参数
我的是
Lizhifun 2017-08-11
  • 打赏
  • 举报
回复
引用 2 楼 happy4944 的回复:
还没在后台操作图片文本等
主要是想把图片保存在内存中再用Halcon读取,这样速度会快一些,相机API提供的方法是保存到本地硬盘,再读取的话速度太慢了
Lizhifun 2017-08-10
  • 打赏
  • 举报
回复
有没有人用过啊 自己顶一下
-一个大坑 2017-08-10
  • 打赏
  • 举报
回复
还没在后台操作图片文本等

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧