.Heindl Solutions - Drawing into HALCON images

Drawing into HALCON images

2016-04-29 by Andreas Heindl

Often, when working with HALCON, you need to export images and the output of HALCON (e.g. features and results drawn into the image) via a simple interface to C#, C++, or the C world. A little known fact is that HALCON can draw graphics into images with the use of window buffers as in the following example:

* Project: Drawing into HALCON images.
* dump_window.hdev
* Copyright (C) 2016, Andreas Heindl Software Solutions
* Contact: http://www.heindl-solutions.com/contact/
read_image (Image, 'fabrik')
get_image_size (Image, Width, Height)

* Set window type to pixmap to be sure to run the same on any platform
* and open a buffer window in memory.
* We should save window type to restore it after opening the window.
* Pixmap buffers don't support e.g. writing text. Use the default window
* type if you need that, i.e. disable setting with set_window_type
NeedFontSupport := false
if (not NeedFontSupport)
  get_window_type ('default', LastWindowType)
  set_window_type ('pixmap')
open_window (0, 0, Width, Height, 0, 'buffer', '', WindowHandle)
if (not NeedFontSupport)
  set_window_type (LastWindowType)
set_part (WindowHandle, 0, 0, Height-1, Width-1)

* Example image processing code
disp_obj (Image, WindowHandle)
edges_sub_pix (Image, Edges, 'canny', 1, 20, 40)
set_colored (WindowHandle, 12)
disp_obj (Edges, WindowHandle)
disp_line (WindowHandle, 32, 32, 64, 64)
if (NeedFontSupport)
  write_string (WindowHandle, 'hello')

* Export window buffer to a HALCON image
dump_window_image (ImageDump, WindowHandle)
close_window (WindowHandle)

You can download the example HDevelop program here: