示例#1
0
        private List <Scan> GetListOfNonDuplicateTargets(ITargetImage targetImage)
        {
            List <Scan> scansWithDuplicates = _rawScans.Where(scan => scan.TargetFound == true && scan.TargetImage.Name == targetImage.Name).ToList();

            int snapperImageRows    = SnapperImage.GridRepresentation.GetLength(0);
            int snapperImageColumns = SnapperImage.GridRepresentation.GetLength(1);

            int targetImageRows    = targetImage.GridRepresentation.GetLength(0);
            int targetImageColumns = targetImage.GridRepresentation.GetLength(1);

            for (int i = 0; i < snapperImageRows - targetImageRows; i++)
            {
                for (int j = 0; j < snapperImageColumns - targetImageColumns; j++)
                {
                    //Get a subarray from the snapperimagearray and look for squares which contain global centroids.
                    var subArray = MultiDimensionalCharacterArrayHelpers.GetSubArrayFromArray
                                       (SnapperImage.GridRepresentation, targetImage.GridRepresentation, j, i);

                    //For each element in the subarray, look for any targets in targetsFound
                    List <Scan> potentialDuplicates = new List <Scan>();

                    for (int k = 0; k < targetImageRows; k++)
                    {
                        for (int m = 0; m < targetImageColumns; m++)
                        {
                            int globalX     = j + k;
                            int globalY     = i + m;
                            var globalCords = new Coordinate(globalX, globalY);

                            //Look for any targets within targetsFound with matching coordinates, if so add to potentialDuplicates.
                            Scan scan =
                                scansWithDuplicates.Where(x => x.TopLHCornerGlobalCoordinates.X == globalX && x.TopLHCornerGlobalCoordinates.Y == globalY).FirstOrDefault();;
                            if (scan != null)
                            {
                                potentialDuplicates.Add(scan);
                            }
                        }
                    }

                    if (potentialDuplicates.Count > 1)
                    {
                        potentialDuplicates = potentialDuplicates.OrderByDescending(x => x.ConfidenceInTargetDetection).ToList();
                        for (int n = 1; n < potentialDuplicates.Count; n++)
                        {
                            scansWithDuplicates.Remove(potentialDuplicates[n]);
                        }
                    }
                }
            }

            return(scansWithDuplicates);
        }
示例#2
0
        /// <summary>
        /// Removes any rows or columns only containing a specific character, e.g. ' ' or 'X'.
        /// Note this does not trim any blank rows or columns within the main bulk of the array.
        /// For example, using the '0' as the "blank character".
        ///
        /// {000000}
        /// {0XXXX0}
        /// {000000}
        /// {00XX00}
        /// {00XX00}
        /// {000000}
        ///
        /// =>
        ///
        /// {XXXX}
        /// {0000}
        /// {0XX0}
        /// {0XX0}
        ///
        /// </summary>
        /// <param name="array">The array to trim empty rows and columns from.</param>
        /// <param name="ch">The "blank" character/</param>
        /// <returns></returns>
        public static char[,] TrimArray(this char[,] array, char ch)
        {
            //Get max and min column numbers where not blank.
            List <int> nonBlankRows = new List <int>();

            for (int i = 0; i < array.GetLength(0); i++)
            {
                if (MultiDimensionalCharacterArrayHelpers.CheckIfRowIsBlank(array, i, ch) == false)
                {
                    nonBlankRows.Add(i);
                }
            }

            int minNonBlankRow = nonBlankRows.Min();
            int maxNonBlankRow = nonBlankRows.Max();

            //Get max and min row numbers where not blank.
            List <int> nonBlankCols = new List <int>();

            for (int j = 0; j < array.GetLength(1); j++)
            {
                if (MultiDimensionalCharacterArrayHelpers.CheckIfColumnIsBlank(array, j, ch) == false)
                {
                    nonBlankCols.Add(j);
                }
            }

            int minNonBlankCol = nonBlankCols.Min();
            int maxNonBlankCol = nonBlankCols.Max();

            //Copy array between above constraints over to new array to be replaced.
            int numberOfRowsReqd = maxNonBlankRow - minNonBlankRow + 1;
            int numberOfColsReqd = maxNonBlankCol - minNonBlankCol + 1;

            char[,] trimmedArray = new char[numberOfRowsReqd, numberOfColsReqd];

            //For each row in the matrix
            for (int i = 0; i < numberOfRowsReqd; i++)
            {
                for (int j = 0; j < numberOfColsReqd; j++)
                {
                    trimmedArray[i, j] = array[i + minNonBlankRow, j + minNonBlankCol];
                }
            }

            return(trimmedArray);
        }