Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new ImageDetection by merging the blobs of other detections. Requires the input ImageDetections to have <see cref="ObjectPoints"/> property.
        /// </summary>
        /// <param name="Detections">The list of input detections to merge.</param>
        /// <returns>A new instance of ImageDetection.</returns>
        public static ImageDetection MergeStandardDetections(ImageDetection[] Detections)
        {
            List <PixelPoint> Pixels   = new List <PixelPoint>();
            List <double>     Values   = new List <double>();
            PairingProperties KeptProp = null;

            foreach (ImageDetection imd in Detections)
            {
                if (imd.TryFetchProperty(out ObjectPoints ojp))
                {
                    Pixels.AddRange(ojp.PixelPoints);
                    Values.AddRange(ojp.PixelValues);
                    imd.TryFetchProperty(out PairingProperties Kprop);
                    if (KeptProp == null)
                    {
                        KeptProp = Kprop;
                    }
                    else
                    {
                        KeptProp.Algorithm |= Kprop.Algorithm;
                    }
                }
            }

            if (Pixels.Count == 0)
            {
                if (Detections.Length != 1)
                {
                    if (KeptProp == null)
                    {
                        KeptProp = new PairingProperties();
                    }
                    KeptProp.MultiNoPoints = true;
                }
                return(Detections[0]);
            }
            ImageDetection Result = StandardDetectionFactory.CreateDetection(Detections[0].ParentImage, Pixels, Values);

            if (KeptProp != null)
            {
                Result.SetResetProperty(KeptProp);
            }
            return(Result);
        }