Question: Write C# Windows Form App code to determine the central position of the video in the picturebox to find if the red object lies to
Write C# Windows Form App code to determine the central position of the video in the picturebox to find if the red object lies to the left or right of the video in the camera.
I have detected the red object using following code. I would like to determine the "pixel location" of the red object and check if it lies to the "left of the central position in the video" or to the right.
ColorFiltering colorfilter = new ColorFiltering(); colorfilter.Red = new IntRange(Red, (int)numericUpDownRed.Value); colorfilter.Green = new IntRange(Green, (int)numericUpDownGreen.Value); colorfilter.Blue = new IntRange(Blue, (int)numericUpDownBlue.Value); colorfilter.ApplyInPlace(video2);
//BlobCounter BlobCounter blobcounter = new BlobCounter(); blobcounter.MinHeight = 20; blobcounter.MinWidth = 20; blobcounter.ObjectsOrder = ObjectsOrder.Size; blobcounter.ProcessImage(video2); Rectangle[] rect = blobcounter.GetObjectsRectangles(); if (rect.Length > 0) { Rectangle target = rect[0]; Graphics graphic = Graphics.FromImage(video2); // To apply Grapghics on video2, that is, pictureBox2.
g = Graphics.FromImage(video2); using (Pen pen = new Pen(Color.White, 3)) {
graphic.DrawRectangle(pen, target);
g.DrawString("Target Located !", new Font("Arial", 20), new SolidBrush(Color.White), new PointF(2, 2)); // to demonstrate 'recognition' of target. g.Dispose(); } graphic.Dispose(); } pictureBox2.Image = video2; } pictureBox1.Image = video;
Step by Step Solution
There are 3 Steps involved in it
To determine whether the detected red object lies to the left or right of the central position of the video in the PictureBox you need to calculate th... View full answer
Get step-by-step solutions from verified subject matter experts
