This section demonstrates how to create a simple HALCON application with .NET Core. For a more comprehensive description, see section “Creating Applications With HALCON/.NET”.
The task is to read an image and compute the number of connected regions in it, as illustrated in figure 9.1
Figure 9.1: Left: Input image of a printed circuit board. Middle: Regions found by threshold, colored red. Right: Connected regions, a result of connection.
dotnet new console -n region_example cd region_example dotnet add package MVTec.HalconDotNet -v 21050
using System; using HalconDotNet; namespace ConsoleApp { class Program { static void Main(string[] args) { HImage img = new HImage("pcb"); HRegion region = img.Threshold(0d, 122d); int numRegions = region.Connection().CountObj(); Console.WriteLine("Number of Regions: " + numRegions); } } }
dotnet run
As a result, you should see the following output 'Number of Regions: 43'.