public void Verify_Target_Test1_ValidateGlobalCoodinates() { var snapper = new SnapperImageArray("map", snapperImageArray); var target = new TargetImageArray("test1", targetArray, ' '); var expected = new Coordinate(5.5, 7.5); var actual = ITargetImage.CalculateGlobalCoordinatesOfShapeCentroid(target, 4, 5); Assert.AreEqual(expected, actual); }
public Scan(ISnapperImage snapperImage, ITargetImage targetImage, int horizontalOffset, int verticalOffset, double minimumConfidenceInTargetPrecision) { SnapperImage = snapperImage; TargetImage = targetImage; this.HorizontalOffset = horizontalOffset; this.VerticalOffset = verticalOffset; MinimumConfidenceInTargetPrecision = minimumConfidenceInTargetPrecision; CentroidGlobalCoordinates = ITargetImage.CalculateGlobalCoordinatesOfShapeCentroid(TargetImage, HorizontalOffset, VerticalOffset); TopLHCornerGlobalCoordinates = new Coordinate(HorizontalOffset, VerticalOffset); ScanImageForTarget(); }
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); }
public TargetImageArray(string name, char[,] array, char blankCharacter) { this.Name = name; this.GridRepresentation = array; this.InternalShapeCoordinatesOfTarget = ITargetImage.CalculateCoordinatesInsidePerimeterOfObject(this, blankCharacter); this.CentroidLocalCoordinates = CalculateLocalCoordinatesOfShapeCentroid(array); bool targetOK = ITargetImage.VerifyTargetHasADefinedShape(InternalShapeCoordinatesOfTarget); if (!targetOK) { throw new Exception("Target is not defined by a particular shape - please check input and try again."); } }
public TargetImageTextFile(string name, string filePath, char blankCharacter) { this.Name = name; this.FilePath = filePath; this.GridRepresentation = ConvertTextFileInto2DArray(filePath).TrimArray(blankCharacter); this.InternalShapeCoordinatesOfTarget = ITargetImage.CalculateCoordinatesInsidePerimeterOfObject(this, blankCharacter); this.CentroidLocalCoordinates = CalculateLocalCoordinatesOfShapeCentroid(); bool targetOK = ITargetImage.VerifyTargetHasADefinedShape(InternalShapeCoordinatesOfTarget); if (!targetOK) { throw new Exception("Target is not defined by a particular shape - please check input and try again."); } }
private void ScanForTarget(ITargetImage target) { int snapperImageRows = SnapperImage.GridRepresentation.GetLength(0); int snapperImageColumns = SnapperImage.GridRepresentation.GetLength(1); int targetRows = target.GridRepresentation.GetLength(0); int targetCols = target.GridRepresentation.GetLength(1); int maximumHorizontalOffset = snapperImageColumns - targetCols; int maximumVerticalOffset = snapperImageRows - targetRows; for (int i = 0; i <= maximumVerticalOffset; i++) { for (int j = 0; j <= maximumHorizontalOffset; j++) { Scan s = new Scan(SnapperImage, target, j, i, MinimumConfidenceInTargetPrecision); _rawScans.Add(s); } } }