using System; using System.Collections.Generic; using System.Linq; using System.Text; using OpenCvSharp; namespace AtariRobot.Kaboom { public class KaboomScreen { public List Bombs { get; set; } public List Buckets { get; set; } public TemplateMatch Bomber { get; set; } public int BucketWidth { get; set; } public CvSize ScreenSize { get; set; } public void Display(IplImage screen) { double bucketHalfWidth = BucketWidth / 2.0; double bucketX = 0; if (Buckets.Count > 0) { bucketX = Buckets.Average(bucket => bucket.Location.X); } foreach (TemplateMatch bomb in Bombs) { CvColor bombColor = CvColor.Red; if (bomb.Location.X > bucketX + bucketHalfWidth || bomb.Location.X < bucketX - bucketHalfWidth) { bombColor = CvColor.Red; } else { bombColor = CvColor.Green; } screen.Circle(bomb.Location, 5, bombColor); //processedImage.PutText(bomb.Score.ToString(), bomb.Location, Helper.SmallFont, CvColor.Yellow); } CvColor bucketColor = CvColor.White; if (Bombs.Count != 0 && Buckets.Count != 0) { TemplateMatch lowestBomb = Bombs[0]; TemplateMatch highestBucket = Buckets[0]; int distance = Math.Abs(lowestBomb.Location.X - (int)bucketX) - (int)bucketHalfWidth; if (lowestBomb.Location.X < bucketX - bucketHalfWidth) { bucketColor = CvColor.Pink; Cv.DrawLine(screen, lowestBomb.Location.X, highestBucket.Location.Y, (int)(bucketX - bucketHalfWidth), highestBucket.Location.Y, bucketColor); Cv.PutText(screen, string.Format("<-- {0}", distance), new CvPoint((int)bucketX, highestBucket.Location.Y - 10), Helper.SmallFont, bucketColor); } else if (lowestBomb.Location.X > bucketX + bucketHalfWidth) { bucketColor = CvColor.Pink; Cv.DrawLine(screen, lowestBomb.Location.X, highestBucket.Location.Y, (int)(bucketX + bucketHalfWidth), highestBucket.Location.Y, bucketColor); Cv.PutText(screen, string.Format("{0} -->", distance), new CvPoint((int)bucketX, highestBucket.Location.Y - 10), Helper.SmallFont, bucketColor); } else { bucketColor = CvColor.LightGreen; } } foreach (TemplateMatch bucket in Buckets) { screen.Ellipse(bucket.Location, new CvSize(20, 5), 360, 0, 360, bucketColor); //processedImage.PutText(bucket.Score.ToString(), bucket.Location, Helper.SmallFont, CvColor.Yellow); } if (Bomber != null) { screen.Circle(Bomber.Location, 5, CvColor.Blue); //processedImage.PutText(screen.Bomber.Score.ToString(), screen.Bomber.Location, Helper.SmallFont, CvColor.Yellow); } } } }