/// <summary> /// Поиск изображений на карте /// </summary> /// <param name="map">Карта</param> /// <param name="masks">Искомые изображения</param> /// <param name="detected">Результат поиска</param> public void Detect(int[,] map, ArrayList masks, ArrayList detected) { var horizontalColors = new Dictionary<int, Dictionary<int, int>>(); var verticalColors = new Dictionary<int, Dictionary<int, int>>(); CalculateArrayAxes(map, horizontalColors, verticalColors); // Теперь сравниваем с каждой маской foreach (MaskItem mask in masks) { int ySimilarity = 0; for (int y = 30; y < map.GetLength(1) - 100; ++y) { if ( verticalColors[y].ContainsKey(mask.MaxColorValue) && verticalColors[y][mask.MaxColorValue] >= 2 ) { ySimilarity++; Console.WriteLine(String.Format("Y {0,4} {1,4} {2}", y, ySimilarity, mask.Name)); if (ySimilarity >= mask.Height) { int xSimilarity = 0; for (int x = 100; x < map.GetLength(0) - 100; ++x) { Console.WriteLine(String.Format("{0,4} {1,4} {2}", x, y, mask.Name)); if ( horizontalColors[x].ContainsKey(mask.MaxColorValue) && horizontalColors[x][mask.MaxColorValue] >= 2 ) { xSimilarity++; if (xSimilarity >= mask.Width) { if (TestBlock(map, mask, detected, x - mask.Width, y - mask.Height)) { DetectedItem detectedItem = new DetectedItem(); detectedItem.Mask = mask; detectedItem.X = x - mask.Width; detectedItem.Y = y - mask.Height; detected.Add(detectedItem); Console.WriteLine("Detected: " + mask.Name); if (detected.Count > 10) { Console.WriteLine("Max detected mask reached."); return; } x += mask.Width; continue; } } } else { xSimilarity = 0; } } } } else { ySimilarity = 0; } } } //DetectedItem sample = new DetectedItem(); //sample.Mask = (MaskItem)masks[0]; //sample.X = 100; //sample.Y = 150; //detected.Add(sample); }
/// <summary> /// Поиск изображений на карте /// </summary> /// <param name="map">Карта</param> /// <param name="masks">Искомые изображения</param> /// <param name="detected">Результат поиска</param> public void Detect(int[,] map, ArrayList masks, ArrayList detected) { var horizontalColors = new Dictionary <int, Dictionary <int, int> >(); var verticalColors = new Dictionary <int, Dictionary <int, int> >(); CalculateArrayAxes(map, horizontalColors, verticalColors); // Теперь сравниваем с каждой маской foreach (MaskItem mask in masks) { int ySimilarity = 0; for (int y = 30; y < map.GetLength(1) - 100; ++y) { if ( verticalColors[y].ContainsKey(mask.MaxColorValue) && verticalColors[y][mask.MaxColorValue] >= 2 ) { ySimilarity++; Console.WriteLine(String.Format("Y {0,4} {1,4} {2}", y, ySimilarity, mask.Name)); if (ySimilarity >= mask.Height) { int xSimilarity = 0; for (int x = 100; x < map.GetLength(0) - 100; ++x) { Console.WriteLine(String.Format("{0,4} {1,4} {2}", x, y, mask.Name)); if ( horizontalColors[x].ContainsKey(mask.MaxColorValue) && horizontalColors[x][mask.MaxColorValue] >= 2 ) { xSimilarity++; if (xSimilarity >= mask.Width) { if (TestBlock(map, mask, detected, x - mask.Width, y - mask.Height)) { DetectedItem detectedItem = new DetectedItem(); detectedItem.Mask = mask; detectedItem.X = x - mask.Width; detectedItem.Y = y - mask.Height; detected.Add(detectedItem); Console.WriteLine("Detected: " + mask.Name); if (detected.Count > 10) { Console.WriteLine("Max detected mask reached."); return; } x += mask.Width; continue; } } } else { xSimilarity = 0; } } } } else { ySimilarity = 0; } } } //DetectedItem sample = new DetectedItem(); //sample.Mask = (MaskItem)masks[0]; //sample.X = 100; //sample.Y = 150; //detected.Add(sample); }