123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- using OpenCvSharp;
- //using PaintDotNet.Base.DedicatedAnalysis.GrainSize.Model;
- using System.Collections.Generic;
- using System.Drawing;
- namespace PaintDotNet.Base.DedicatedAnalysis.GrainSize
- {
- /// <summary>
- /// 夹杂物标准
- /// </summary>
- public abstract class GrainSizeStandard
- {
- public static Color[] RAINBOW_COLORS = { Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Cyan, Color.Purple };
- /// <summary>
- /// 设置
- /// </summary>
- public GrainSizeGlobalSettings globalSettings = new GrainSizeGlobalSettings();
- //#region 识别测量区域中的微粒
- ///// <summary>
- ///// 识别测量区域中的微粒
- ///// </summary>
- ///// <param name="field">视场</param>
- ///// <returns>识别出的微粒列表</returns>
- //public virtual List<Particle> identifyParticles(Mat field)
- //{
- // Cv2.Threshold(field, field, 175, 255, ThresholdTypes.BinaryInv);
- // OpenCvSharp.Point[][] contours;
- // HierarchyIndex[] hierarchy;
- // Cv2.FindContours(field, out contours, out hierarchy, RetrievalModes.Tree, ContourApproximationModes.ApproxNone);
-
- // List<Particle> particles = new List<Particle>();
-
- // for (int i = 0; i < contours.Length; i++)
- // {
- // if (hierarchy[i].Parent != -1)
- // {
- // continue;
- // }
- // OpenCvSharp.Point[] contour = contours[i];
- // particles.Add(new Particle(contour, this));
- // }
- // return particles;
- //}
- //#endregion
- //#region 过滤微粒
- ///// <summary>
- ///// 过滤微粒
- ///// </summary>
- ///// 使用minimumLength,minimumWidth最小尺寸来过滤微粒
- ///// <param name="particles">过滤前的微粒列表</param>
- ///// <returns>过滤后的微粒列表</returns>
- //public virtual List<Particle> filterParticles(List<Particle> particles)
- //{
- // for (int i = particles.Count - 1; i >= 0; i--)
- // {
- // Particle particle = particles[i];
- // if (particle.physicalLength < this.globalSettings.minimumLength ||
- // particle.physicalWidth < this.globalSettings.minimumWidth)
- // {
- // particles.Remove(particle);
- // }
- // }
- // return particles;
- //}
- //#endregion
- //#region 划分夹杂物
- ///// <summary>
- ///// 划分夹杂物
- ///// </summary>
- ///// 使用distancesBetweenParticles,distancesBetweenStringers划分夹杂物
- ///// <param name="particles">过滤后的微粒列表</param>
- ///// <returns>夹杂物列表</returns>
- //public virtual List<Inclusion> divideInclusion(List<Particle> particles)
- //{
- // return this.inclusionsDivideInclusion(this.particlesDivideInclusion(particles));
- //}
- //#endregion
- //#region 微粒划分夹杂物
- ///// <summary>
- ///// 微粒划分夹杂物
- ///// </summary>
- ///// <param name="particles">过滤后的微粒列表</param>
- ///// <returns>夹杂物列表</returns>
- //protected virtual List<Inclusion> particlesDivideInclusion(List<Particle> particles)
- //{
- // List<Inclusion> inclusions = new List<Inclusion>();
- // // 第一次划分 微粒划分夹杂物
- // foreach (Particle particle in particles)
- // {
- // if (inclusions.Count == 0)
- // {
- // Inclusion inclusion = new Inclusion(this);
- // inclusion.addParticles(particle);
- // inclusions.Add(inclusion);
- // continue;
- // }
- // foreach (Inclusion inclusion in inclusions)
- // {
- // if (inclusion.particles[0].shape != particle.shape)
- // {
- // continue;
- // }
- // // 矩形相交
- // if (inclusion.rectProfile.IntersectsWith(particle.rectProfile))
- // {
- // inclusion.addParticles(particle);
- // goto particleJump;
- // }
- // else
- // {
- // int verticalDistancePx = this.globalSettings.distancesBetweenParticlesE, horizontalDistancePx = this.globalSettings.distancesBetweenParticlesT;
- // // 先比较垂直距离
- // if (this.globalSettings.rollingDirection == InclusionsGlobalSettings.RollingDirection.PORTRAIT)
- // {
- // if (particle.rectProfile.Bottom < inclusion.rectProfile.Top)
- // {
- // verticalDistancePx = inclusion.rectProfile.Top - particle.rectProfile.Bottom;
- // }
- // if (particle.rectProfile.Top > inclusion.rectProfile.Bottom)
- // {
- // verticalDistancePx = particle.rectProfile.Top - inclusion.rectProfile.Bottom;
- // }
- // if (particle.rectProfile.Right < inclusion.rectProfile.Left)
- // {
- // horizontalDistancePx = inclusion.rectProfile.Left - particle.rectProfile.Right;
- // }
- // if (particle.rectProfile.Left > inclusion.rectProfile.Right)
- // {
- // horizontalDistancePx = particle.rectProfile.Left - inclusion.rectProfile.Right;
- // }
- // }
- // else
- // {
- // if (particle.rectProfile.Bottom < inclusion.rectProfile.Top)
- // {
- // horizontalDistancePx = inclusion.rectProfile.Top - particle.rectProfile.Bottom;
- // }
- // if (particle.rectProfile.Top > inclusion.rectProfile.Bottom)
- // {
- // horizontalDistancePx = particle.rectProfile.Top - inclusion.rectProfile.Bottom;
- // }
- // if (particle.rectProfile.Right < inclusion.rectProfile.Left)
- // {
- // verticalDistancePx = inclusion.rectProfile.Left - particle.rectProfile.Right;
- // }
- // if (particle.rectProfile.Left > inclusion.rectProfile.Right)
- // {
- // verticalDistancePx = particle.rectProfile.Left - inclusion.rectProfile.Right;
- // }
- // }
- // if (verticalDistancePx * this.globalSettings.pxPerUnit <= this.globalSettings.distancesBetweenParticlesE &&
- // horizontalDistancePx * this.globalSettings.pxPerUnit <= this.globalSettings.distancesBetweenParticlesT)
- // {
- // inclusion.addParticles(particle);
- // goto particleJump;
- // }
- // }
- // }
- // Inclusion newInclusion = new Inclusion(this);
- // newInclusion.addParticles(particle);
- // inclusions.Add(newInclusion);
- // particleJump:;
- // }
- // return inclusions;
- //}
- //#endregion
- //#region 夹杂物划分夹杂物(合并)
- ///// <summary>
- ///// 夹杂物划分夹杂物(合并)
- ///// </summary>
- ///// <param name="inclusions">夹杂物列表</param>
- ///// <returns>夹杂物列表</returns>
- //protected virtual List<Inclusion> inclusionsDivideInclusion(List<Inclusion> inclusions)
- //{
- // // 第二次划分 夹杂物间划分
- // for (int i = 0; i < inclusions.Count; i++)
- // {
- // if (i > inclusions.Count - 1)
- // {
- // break;
- // }
- // Inclusion inclusion = inclusions[i];
- // for (int o = inclusions.Count - 1; o > i; o--)
- // {
- // if (o > inclusions.Count - 1)
- // {
- // break;
- // }
- // // 矩形相交
- // if (inclusion.rectProfile.IntersectsWith(inclusions[o].rectProfile))
- // {
- // inclusion.addParticles(inclusions[o].particles);
- // inclusions.RemoveAt(o);
- // }
- // else
- // {
- // if (inclusions[o].particles[0].shape != inclusion.particles[0].shape)
- // {
- // continue;
- // }
- // int verticalDistancePx = this.globalSettings.distancesBetweenParticlesE, horizontalDistancePx = this.globalSettings.distancesBetweenParticlesT;
- // // 先比较垂直距离
- // if (this.globalSettings.rollingDirection == InclusionsGlobalSettings.RollingDirection.PORTRAIT)
- // {
- // if (inclusions[o].rectProfile.Bottom < inclusion.rectProfile.Top)
- // {
- // verticalDistancePx = inclusion.rectProfile.Top - inclusions[o].rectProfile.Bottom;
- // }
- // if (inclusions[o].rectProfile.Top > inclusion.rectProfile.Bottom)
- // {
- // verticalDistancePx = inclusions[o].rectProfile.Top - inclusion.rectProfile.Bottom;
- // }
- // if (inclusions[o].rectProfile.Right < inclusion.rectProfile.Left)
- // {
- // horizontalDistancePx = inclusion.rectProfile.Left - inclusions[o].rectProfile.Right;
- // }
- // if (inclusions[o].rectProfile.Left > inclusion.rectProfile.Right)
- // {
- // horizontalDistancePx = inclusions[o].rectProfile.Left - inclusion.rectProfile.Right;
- // }
- // }
- // else
- // {
- // if (inclusions[o].rectProfile.Bottom < inclusion.rectProfile.Top)
- // {
- // horizontalDistancePx = inclusion.rectProfile.Top - inclusions[o].rectProfile.Bottom;
- // }
- // if (inclusions[o].rectProfile.Top > inclusion.rectProfile.Bottom)
- // {
- // horizontalDistancePx = inclusions[o].rectProfile.Top - inclusion.rectProfile.Bottom;
- // }
- // if (inclusions[o].rectProfile.Right < inclusion.rectProfile.Left)
- // {
- // verticalDistancePx = inclusion.rectProfile.Left - inclusions[o].rectProfile.Right;
- // }
- // if (inclusions[o].rectProfile.Left > inclusion.rectProfile.Right)
- // {
- // verticalDistancePx = inclusions[o].rectProfile.Left - inclusion.rectProfile.Right;
- // }
- // }
- // if (verticalDistancePx * this.globalSettings.pxPerUnit <= this.globalSettings.distancesBetweenParticlesE &&
- // horizontalDistancePx * this.globalSettings.pxPerUnit <= this.globalSettings.distancesBetweenParticlesT)
- // {
- // inclusion.addParticles(inclusions[o].particles);
- // inclusions.RemoveAt(o);
- // }
- // }
- // }
- // }
- // List<Inclusion> tobeCombined = new List<Inclusion>();
- // foreach (var item in inclusions)
- // {
- // if (item.particles.Count<3)
- // {
- // tobeCombined.Add(item);
- // }
- // }
- // inclusionsCombinationSplit(inclusions,tobeCombined);
- // return inclusions;
- //}
- //#endregion
- //#region 夹杂物组合
- ///// <summary>
- ///// 夹杂物组合
- ///// </summary>
- ///// <param name="allInclusions">全部的夹杂物</param>
- ///// <param name="tobeCombined">待合并的夹杂物</param>
- //public virtual List<Inclusion> inclusionsCombination(List<Inclusion> allInclusions, List<Inclusion> tobeCombined)
- //{
- // Inclusion inclusion = new Inclusion(this);
- // foreach (Inclusion item in tobeCombined)
- // {
- // inclusion.addParticles(item.particles);
- // allInclusions.Remove(item);
- // }
- // allInclusions.Add(inclusion);
- // return allInclusions;
- //}
- //#endregion
- //#region 夹杂物组合拆分
- ///// <summary>
- ///// 夹杂物组合拆分
- ///// </summary>
- ///// <param name="allInclusions">全部的夹杂物</param>
- ///// <param name="tobeCombined">待拆分的夹杂物</param>
- //public virtual List<Inclusion> inclusionsCombinationSplit(List<Inclusion> allInclusions, List<Inclusion> tobeCombined)
- //{
- // foreach (Inclusion item in tobeCombined)
- // {
- // foreach (Particle particle in item.particles)
- // {
- // Inclusion inclusion = new Inclusion(this);
- // inclusion.addParticles(particle);
- // allInclusions.Add(inclusion);
- // }
- // allInclusions.Remove(item);
- // }
- // return allInclusions;
- //}
- //#endregion
- ///// <summary>
- ///// 判断夹杂物类型
- ///// </summary>
- //public abstract void determineType(Inclusion inclusion);
- ///// <summary>
- ///// 边缘误差修正
- ///// </summary>
- ///// 根据视场边界修正所计算的夹杂物
- ///// <param name="inclusion"></param>
- //public abstract void edgeErrorsCorrection(List<Inclusion> inclusions);
- }
-
- }
|