お使いのブラウザが古くなっていますので、このウェブサイトのすべての機能が表示されない可能性があります。 お使いのブラウザの更新する方法をご覧ください。

OK
ビジョンシステムを構築する オンラインストア

How can I convert a pylon GrabResult into an MVTec HALCON image buffer?

If you want to use the Basler pylon Camera Software Suite for image acquisition and MVTec HALCON for further image processing, you have to convert the pylon GrabResult into a HALCON HImage buffer accordingly.

The following code snippets show how to create a HALCON HImage for monochrome pixel formats, e.g., MONO8, and debayered pixel formats, e.g., BGR or RGB, by using the HImage constructor.

In addition, the usage of the pylon CImageFormatConverter for converting of Bayer raw pixel formats, e.g., BayerRG8, BayerBG8, etc., is demonstrated.

The following code shows how to set up a HALCON HWindow for displaying a HALCON HImage.

/* Create an instant camera object with the first camera device found */

CInstantCamera camera(CTlFactory::GetInstance().CreateFirstDevice());

/* Get the camera nodes to Width and Height */

camera.Open();

INodeMap& nodemap = camera.GetNodeMap();

CIntegerPtr Width = nodemap.GetNode(„Width“);

CIntegerPtr Height = nodemap.GetNode(„Height“);

/* Create HWindow for display */

HWindow window(16, 16, Width->GetValue(), Height->GetValue(), 0, „visible“, „“);

/* Destination image (except for MONO8) */

HImage image;

If HALCON HImage should be used with MONO8, the buffer creation looks as follows:

if (ptrGrabResult->GetPixelType() == EPixelType::PixelType_Mono8)

{

HImage img(„byte“,

(Hlong)ptrGrabResult->GetWidth(),

(Hlong)ptrGrabResult->GetHeight(),

(uint8_t*)ptrGrabResult->GetBuffer());

/* Show HImage in HWindow */

window.AttachBackgroundToWindow(img);

}

If HALCON HImage should be used with BGR8packed, the buffer creation looks as follows:

else if (ptrGrabResult->GetPixelType() == EPixelType::PixelType_BGR8packed)

{

image.GenImageInterleaved((uint8_t*)ptrGrabResult->GetBuffer(),

„bgr“,

(Hlong)ptrGrabResult->GetWidth(),

(Hlong)ptrGrabResult->GetHeight(),

-1, „byte“,

(Hlong)ptrGrabResult->GetWidth(),

(Hlong)ptrGrabResult->GetHeight(),

0, 0, -1, 0);

window.AttachBackgroundToWindow(image);

}

Note:

Do not confuse BGR with RGB, because otherwise your colors will become wrong.

If you have configured a BGR pixel format on your Basler camera, e.g., EPixelType::PixelType_BGR8packed, you will also need a BGR attribute for HImage.

If you have configured an RGB pixel format on your Basler camera, e.g., EPixelType::PixelType_RGB8packed, you will also need an RGB attribute for HImage.

If HALCON HImage should be used with any Bayer pixel formats, e.g., BayerRG8, the pylon CImageFormatConverter has to be used in addition. The buffer creation looks as follows:

else

{

CPylonImage pylonimage;

CImageFormatConverter fc;

fc.OutputPixelFormat = PixelType_BGR8packed;

/* Convert GrabResult to BGR image first */

fc.Convert(pylonimage, ptrGrabResult);

/* Now create the BGR HImage */

image.GenImageInterleaved((uint8_t*)pylonimage.GetBuffer(),

„bgr“,

(Hlong)ptrGrabResult->GetWidth(),

(Hlong)ptrGrabResult->GetHeight(),

-1, „byte“,

(Hlong)ptrGrabResult->GetWidth(),

(Hlong)ptrGrabResult->GetHeight(),

0, 0, -1, 0);

window.AttachBackgroundToWindow(image);

}

Complete Microsoft Visual Studio solutions based on pylon 6.x and HALCON 18.11 for the C++ and C# programming languages are attached to this article.

pylon_to_Halcon_HImage

サポートはおまかせください

お問い合わせ
サポート
日本国内の販売代理店