Exemplo n.º 1
0
        private void SpeedDownCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            CameraVehicle vehicle = this.vehicle as CameraVehicle;

            vehicle.SetSpeed(vehicle.MidSpeed - 4.05);
            //UpdateInfoTextBlock();
        }
Exemplo n.º 2
0
        private void connectButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                CameraVehicle vehicle = this.vehicle as CameraVehicle;
                vehicle.ConnectToBrick(connectionComboBox.SelectedValue.ToString());
                buttonsGrid.IsEnabled = true;

                //RecordedActions(vehicle);
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                if (ex.InnerException != null)
                {
                    message += "\n" + ex.InnerException.Message;
                    if (ex.InnerException.InnerException != null)
                    {
                        message += "\n......";
                    }
                }
                MessageBox.Show(message);
                buttonsGrid.IsEnabled = false;
            }
        }
Exemplo n.º 3
0
        private void TurnRightCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            //lastSteeringTick = Environment.TickCount;

            CameraVehicle vehicle = this.vehicle as CameraVehicle;

            vehicle.Steer(vehicle.SteeringAngle + 10);

            SteeringAngle = vehicle.SteeringAngle;
            //UpdateInfoTextBlock();
        }
Exemplo n.º 4
0
        private void TurnLeftCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            //vehicle.SteeringMotor.On(20, 10, true);
            CameraVehicle vehicle = this.vehicle as CameraVehicle;

            //lastSteeringTick = Environment.TickCount;

            vehicle.Steer(vehicle.SteeringAngle - 10);

            SteeringAngle = vehicle.SteeringAngle;

            //UpdateInfoTextBlock();
        }
Exemplo n.º 5
0
        private static async void RecordedActions(CameraVehicle vehicle)
        {
            await vehicle.Forward(96);

            await vehicle.ForwardRight(40);

            await vehicle.BackwardLeft(30);

            await vehicle.Backward(15);

            await vehicle.BackwardLeft(20);

            await vehicle.Backward(25);

            await vehicle.BackwardRight(40);

            await vehicle.ForwardLeft(40);

            await vehicle.Backward(4);
        }
Exemplo n.º 6
0
        private void AnalyzeFrame(object sender, DoWorkEventArgs e)
        {
            Image <Bgr, byte> img = ((ImageAvailableEventArgs)e.Argument).Image;

            if (backgroundImage == null)
            {
                backgroundImage = new Image <Gray, byte>(img.Size);
            }

            //long t = Environment.TickCount;
            Image <Gray, byte> b = GetBackground(img);

            Dispatcher.BeginInvoke(new Action(() => CvInvoke.cvShowImage("Background", img.Copy(b))));

            //Debug.WriteLine("GetBackground: " + (Environment.TickCount - t));
            //t = Environment.TickCount;
            //CvInvoke.cvShowImage("Masked", img);

            Contour <PointInt> contours       = b.FindContours();
            Contour <PointInt> biggestContour = contours;

            while (contours != null)
            {
                if (contours.Area > biggestContour.Area)
                {
                    biggestContour = contours;
                }
                contours = contours.HNext;
            }
            //Debug.WriteLine("contours: " + (Environment.TickCount - t));
            //t = Environment.TickCount;

            bool voteFull = false;

            Image <Gray, byte> tempImage = new Image <Gray, byte>(backgroundImage.Size);

            tempImage.Draw(biggestContour, new Gray(10), -1);
            backgroundImage = backgroundImage.Add(tempImage);

            PointInt pUseless = PointInt.Empty;

            voteFull = !backgroundImage.CheckRange(0, 250, ref pUseless);

            if (voteFull)
            {
                collectedBackgroundCount++;
                Dispatcher.Invoke(() =>
                {
                    backgroundImage = backgroundImage - new Gray(130);

                    //w.carRectangle.Width = this.vehicle.State.Width;
                    //w.carRectangle.Height = this.vehicle.State.Length;
                    //w.carRectangle.SetValue(Canvas.LeftProperty, this.vehicle.State.Center.X - this.vehicle.State.Width / 2);
                    //w.carRectangle.SetValue(Canvas.TopProperty, this.vehicle.State.Center.Y + this.vehicle.State.Length / 2);

                    backgroundImage._Dilate(1);
                    //backgroundImage.ROI = new Rectangle(0, backgroundImage.Height - 1, backgroundImage.Width, 1);
                    //backgroundImage._Or(new Image<Gray, byte>(backgroundImage.Width, 1, new Gray(255)));
                    //backgroundImage.ROI = Rectangle.Empty;
                    CvInvoke.cvShowImage("Background-Draw to map",
                                         backgroundImage.ThresholdBinary(new Gray(0), new Gray(255)));
                    AddToMap(backgroundImage.ThresholdBinary(new Gray(0), new Gray(255)), img);

                    MapWindow w = GetMapWindow();
                    w.Draw();

                    CameraVehicle vehicle = this.vehicle as CameraVehicle;

                    //if (vehicle != null)
                    //{
                    //    if (collectedBackgroundCount < 3)
                    //        vehicle.SetSpeed(4.05, 5000);
                    //}

                    getBackgroundCheckBox.IsChecked = false;

                    CvInvoke.cvShowImage("VotedBackground", backgroundImage);
                });
            }
            else
            {
                Dispatcher.BeginInvoke(new Action(() => CvInvoke.cvShowImage("VotedBackground", backgroundImage)));
            }
        }
Exemplo n.º 7
0
        private void BrakeCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            CameraVehicle vehicle = this.vehicle as CameraVehicle;

            vehicle.SetSpeed(0);
        }
Exemplo n.º 8
0
        private void TurnRightCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            CameraVehicle vehicle = this.vehicle as CameraVehicle;

            e.CanExecute = vehicle != null && vehicle.SteeringAngle < vehicle.State.TurnMaxDegree;
        }