- 引用 dll
在 Halcon 安装目录下的 bin\dotnet35
引用 halcondotnet.dll
。
- 包含命名空间:
xmlns:halcon="clr-namespace:HalconDotNet;assembly=halcondotnet"
- 测试代码:
界面:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button Content="加载图像" Click="Button_Click"/>
<halcon:HSmartWindowControlWPF x:Name="HWidget" Grid.Row="1"/>
</Grid>
按钮:
private void Button_Click(object sender, RoutedEventArgs e)
{
string imagePath = @"D:\huwj\_Temp\MyDemoPractice\CV-BiliBli-HenJi_halcon\img\dog.jpg";
HImage image = new HImage();
image.ReadImage(imagePath);
int width, height;
image.GetImageSize(out width, out height);
HWidget.HalconWindow.SetPart(0, 0, width, height);
HWidget.HalconWindow.DispObj(image);
}
- 另外需要的动态库
可能需要安装目录下 \bin\x64-win64
的:
-
halcon.dll
可能会报错,找不到 halcon.dll
。
-
hcanvas.dll
:
调用 Halcon 控件的时候可能会报错:
HalconDotNet.HOperatorException:“HALCON error #5190: Invalid window parameter in operator set_window_param”
- 点击测试按钮