123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- using OpenCvSharp;
- using System;
- using System.Drawing;
- using static PaintDotNet.Base.DedicatedAnalysis.Inclusions.InclusionsGlobalSettings;
- using Point = System.Drawing.Point;
- namespace PaintDotNet.Base.DedicatedAnalysis.Inclusions.Model
- {
- /// <summary>
- /// 微粒(particle)
- /// 单个析出的沉淀物,一般为非金属。
- /// </summary>
- public class Particle
- {
- #region 属性
- /// <summary>
- /// 组成微粒的像素数组
- /// </summary>
- public OpenCvSharp.Point[] points;
- public Point[] points2;
- /// <summary>
- /// 当前微粒判定所使用的标准
- /// </summary>
- public InclusionsStandard standard;
- /// <summary>
- /// 水平距离
- /// </summary>
- public double horizontalDistance;
- /// <summary>
- /// 垂直距离
- /// </summary>
- public double verticalDistance;
- /// <summary>
- /// 像素长度
- /// </summary>
- public double pixelLength;
- /// <summary>
- /// 像素宽度
- /// </summary>
- public double pixelWidth;
- /// <summary>
- /// 物理长度
- /// </summary>
- public double physicalLength;
- /// <summary>
- /// 物理宽度
- /// </summary>
- public double physicalWidth;
- /// <summary>
- /// 长宽比
- /// </summary>
- public double lwRatio;
- /// <summary>
- /// 形状
- /// </summary>
- public ParticleShape shape;
- /// <summary>
- /// 矩形轮廓
- /// </summary>
- public Rectangle rectProfile;
- /// <summary>
- /// 矩形轮廓(K法)
- /// </summary>
- public Rectangle rectKMethodProfile;
- public double areaK;
- public int offsetX;
- public int offsetY;
- #endregion
- /// <summary>
- /// 构造方法
- /// </summary>
- /// <param name="points">组成微粒的像素数组</param>
- /// <param name="standard">当前微粒判定所使用的标准</param>
- public Particle(OpenCvSharp.Point[] points, InclusionsStandard standard)
- {
- this.points = points;
- this.points2 = new Point[points.Length];
- this.standard = standard;
- parametersCalculation();
- this.areaK = Cv2.ContourArea(points);
- }
- /// <summary>
- /// 参数计算
- /// </summary>
- private void parametersCalculation()
- {
- int minx = 0, miny = 0, maxx = 0, maxy = 0;
- for (int i = 0; i < this.points.Length; i++)
- {
- this.points2[i] = new Point(this.points[i].X, this.points[i].Y);
- if (i==0)
- {
- minx = this.points[i].X;
- maxx = this.points[i].X;
- miny = this.points[i].Y;
- maxy = this.points[i].Y;
- continue;
- }
- if (this.points[i].X < minx)
- {
- minx = this.points[i].X;
- }
- if (this.points[i].X > maxx)
- {
- maxx = this.points[i].X;
- }
- if (this.points[i].Y < miny)
- {
- miny = this.points[i].Y;
- }
- if (this.points[i].Y > maxy)
- {
- maxy = this.points[i].Y;
- }
- }
- // 计算
- this.horizontalDistance = maxx - minx;
- this.verticalDistance = maxy - miny;
- // 计算长度,宽度/直径,面积,长宽比
- // 计算长度,宽度/直径,面积,形状系数,长宽比
- if (this.standard.globalSettings.rollingDirection == RollingDirection.PORTRAIT)
- {
- this.pixelLength = maxy - miny;
- this.pixelWidth = maxx - minx;
- }
- else
- {
- this.pixelWidth = maxy - miny;
- this.pixelLength = maxx - minx;
- }
- this.rectProfile = new Rectangle(minx, miny, maxx - minx, maxy - miny);
- this.rectKMethodProfile = this.rectProfile;
- this.lwRatio = this.pixelLength / this.pixelWidth;
- if (this.lwRatio < this.standard.globalSettings.lwRatioLimit)
- {
- this.shape = ParticleShape.Globular;
- }
- else
- {
- this.shape = ParticleShape.Elongated;
- }
- this.physicalLength = this.pixelLength * this.standard.globalSettings.pxPerUnit;
- this.physicalWidth = this.pixelWidth * this.standard.globalSettings.pxPerUnit;
- }
- }
- }
|