Halcon 12: User interaction via drawing objects

Drawing objects represent regions, XLDs, and text objects that are attached to a HALCON window and that can be modified interactively and asynchronously, i.e., without blocking the application. Drawing objects are available for circles, circle sectors, ellipses, ellipse sectors, lines, rectangles, XLDs, and text.

The following image shows, how the user can easily modify poDrawingObjectsSectorsition, size, and orientation of a circle sector

To use a drawing object, you just need to create it with:

create_drawing_object_xxx

To change the display style, e.g., color or line width, in which the drawing object is displayed, you could use:

set_drawing_object_params

Then you need to attach the drawing object to a specific HALCON window, so that the drawing object will be displayed and can be modified there:

attach_drawing_object_to_window

When you no longer need the drawing object, you have to detach it from the HALCON window and clear the drawing object with

detach_drawing_object_from_window
clear_drawing_object
Tips:

I: It is possible to detach a drawing object and then attach it to
another (or the same) HALCON window again. As long as a drawing object is not deleted with clear_drawing_object, it remains alive.

II: If you want to show one image in the background, you could use:

attach_background_to_window

The attached background image will not even be cleared with:

dev_clear_window

If you no longer need the background image, you should detach it with:

detach_background_from_window

III: Once a drawing object is attached to a HALCON window, all displayed HALCON objects, e.g., from disp_obj, will be stored in a graphic stack, associated with this HALCON window. The size of this stack is limited to 50 per default. You can use set_system to change this value.
The attached drawing objects are always shown at the top of the window.

IV: Any other interactive operator, e.g., get_mbutton, read_char,
draw_rectangle1, draw_circle, etc. will conflict with the interaction of drawing objects. So, do not use one of those when you are using drawing objects!

Drawing objects will typically be used in stand-alone applications. For that, HALCON 12.0.1 released a .NET example program MultiThreadingMessageQueues. It demonstrates a typical industrial application consisting of three components: image acquisition, image processing, and visualization. The last part is combined with user interaction based on drawing objects.

This program is well-structured, scalable, and reusable. We applied two design patterns in this program: the actor model and the chain of responsibility pattern. Although just one camera and one image processing thread are used in this example, you could extend it into several cameras and multiple image processing threads easily.

Based on the actor model, each actor contains one message queue for its communication. At the beginning, the actor fetches a message from the queue and processes it. After finishing, it sends a message to the message queue of its subsequent actor. It is possible that one actor sends messages to multiple actors. All the actors are totally independent and working asynchronous, which ensures a high throughput.

actor

The processing chain is designed such that one thread grabs images from the camera and passes them to the next thread. There, the object is searched using shape based matching and finally, the contour of the found object is visualized in another UI thread.

Processing Thread

With the drawing objects, the user can specify a model region
interactively. The thread that creates the shape model gets the specified region by using:

hobj = drawing_obj.GetDrawingObjectIconic();

Furthermore, it is also possible to implement call back functions so that the thread receives the region automatically. This is demonstrated in the .NET example programs DrawingObjects and DrawingObjectsWPF.

In addition, a graphic stack is implemented for visualization. The message from the queue will be passed into this stack at first, so that they will not be visualized as soon as they arrive the queue, but only when the graphic stack is ready to display. This makes the visualization more efficient and controllable.

Pass the message into graphic stack:

AddToStack(objs.GetMessageObj(“contour”));
AddToStack(objs.GetMessageObj(“image”));

halconWindow.HalconWindow.ClearWindow();
while (graphic_stack.Count > 0)
{
halconWindow.HalconWindow.DispObj(graphic_stack.Pop());
}