轮胎外观检测添加思谋语义分割模型检测工具
C3204
2026-03-30 06c627ec032b3f3876fd7db8a3ff0ff1a6614fa2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using HalconDotNet;
using LB_SmartVisionCommon;
using LB_VisionControls;
using LB_VisionProcesses.Alogrithms.Halcon;
using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace LB_VisionProcesses.Alogrithms
{
    public class IntersectionLine2Tool : TAlgorithm
    {
        public IntersectionLine2Tool()
        {
            strProcessClass = "LB_VisionProcesses.Alogrithms.IntersectionLine2Tool";
            strProcessName = "线线交点工具";
 
            Params.Inputs.Add("基准线段", new HSegment());
            Params.Inputs.Add("相交线段", new HSegment());
            Params.Inputs.Add("是否期望有交点", true);
            Params.Inputs.Add("要求交点在线段上", false);
 
            Params.Outputs.Add("X", 0.0);
            Params.Outputs.Add("Y", 0.0);
            Params.Outputs.Add("Angle", 0.0);
            Params.Outputs.Add("HPoint", new HPoint());
        }
 
        /// <summary>
        /// 算子逻辑
        /// </summary>
        public override void TAlgorithmMain()
        {
            #region 初始化变量
 
            #endregion
 
            try
            {
                #region 裁剪区域
 
                #endregion
 
                #region 算子逻辑
                Record = new ObjectRecord();
                var oBaseSegment = Params.Inputs["基准线段"];
                var oInterSegment = Params.Inputs["相交线段"];
                bool bIntersection = Convert.ToBoolean(Params.Inputs["是否期望有交点"]);
                bool bOnSegment = Convert.ToBoolean(Params.Inputs["要求交点在线段上"]);
                double Angle = 0;
                Point2d? InterPoint = null;
                if (!(oBaseSegment is HSegment) || !(oInterSegment is HSegment))
                {
                    Msg = "输入的线段类型错误";
                    Result = false;
                    AsyncLogHelper.Error(Msg);
                    return;
                }
                HSegment BaseSegment = (HSegment)oBaseSegment;
                HSegment InterSegment = (HSegment)oInterSegment;
 
                try
                {
                    InterPoint = TAlgorithm.GetLineIntersection(BaseSegment.StartPoint.ToPoint2d(), BaseSegment.EndPoint.ToPoint2d()
                        , InterSegment.StartPoint.ToPoint2d(), InterSegment.EndPoint.ToPoint2d(), bOnSegment);
                    HOperatorSet.AngleLl(BaseSegment.StartPoint.Row, BaseSegment.StartPoint.Column, BaseSegment.EndPoint.Row, BaseSegment.EndPoint.Column
                        , InterSegment.StartPoint.Row, InterSegment.StartPoint.Column, InterSegment.EndPoint.Row, InterSegment.EndPoint.Column, out HTuple hv_Phi);
                    Angle = hv_Phi.D * 180.0 / Math.PI;
                }
                catch { Angle = 0; InterPoint = null; }
                #endregion
 
                #region 结果处理
                if (InterPoint == null)
                {
                    Params.Outputs["X"] = 0;
                    Params.Outputs["Y"] = 0;
                    Params.Outputs["Angle"] = Angle;
                    Params.Outputs["HPoint"] = new HPoint();
                }
                else
                {
                    HOperatorSet.GenCrossContourXld(out HObject CrossXld, InterPoint.Value.Y, InterPoint.Value.X, 20, 0);
                    Record.AddXld(CrossXld);
                    Params.Outputs["X"] = InterPoint.Value.X;
                    Params.Outputs["Y"] = InterPoint.Value.Y;
                    Params.Outputs["Angle"] = Angle;
                    Params.Outputs["HPoint"] = new HPoint(InterPoint.Value.X, InterPoint.Value.Y);
                }
                #endregion
 
                #region 生成OutputImage给后续处理
                try
                {
                    OutputImage = InputImage;
                }
                catch (Exception ex)
                {
                    Msg = "生成OutputImage失败,原因是:" + ex.ToString();
                    Result = false;
                    AsyncLogHelper.Error(Msg);
                    return;
                }
                #endregion
 
                if (Msg == "运行超时")
                {
                    Result = false;
                    return;
                }
 
                if (bIntersection && InterPoint == null)
                {
                    Msg = "两条线段没有交点";
                    Result = false;
                }
                else if (!bIntersection && InterPoint != null)
                {
                    Msg = "两条线段有交点";
                    Result = false;
                }
                AsyncLogHelper.Error(Msg);
                return;
            }
            catch (Exception ex)
            {
                Msg = "运行失败,原因是:" + ex.ToString().TrimEnd();
                OutputImage = null;
                Result = false;
                AsyncLogHelper.Error(Msg);
                return;
            }
            finally
            {
                bCompleted = true;
                #region 内存释放
 
                #endregion
            }
        }
    }
}