Implementing HALCON in an existing application will need some preparations. The current infrastructure of the program will make it necessary to integrate the HALCON procedures in the work flow. Images to be processed can be captured by the application directly and are stored in a native data type like the bitmap classes on Windows systems.
Bitmaps use a structure which is slightly different than HALCON image objects. The image memory for bitmaps must be stored so that the number of bytes per row is always divisible by four. Furthermore, bitmaps use an interleaved image format.
The creation of a bitmap from a HALCON image can be done through the constructors of the bitmap class. With single channel images this is straight forward by using the pointer from the operator get_image_pointer1 and the dimensions of the image.
When you want to create a three channel RGB bitmap you will need to convert the planar data from the HALCON images to the interleaved format. Furthermore, you need to pad the data so that the rows are divisible by 4. In .NET languages you can use the Marshal class to copy the data into a newly allocated buffer. When you have copied the pixels you can use the pointer of this new buffer in the constructor of the bitmap class.
You maybe have a bitmap in your application and want to convert it to an HImage object. Then we can use a trick in order to avoid problems with the padding. Single channel bitmaps and three channels bitmaps can be converted into 32 bit per pixel formats. This means that each row of the bitmap is directly divisible by 4. For 32 bpp data, padding is not necessary.
The conversion can be done again with the use of the bitmap constructor to create a new bitmap with 32 bpp. From the pointer of the 32 bpp bitmap you can create a HALCON image using the operator gen_image_interleaved with the parameter ColorFormat set to “bgrx”.
Example implementations for each of the conversions in C# are available through our support team. Please contact them at support@multipix.com