增加查找线工具

This commit is contained in:
liu.wenjie
2019-08-04 21:51:40 +08:00
committed by liu.wenjie
parent 61de0d1236
commit 9d8944dcc3
256 changed files with 719371 additions and 778 deletions

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HalconDotNet;
namespace CommonMethods
{
public class ComGlobalParams
{
public static HObject inputImageGlobal
{
get
{
HObject inputImage = new HObject();
HOperatorSet.ReadImage(out inputImage, @"G:\Outer_HB.bmp");
return inputImage;
}
set
{
}
}
}
}

View File

@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{1C8D0DDC-2086-48A9-9586-F2B643E2FC54}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CommonMethods</RootNamespace>
<AssemblyName>CommonMethods</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="halcondotnet">
<HintPath>C:\Program Files\MVTec\HALCON-19.05-Progress\bin\dotnet20\halcondotnet.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ComGlobalParams.cs" />
<Compile Include="CommonMethods.cs" />
<Compile Include="Interface\CommonStruct.cs" />
<Compile Include="Interface\IToolInfo.cs" />
<Compile Include="Interface\IVisionJobInterface.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,192 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HalconDotNet;
namespace CommonMethods
{
public class CommonMethods
{
/// <summary>
/// 延时操作
/// </summary>
/// <param name="mm"></param>
public static void Delay(int mm)
{
DateTime delay = DateTime.Now.AddMilliseconds((double)mm);
while (delay > DateTime.Now)
{
Application.DoEvents();
}
}
/// <summary>
/// Creates an arrow shaped XLD contour.
/// </summary>
/// <param name="ho_Arrow">生成的箭头</param>
/// <param name="hv_Row1">箭头起点Row</param>
/// <param name="hv_Column1">箭头起点Column</param>
/// <param name="hv_Row2">箭头终点Row</param>
/// <param name="hv_Column2">箭头终点Column</param>
/// <param name="hv_HeadLength">头长度</param>
/// <param name="hv_HeadWidth">头宽度</param>
public static void gen_arrow_contour_xld(out HObject ho_Arrow, HTuple hv_Row1, HTuple hv_Column1,
HTuple hv_Row2, HTuple hv_Column2, HTuple hv_HeadLength, HTuple hv_HeadWidth)
{
// Stack for temporary objects
HObject[] OTemp = new HObject[20];
// Local iconic variables
HObject ho_TempArrow = null;
// Local control variables
HTuple hv_Length = new HTuple(), hv_ZeroLengthIndices = new HTuple();
HTuple hv_DR = new HTuple(), hv_DC = new HTuple(), hv_HalfHeadWidth = new HTuple();
HTuple hv_RowP1 = new HTuple(), hv_ColP1 = new HTuple();
HTuple hv_RowP2 = new HTuple(), hv_ColP2 = new HTuple();
HTuple hv_Index = new HTuple();
// Initialize local and output iconic variables
HOperatorSet.GenEmptyObj(out ho_Arrow);
HOperatorSet.GenEmptyObj(out ho_TempArrow);
//This procedure generates arrow shaped XLD contours,
//pointing from (Row1, Column1) to (Row2, Column2).
//If starting and end point are identical, a contour consisting
//of a single point is returned.
//
//input parameteres:
//Row1, Column1: Coordinates of the arrows' starting points
//Row2, Column2: Coordinates of the arrows' end points
//HeadLength, HeadWidth: Size of the arrow heads in pixels
//
//output parameter:
//Arrow: The resulting XLD contour
//
//The input tuples Row1, Column1, Row2, and Column2 have to be of
//the same length.
//HeadLength and HeadWidth either have to be of the same length as
//Row1, Column1, Row2, and Column2 or have to be a single element.
//If one of the above restrictions is violated, an error will occur.
//
//
//Init
ho_Arrow.Dispose();
HOperatorSet.GenEmptyObj(out ho_Arrow);
//
//Calculate the arrow length
hv_Length.Dispose();
HOperatorSet.DistancePp(hv_Row1, hv_Column1, hv_Row2, hv_Column2, out hv_Length);
//
//Mark arrows with identical start and end point
//(set Length to -1 to avoid division-by-zero exception)
hv_ZeroLengthIndices.Dispose();
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
hv_ZeroLengthIndices = hv_Length.TupleFind(
0);
}
if ((int)(new HTuple(hv_ZeroLengthIndices.TupleNotEqual(-1))) != 0)
{
if (hv_Length == null)
hv_Length = new HTuple();
hv_Length[hv_ZeroLengthIndices] = -1;
}
//
//Calculate auxiliary variables.
hv_DR.Dispose();
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
hv_DR = (1.0 * (hv_Row2 - hv_Row1)) / hv_Length;
}
hv_DC.Dispose();
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
hv_DC = (1.0 * (hv_Column2 - hv_Column1)) / hv_Length;
}
hv_HalfHeadWidth.Dispose();
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
hv_HalfHeadWidth = hv_HeadWidth / 2.0;
}
//
//Calculate end points of the arrow head.
hv_RowP1.Dispose();
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
hv_RowP1 = (hv_Row1 + ((hv_Length - hv_HeadLength) * hv_DR)) + (hv_HalfHeadWidth * hv_DC);
}
hv_ColP1.Dispose();
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
hv_ColP1 = (hv_Column1 + ((hv_Length - hv_HeadLength) * hv_DC)) - (hv_HalfHeadWidth * hv_DR);
}
hv_RowP2.Dispose();
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
hv_RowP2 = (hv_Row1 + ((hv_Length - hv_HeadLength) * hv_DR)) - (hv_HalfHeadWidth * hv_DC);
}
hv_ColP2.Dispose();
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
hv_ColP2 = (hv_Column1 + ((hv_Length - hv_HeadLength) * hv_DC)) + (hv_HalfHeadWidth * hv_DR);
}
//
//Finally create output XLD contour for each input point pair
for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_Length.TupleLength())) - 1); hv_Index = (int)hv_Index + 1)
{
if ((int)(new HTuple(((hv_Length.TupleSelect(hv_Index))).TupleEqual(-1))) != 0)
{
//Create_ single points for arrows with identical start and end point
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
ho_TempArrow.Dispose();
HOperatorSet.GenContourPolygonXld(out ho_TempArrow, hv_Row1.TupleSelect(hv_Index),
hv_Column1.TupleSelect(hv_Index));
}
}
else
{
//Create arrow contour
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
ho_TempArrow.Dispose();
HOperatorSet.GenContourPolygonXld(out ho_TempArrow, ((((((((((hv_Row1.TupleSelect(
hv_Index))).TupleConcat(hv_Row2.TupleSelect(hv_Index)))).TupleConcat(
hv_RowP1.TupleSelect(hv_Index)))).TupleConcat(hv_Row2.TupleSelect(hv_Index)))).TupleConcat(
hv_RowP2.TupleSelect(hv_Index)))).TupleConcat(hv_Row2.TupleSelect(hv_Index)),
((((((((((hv_Column1.TupleSelect(hv_Index))).TupleConcat(hv_Column2.TupleSelect(
hv_Index)))).TupleConcat(hv_ColP1.TupleSelect(hv_Index)))).TupleConcat(
hv_Column2.TupleSelect(hv_Index)))).TupleConcat(hv_ColP2.TupleSelect(
hv_Index)))).TupleConcat(hv_Column2.TupleSelect(hv_Index)));
}
}
{
HObject ExpTmpOutVar_0;
HOperatorSet.ConcatObj(ho_Arrow, ho_TempArrow, out ExpTmpOutVar_0);
ho_Arrow.Dispose();
ho_Arrow = ExpTmpOutVar_0;
}
}
ho_TempArrow.Dispose();
hv_Length.Dispose();
hv_ZeroLengthIndices.Dispose();
hv_DR.Dispose();
hv_DC.Dispose();
hv_HalfHeadWidth.Dispose();
hv_RowP1.Dispose();
hv_ColP1.Dispose();
hv_RowP2.Dispose();
hv_ColP2.Dispose();
hv_Index.Dispose();
return;
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,141 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CommonMethods
{
public class IToolInfo
{
/// <summary>
/// 工具是否启用
/// </summary>
public bool enable { get; set; }
/// <summary>
/// 工具名称
/// </summary>
public string toolName { get; set; }
/// <summary>
/// 工具类型
/// </summary>
public ToolType toolType { get; set; }
/// <summary>
/// 工具对象
/// </summary>
public object tool { get; set; }
/// <summary>
/// 工具窗体
/// </summary>
public Form FormTool { get; set; }
/// <summary>
/// 工具窗体名
/// </summary>
public string FormToolName { get; set; }
/// <summary>
/// 工具描述信息
/// </summary>
public string toolTipInfo { get; set; }
/// <summary>
/// 工具输入字典集合
/// </summary>
public List<ToolIO> toolInput { get; set; }
/// <summary>
/// 工具输出字典集合
/// </summary>
public List<ToolIO> toolOutput { get; set; }
/// <summary>
/// 工具作用描述
/// </summary>
public string toolDescription { get; set; }
/// <summary>
/// 工具运行结果
/// </summary>
public ToolRunStatu toolRunStatu { get; set; }
public IToolInfo()
{
enable = true;
toolType = ToolType.None;
toolName = string.Empty;
tool = new object();
toolInput = new List<ToolIO>();
toolOutput = new List<ToolIO>();
}
/// <summary>
/// 以IO名获取IO对象
/// </summary>
/// <param name="IOName"></param>
/// <returns></returns>
public ToolIO GetInput(string IOName)
{
for (int i = 0; i < toolInput.Count; i++)
{
if (toolInput[i].IOName == IOName)
return toolInput[i];
}
return new ToolIO();
}
/// <summary>
/// 以IO名获取IO对象
/// </summary>
/// <param name="IOName"></param>
/// <returns></returns>
public ToolIO GetOutput(string IOName)
{
for (int i = 0; i < toolOutput.Count; i++)
{
if (toolOutput[i].IOName == IOName)
return toolOutput[i];
}
return new ToolIO();
}
/// <summary>
/// 移除工具输入项
/// </summary>
/// <param name="IOName"></param>
public void RemoveInputIO(string IOName)
{
for (int i = 0; i < toolInput.Count; i++)
{
if (toolInput[i].IOName == toolName)
toolInput.RemoveAt(i);
}
}
/// <summary>
/// 移除工具输出项
/// </summary>
/// <param name="IOName"></param>
public void RemoveOutputIO(string IOName)
{
for (int i = 0; i < toolOutput.Count; i++)
{
if (toolOutput[i].IOName == toolName)
toolOutput.RemoveAt(i);
}
}
}
/// <summary>
/// 工具的输入输出类
/// </summary>
[Serializable]
public class ToolIO
{
public string IOName;
public object value;
public DataType ioType;
public ToolIO() { }
public ToolIO(string IOName1, object value1, DataType ioType1)
{
this.IOName = IOName1;
this.value = value1;
this.ioType = ioType1;
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
F:\VSCode\VisionEditTest\CommonMethods\bin\Debug\CommonMethods.dll
F:\VSCode\VisionEditTest\CommonMethods\bin\Debug\CommonMethods.pdb
F:\VSCode\VisionEditTest\CommonMethods\bin\Debug\halcondotnet.dll
F:\VSCode\VisionEditTest\CommonMethods\bin\Debug\halcondotnet.xml
F:\VSCode\VisionEditTest\CommonMethods\obj\Debug\CommonMethods.dll
F:\VSCode\VisionEditTest\CommonMethods\obj\Debug\CommonMethods.pdb
F:\VSCode\VisionEditTest\CommonMethods\obj\Debug\CommonHelper.csprojResolveAssemblyReference.cache

View File

@@ -0,0 +1,4 @@
F:\VSCode\VisionEditTest\CommonMethods\bin\Debug\CommonMethods.dll
F:\VSCode\VisionEditTest\CommonMethods\bin\Debug\CommonMethods.pdb
F:\VSCode\VisionEditTest\CommonMethods\obj\Debug\CommonMethods.dll
F:\VSCode\VisionEditTest\CommonMethods\obj\Debug\CommonMethods.pdb

Binary file not shown.

Binary file not shown.