Exemplo n.º 1
0
 public void SetStop()
 {
     _state = NowState.Stop;
     // the behavior of ending
     FormMain.GetInstance().GetButton_BeginEnd().Text  = "Start";
     FormMain.GetInstance().GetButton_Sample().Enabled = false;
     VideoSourceDevice.End();
 }
Exemplo n.º 2
0
 public void SetStart()
 {
     _state = NowState.Start;
     // the behavior of starting
     FormMain.GetInstance().GetButton_BeginEnd().Text  = "End";
     FormMain.GetInstance().GetButton_Sample().Enabled = true;
     VideoSourceDevice.Start();
 }
Exemplo n.º 3
0
        private void buttonSample_Click(object sender, EventArgs e)
        {
            /*
             * Image tempImage = videoSourcePlayer.GetCurrentVideoFrame();
             * string tempPath = _tempFileManager.AddTempFile(tempImage);
             * TextureAnalysisResult textureResult = Cv.TextureAnalysis(tempPath);
             * FindCuttingPointResult cuttingPointResult = Cv.FindCuttingPoint(textureResult, Cv.FindCuttingPointMode.MaximumMethod);
             * Bitmap resultImage = textureResult.img.Resize(pictureBox.Width, pictureBox.Height, Inter.Linear, true).Bitmap;
             *
             * Bitmap newBitmap = new Bitmap(resultImage.Width, resultImage.Height);
             * Graphics g = Graphics.FromImage(newBitmap);
             * g.DrawImage(resultImage, 0, 0);
             * for (int i = 0; i < cuttingPointResult.Edges.Count; i++)
             * {
             *      float location = (float)cuttingPointResult.Edges[i] / cuttingPointResult.Accuracy * newBitmap.Width;
             *      g.DrawLine(new Pen(Color.Red, 4), location, 0 * newBitmap.Height, location, 1 * newBitmap.Height);
             * }
             * g.Dispose();
             *
             * pictureBox.Image = newBitmap;
             */
            string            tempPath = VideoSourceDevice.GetCurrentPicturePath();
            Image <Rgb, Byte> rawImage = new Image <Rgb, byte>(tempPath);

            double[] threshold1 = new double[]
            {
                200
            };
            double[] threshold2 = new double[]
            {
                200, 300, 400
            };
            CannyTextureAnalysisResult textureAnalysisResult = Cv.AutoCannyTextureAnalysis(rawImage, threshold1, threshold2, 0);
            ZedGraphForm tempZedGraphForm = new ZedGraphForm(textureAnalysisResult.Data);

            tempZedGraphForm.Show();
            MessageBox.Show(textureAnalysisResult.Info);
        }
Exemplo n.º 4
0
 public override void Init()
 {
     SetStop();
     VideoSourceDevice.Scan();
 }
Exemplo n.º 5
0
 private void comboBoxCaptureDevice_TextChanged(object sender, EventArgs e)
 {
     VideoSourceDevice.UpdateResolution();
 }
Exemplo n.º 6
0
        private void buttonSample_Click(object sender, EventArgs e)
        {
            Image <Rgb, Byte> rawImage;
            string            tempPath = VideoSourceDevice.GetCurrentPicturePath();

            try
            {
                rawImage = new Image <Rgb, byte>(tempPath);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                return;
            }

            double[] threshold1 = new double[]
            {
                200
            };
            double[] threshold2 = new double[]
            {
                200, 300, 400
            };
            CannyTextureAnalysisResult textureAnalysisResult = Cv.AutoCannyTextureAnalysis(rawImage, threshold1, threshold2, 0);
            float diff = textureAnalysisResult.Diff;

            /*
             * ZedGraphForm tempGraphForm = new ZedGraphForm(textureAnalysisResult.Data);
             * tempGraphForm.Show();
             */
            Debug.ShowImg(textureAnalysisResult.Img);

            textBoxConsole.AppendText("Center: " + textureAnalysisResult.Center + Environment.NewLine);

            // if center is close to 0.5, it means the car direction is nearly towards the path.
            float threadhold = 0.05f;

            if (Math.Abs(diff) > threadhold)
            {
                if (diff > threadhold)
                {
                    if (_previousDiff < -threadhold)
                    {
                        Arduino.GetInstance().Send(MotorDirection.Forward, 35, MotorDirection.Backward, 35, 200);
                    }
                    else
                    {
                        Arduino.GetInstance().Send(MotorDirection.Forward, 75, MotorDirection.Backward, 75, 200);
                    }
                }
                else if (diff < -threadhold)
                {
                    if (_previousDiff > threadhold)
                    {
                        Arduino.GetInstance().Send(MotorDirection.Backward, 35, MotorDirection.Forward, 35, 200);
                    }
                    else
                    {
                        Arduino.GetInstance().Send(MotorDirection.Backward, 75, MotorDirection.Forward, 75, 200);
                    }
                }
            }
            else
            {
                Arduino.GetInstance().Send(MotorDirection.Forward, 75, MotorDirection.Forward, 75, 200);
            }
            _previousDiff = diff;
        }
Exemplo n.º 7
0
 private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
 {
     _tempFileManager.ReleasePageFile();
     VideoSourceDevice.End();
 }
Exemplo n.º 8
0
        private static void G1T1Loop()
        {
            Image <Rgb, Byte> rawImage;
            string            tempPath = VideoSourceDevice.GetCurrentPicturePath();

            try
            {
                rawImage = new Image <Rgb, byte>(tempPath);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                return;
            }

            double[] threshold1 = new double[]
            {
                200
            };
            double[] threshold2 = new double[]
            {
                200, 300, 400
            };
            CannyTextureAnalysisResult textureAnalysisResult = Cv.AutoCannyTextureAnalysis(rawImage, threshold1, threshold2, 0);
            float center = textureAnalysisResult.Center;
            float diff   = textureAnalysisResult.Diff;

            // if center is close to 0.5, it means the car direction is nearly towards the path.
            float threadhold = 0.02f;

            if (Math.Abs(diff) > threadhold)
            {
                if (diff > threadhold)
                {
                    if (_previousDiff < -threadhold)
                    {
                        Arduino.GetInstance().Send(MotorDirection.Forward, 35, MotorDirection.Backward, 35, 200);
                    }
                    else
                    {
                        Arduino.GetInstance().Send(MotorDirection.Forward, 75, MotorDirection.Backward, 75, 200);
                    }
                }
                else if (diff < -threadhold)
                {
                    if (_previousDiff > threadhold)
                    {
                        Arduino.GetInstance().Send(MotorDirection.Backward, 35, MotorDirection.Forward, 35, 200);
                    }
                    else
                    {
                        Arduino.GetInstance().Send(MotorDirection.Backward, 75, MotorDirection.Forward, 75, 200);
                    }
                }
            }
            else
            {
                Arduino.GetInstance().Send(MotorDirection.Forward, 75, MotorDirection.Forward, 75, 200);
            }
            _previousDiff = diff;
        }