-
产品中心
计算机视觉硬件工业相机 镜头 机器视觉光源 采集卡 线材 配件 网络和外围设备计算机视觉软件pylon Camera Software Suite VisualApplets 其他软件产品线嵌入式视觉产品线 医疗和生命科学产品线 CoaXPress产品线面阵相机Basler ace 2 Basler ace Basler MED ace Basler boost Basler beat Basler dart Basler pulse Basler scout线阵相机Basler racerBasler racerBasler racer - the right choice镜头固定焦距镜头机器视觉光源Basler相机光源系列
- 选型工具
- 解决方案
- 下载中心
- 品牌中心
- 销售与支持
-
Vision Campus
相机技术Sony IMX CMOS芯片系列型号比较 为什么要对相机进行色彩校准? 专家教您如何为视觉系统找到合适的镜头 适用于嵌入式视觉系统的五大专家级技巧 什么是多光谱成像? CMOS相机比较 图像处理过程中的色彩 处理板 什么是图像处理 图像处理中的3D技术 什么是嵌入式视觉? 为何选择CMOS图像芯片? 什么是ToF (Time-of-Flight)? 什么是成像质量? 相机尺寸 数字相机的工作原理是什么? 芯片技术:CMOS与CCD的对比 实时性 NIR: 即使在弱光条件也可以呈现清晰图像 高灵敏度图像处理相机显示更多收起接口和标准System Setup with CoaXPress 2.0 什么是CoaXPress? 哪一款接口适合嵌入式视觉? 配备GigE 2.0的多相机系统 USB 3.0 – 引领未来的标准化接口 接口是什么? Camera Link 千兆网(GigE) GenICam标准 USB 3.0和USB3 Vision
- 公司概况
How can I convert a pylon GrabResult into a Matrox MIL image buffer?
If you want to convert a pylon GrabResult directly into an image buffer of a Matrox MIL image, you may use the pylon CImageFormatConverter.
The following code snippets show how to create a MIL image buffer and correctly configure the pylon CImageFormatConverter (in pylon C# called: PixelDataConverter), depending on the used Pixel Format.
If the MIL image buffer should be used with M_MONO8, the buffer creation looks as follows:
CImageFormatConverter converter;
converter.OutputPixelFormat = PixelType_Mono8; // 8 bit gray value per pixel
MIL_INT SizeBytesPerPixel = 1; // 8 bit per pixel
MIL_INT SizeBand = 1; // 1 color only (monochrome)
MIL_INT SizeType = 8 + M_UNSIGNED; // uint8_t
MIL_INT SizeX = camera.Width.GetValue();
MIL_INT SizeY = camera.Height.GetValue();
/* Allocate MIL Monochrome Buffer */
MIL_ID MilImage;
MbufAlloc2d(MilSystem, SizeBand, SizeX, SizeY, SizeType, M_IMAGE + M_PACKED + M_MONO8 + M_DISP + M_PROC, &MilImage);
/* Optionally, select the new image buffer to be displayed in the MIL display window */
MdispSelect(MilDisplay, MilImage);
/* Inquire the Line Pitch used by the MIL buffer (Offset in bytes between two adjacent lines) */
MIL_INT SizePitch = MbufInquire(MilImage, M_PITCH_BYTE, M_NULL);
/* The real buffer size, needed in OnImageGrabbed() */
MIL_INT SizeImageBuffer = SizePitch * SizeY;
/* Now calculate the amount of PaddingX bytes */
MIL_INT SizePaddingXBytes = SizePitch - (SizeX * SizeBytesPerPixel);
/* Configure the CImageFormatConverter to use PaddingX bytes */
converter.OutputPaddingX.SetValue(SizePaddingXBytes);
If the MIL image buffer should be used with M_BGR24 (e.g., if your pylon GrabResult has any color format), the buffer creation looks as follows:
converter.OutputPixelFormat = PixelType_BGR8packed; // This corresponds to MIL M_BGR24
MIL_INT SizeBytesPerPixel = 3; // 24 bit per pixel (BGRBGR)
MIL_INT SizeBand = 3; // 3 colors (R, G, B)
MIL_INT SizeType = 8 + M_UNSIGNED; // uint8_t
MIL_INT SizeX = camera.Width.GetValue();
MIL_INT SizeY = camera.Height.GetValue();
MIL_ID MilImage;
MbufAllocColor(MilSystem, SizeBand, SizeX, SizeY, SizeType, M_IMAGE + M_PACKED + M_BGR24 + M_DISP + M_PROC, &MilImage);
Note:
Do not confuse BGR with RGB, because otherwise your colors will become wrong.
If you are using an RGB format for the converter output, you will also need an RGB attribute for the buffer allocation (e.g., M_RGB24).
If you are using a BGR format for the converter output, you will also need a BGR attribute for the buffer allocation (e.g., M_BGR24).
Also, take into consideration that MbufAllocColor should be used for color images.
Eventually, the conversion of the pylon GrabResult into a Matrox MIL image buffer is done in the pylon Image Event Handler, OnImageGrabbed():
/* Lock MIL image buffer */
MbufControl(MilImage, M_LOCK + M_WRITE, M_DEFAULT);
/* Inquire start address of MIL image buffer */
uint8_t *mil_image_ptr = NULL;
MbufInquire(MilImage, M_HOST_ADDRESS, &mil_image_ptr);
/* Convert GrabResult into MIL image buffer using the CImageFormatConverter */
converter.Convert(mil_image_ptr, SizeImageBuffer, ptrGrabResult);
/* Unlock image buffer */
MbufControl(MilImage, M_UNLOCK, M_DEFAULT);
/* Mark image buffer as "modified", this will update the MIL display window */
MbufControl(MilImage, M_MODIFIED, M_DEFAULT);
Complete Microsoft Visual Studio solutions based on pylon 6.x and MIL Lite 10 for the C++ and C# programming languages can be downloaded below.
如何将pylon GrabResult转换为Matrox MIL image buffer?
如果想将pylon GrabResult直接转换为Matrox MIL image buffer,可以使用pylon CImageFormatConverter转换器。
以下代码段演示了如何创建MIL image buffer,以及如何正确配置 pylon CImageFormatConverter转换器(在pylon C#中称为:PixelDataConverter转换器),具体取决于所使用的像素格式。
如果MIL image buffer要与M_MONO8配合使用,则buffer的创建方式如下所示:
CImageFormatConverter converter;
converter.OutputPixelFormat = PixelType_Mono8; // 8 bit gray value per pixel
MIL_INT SizeBytesPerPixel = 1; // 8 bit per pixel
MIL_INT SizeBand = 1; // 1 color only (monochrome)
MIL_INT SizeType = 8 + M_UNSIGNED; // uint8_t
MIL_INT SizeX = camera.Width.GetValue();
MIL_INT SizeY = camera.Height.GetValue();
/* Allocate MIL Monochrome Buffer */
MIL_ID MilImage;
MbufAlloc2d(MilSystem, SizeBand, SizeX, SizeY, SizeType, M_IMAGE + M_PACKED + M_MONO8 + M_DISP + M_PROC, &MilImage);
/* Optionally, select the new image buffer to be displayed in the MIL display window */
MdispSelect(MilDisplay, MilImage);
/* Inquire the Line Pitch used by the MIL buffer (Offset in bytes between two adjacent lines) */
MIL_INT SizePitch = MbufInquire(MilImage, M_PITCH_BYTE, M_NULL);
/* The real buffer size, needed in OnImageGrabbed() */
MIL_INT SizeImageBuffer = SizePitch * SizeY;
/* Now calculate the amount of PaddingX bytes */
MIL_INT SizePaddingXBytes = SizePitch - (SizeX * SizeBytesPerPixel);
/* Configure the CImageFormatConverter to use PaddingX bytes */
converter.OutputPaddingX.SetValue(SizePaddingXBytes);
如果MIL image buffer要与M_BGR24配合使用(例如,如果您的pylon GrabResult具有任意色彩格式),则buffer的创建方式如下所示:
converter.OutputPixelFormat = PixelType_BGR8packed; // This corresponds to MIL M_BGR24
MIL_INT SizeBytesPerPixel = 3; // 24 bit per pixel (BGRBGR)
MIL_INT SizeBand = 3; // 3 colors (R, G, B)
MIL_INT SizeType = 8 + M_UNSIGNED; // uint8_t
MIL_INT SizeX = camera.Width.GetValue();
MIL_INT SizeY = camera.Height.GetValue();
MIL_ID MilImage;
MbufAllocColor(MilSystem, SizeBand, SizeX, SizeY, SizeType, M_IMAGE + M_PACKED + M_BGR24 + M_DISP + M_PROC, &MilImage);
注意:
请勿混淆BGR和RGB,否则您的色彩信息将会出错。
如果转换器输出使用的是RGB格式,则buffer分配还需要具有RGB属性(例如M_RGB24)。
如果转换器输出使用的是BGR格式,则buffer分配还需要具有BGR属性(例如M_BGR24)。
此外,还要考虑将MbufAllocColor应用于彩色图像。
最后,在pylon Image Event Handler, OnImageGrabbed()中成功将pylon GrabResult转换为MatroxMIL image buffer:
/* Lock MIL image buffer */
MbufControl(MilImage, M_LOCK + M_WRITE, M_DEFAULT);
/* Inquire start address of MIL image buffer */
uint8_t *mil_image_ptr = NULL;
MbufInquire(MilImage, M_HOST_ADDRESS, &mil_image_ptr);
/* Convert GrabResult into MIL image buffer using the CImageFormatConverter */
converter.Convert(mil_image_ptr, SizeImageBuffer, ptrGrabResult);
/* Unlock image buffer */
MbufControl(MilImage, M_UNLOCK, M_DEFAULT);
/* Mark image buffer as "modified", this will update the MIL display window */
MbufControl(MilImage, M_MODIFIED, M_DEFAULT);
本文随附基于pylon 6.x和MIL Lite 10(适用于C++和C#编程语言)的完整Microsoft Visual Studio解决方案。