0
点赞
收藏
分享

微信扫一扫

C# WPF 联合 Halcon 环境测试:加载一张图片

  1. 引用 dll

在 Halcon 安装目录下的 ​​bin\dotnet35​​​ 引用 ​​halcondotnet.dll​​。

  1. 包含命名空间:

 xmlns:halcon="clr-namespace:HalconDotNet;assembly=halcondotnet"

  1. 测试代码:

界面:

<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);
}

  1. 另外需要的动态库

可能需要安装目录下 ​​\bin\x64-win64​​ 的:

  • ​halcon.dll​

可能会报错,找不到 ​​halcon.dll​​ 。

  • ​hcanvas.dll​​:

调用 Halcon 控件的时候可能会报错:

HalconDotNet.HOperatorException:“HALCON error #5190: Invalid window parameter in operator set_window_param”

  1. 点击测试按钮

C# WPF 联合 Halcon 环境测试:加载一张图片_动态库



举报

相关推荐

0 条评论