您的浏览器与网页部分内容不兼容,请及时更新。 点击此处了解如何更新浏览器。

OK
网上商店

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 to MIL MbufMonoColor

如何将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解决方案。

pylon to MIL MbufMonoColor

我们很乐意为您提供协助

销售咨询
支持服务
中国区代理商
定制相机