1.引入Halcon组件

2.项目配置文件
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="halcondotnet" publicKeyToken="4973BED59DDBF2B8"/>
<bindingRedirect oldVersion="12.0.0.0-12.0.65535.65535" newVersion="12.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="halcondotnetxl" publicKeyToken="4973BED59DDBF2B8"/>
<bindingRedirect oldVersion="12.0.0.0-12.0.65535.65535" newVersion="12.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="hdevenginedotnet" publicKeyToken="4973BED59DDBF2B8"/>
<bindingRedirect oldVersion="12.0.0.0-12.0.65535.65535" newVersion="12.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="hdevenginedotnetxl" publicKeyToken="4973BED59DDBF2B8"/>
<bindingRedirect oldVersion="12.0.0.0-12.0.65535.65535" newVersion="12.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
3.页面配置

4.halcon接口调用
public partial class HDevelopExport
{
public int ResultN;
public double usedTime;
public double[] Px;
public double[] Py;
public double Fx, Fy;
public double Cr = 9;
public double Cx, Cy;
public bool IsStart = false;
HTuple hv_R;
List<HTuple> Aa = new List<HTuple>();
HTuple hv_Angle, hv_Score, hv_Runtime;
HTuple hv_ModelID, hv_Row, hv_Column;
HObject ho_Mask;
HTuple hv_S1, hv_S2;
HObject ho_Image, ho_Rectangle, ho_ImageReduced;
public HTuple hv_ExpDefaultWinHandle;
HWindowControl HWindowControl;
/// <summary>
/// 打开相机
/// </summary>
public void OpenCamera()
{
//hv_ExpDefaultWinHandle = Window;
HOperatorSet.GenEmptyObj(out ho_Image); // 生ho_Image数据区
// Grabbing images from a Daheng USB 2.0 camera
HOperatorSet.CloseAllFramegrabbers();
HOperatorSet.OpenFramegrabber("DirectShow", 1, 1, 0, 0, 0, 0, "default", 8, "rgb",
-1, "false", "default", "[0] Integrated Camera", 0, -1, out hv_Angle);
HOperatorSet.SetFramegrabberParam(hv_Angle, "tilt", -3);
HOperatorSet.GrabImageStart(hv_Angle, -1);
//open camera with default settings
}
/// <summary>
/// 关闭相机
/// </summary>
public void CloseCamera()
{
HOperatorSet.CloseAllFramegrabbers();
}
/// <summary>
/// 实时播放
/// </summary>
public void RealTimePlayback()
{
IsStart = true;
//HObject ho_Image = null;
//HTuple hv_AcqHandle

本文档展示了如何在C#环境中集成Halcon组件,进行相机的开启、关闭、实时播放、拍照以及模板匹配等操作。通过调用Halcon接口,实现了图像的抓取、显示和模板匹配功能,可用于工业自动化中的目标检测。

2401

被折叠的 条评论
为什么被折叠?



