The visualisation in HALCON 13 has been completely rewritten. You might not notice these differences if you are a standard HDevelop user. However, if you are developing your vision application based on a programming language, or executing HALCON programs via HDevEngine, you will need to carefully pay attention to these differences. The most frequently asked question is: Why do I get a black screen in my application which works under HALCON 12? Let’s look at the following example. This example is a .NET Windows form application.
public partial class Form1 : Form
{
private HImage hImage;
private HWindow hWindow;
private HFramegrabber hFramegrabber;
public Form1()
{
InitializeComponent();
hWindow = this.hWindowControl.HalconWindow;
hFramegrabber = new HFramegrabber(“File”, 1, 1, 0, 0, 0, 0, “default”, -1, “default”, -1, “default”, “board/board.seq”, “default”, 1, -1);
}
private void button1_Click(object sender, EventArgs e)
{
hFramegrabber.GrabImageStart(-1);
while (true)
{
hImage = hFramegrabber.GrabImageAsync(-1);
hImage.DispObj(hWindow);
hImage.Dispose();
}
}
}
In this example we initialised one HALCON window and one button. As soon as the user clicks this button, the program starts to sequentially grab images from a local directory and displays them inside the window. If we run this example in HALCON 12, the images will be displayed correctly. However, this doesn’t work in HALCON 13, where you will only get a black screen and the application freezes. Why?
This is because the visualisation in HALCON 13 is completely different from HALCON 12. The displaying here has been blocked by the while-loop in runBtn_Click(). While DispObj() is trying to update the window, the GUI is still waiting for runBun_Click() to finish. This causes a dead lock, and the whole application freezes.
If we want to display an image in HALCON 13, we have to ensure that the GUI is not blocked by any other activities. This could, e.g., be an endless loop, an image processing function with a long processing time, or waiting for a keyboard input. It’s the same reason why visualize_object_model_3d only shows a black screen in HALCON 13, because this procedure contains an endless loop.
The correct way to handle this situation is opening a new thread, so that the GUI and the while loop run separately without blocking each other. Alternatively, you can adapt the application to avoid the while-loop, e.g., use System.Windows.Forms.Timer with grab_image_async instead of the endless grabbing.