Beispiel #1
0
        /// <summary>
        /// The o k_ click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void OK_Click(object sender, RoutedEventArgs e)
        {
            double result;
            string addOn = string.Empty;

            if (double.TryParse(this.txbLength.Text, out result))
            {
                if (this.rdbKM.IsChecked.GetValueOrDefault(false))
                {
                    Viana.Project.CalibrationData.RulerUnit = LengthUnit.km;
                }
                else if (this.rdbM.IsChecked.GetValueOrDefault(false))
                {
                    Viana.Project.CalibrationData.RulerUnit = LengthUnit.m;
                }
                else if (this.rdbCM.IsChecked.GetValueOrDefault(false))
                {
                    Viana.Project.CalibrationData.RulerUnit = LengthUnit.cm;
                }
                else if (this.rdbMM.IsChecked.GetValueOrDefault(false))
                {
                    Viana.Project.CalibrationData.RulerUnit = LengthUnit.mm;
                }

                // This line is necessary to get an update event for the ruler value
                // even if only the ruler unit was changed
                Viana.Project.CalibrationData.RulerValueInRulerUnits = -1;
                Viana.Project.CalibrationData.RulerValueInRulerUnits = result;

                this.DialogResult = true;
                this.Close();
            }
            else
            {
                var dlg = new VianaDialog(
                    Labels.CalibrationErrorTitle,
                    Labels.CalibrationErrorDescription,
                    Labels.CalibrationErrorMessage,
                    true);

                dlg.ShowDialog();
            }
        }
        /// <summary>
        /// The container_ mouse left button up.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// </exception>
        protected void Container_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (this.ControlPanel.IsMouseOver)
            {
                return;
            }

            try
            {
                double scaledX   = e.GetPosition(this.VideoImage).X;
                double scaledY   = e.GetPosition(this.VideoImage).Y;
                double factorX   = this.VideoImage.Source.Width / this.VideoImage.ActualWidth;
                double factorY   = this.VideoImage.Source.Height / this.VideoImage.ActualHeight;
                double originalX = factorX * scaledX;
                double originalY = factorY * scaledY;
                var    rect      = new Int32Rect((int)originalX, (int)originalY, 1, 1);

                Bitmap frame = Video.Instance.CreateBitmapFromCurrentImageSource();
                if (frame == null)
                {
                    throw new ArgumentNullException("Native Bitmap is null.");
                }

                Color color = frame.GetPixel((int)originalX, (int)originalY);
                System.Windows.Media.Color selectedColor = System.Windows.Media.Color.FromArgb(255, color.R, color.G, color.B);
                Viana.Project.ProcessingData.TargetColor[this.IndexOfTrackedObject - 1] = selectedColor;
                //Project.TrackObjectColors[this.IndexOfTrackedObject - 1] = new SolidColorBrush(selectedColor);
            }
            catch (Exception)
            {
                var error = new VianaDialog("Error", "No Color selected", "Could not detect the color at the given position", true);
                error.ShowDialog();
            }

            if (this.IndexOfTrackedObject == Viana.Project.ProcessingData.NumberOfTrackedObjects)
            {
                this.DialogResult = true;
                this.Close();
            }

            this.IndexOfTrackedObject++;
            this.ObjectIndexLabel.Content = this.IndexOfTrackedObject.ToString();
        }
Beispiel #3
0
        /// <summary>
        /// This method writes the MethodName and Excpetion message into the ErrorLog.txt file.
        /// </summary>
        /// <param name="ex">
        /// The <see cref="Exception"/> to log.
        /// </param>
        /// <param name="showMessageBox">
        /// True, if this exception should also be displayed in a message box.
        /// </param>
        public static void ProcessException(Exception ex, bool showMessageBox)
        {
            string message = string.Empty;

            message = ex.Message;
            Exception innerException = ex;

            WriteLine("------------------------------------");

            // Loop inner exceptions.
            while (innerException.InnerException != null)
            {
                innerException = innerException.InnerException;
                WriteLine(GetLogEntryForException(innerException));
            }

            message = GetLogEntryForException(innerException);
            WriteLine(message);
            {
                // if (showMessageBox)
                var dlg = new VianaDialog("Exception occured", ex.Message, message, true);
                dlg.ShowDialog();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Handles the MouseLeftButtonDown event of the Container control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="MouseButtonEventArgs" /> instance containing the event data.</param>
        protected override void ContainerMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            base.ContainerMouseLeftButtonDown(sender, e);
            if (this.ignoreMouse)
            {
                return;
            }

            var scaledX   = e.GetPosition(this.VideoImage).X;
            var scaledY   = e.GetPosition(this.VideoImage).Y;
            var factorX   = this.VideoImage.Source.Width / this.VideoImage.ActualWidth;
            var factorY   = this.VideoImage.Source.Height / this.VideoImage.ActualHeight;
            var originalX = factorX * scaledX;
            var originalY = factorY * scaledY;

            if (!this.originIsSet)
            {
                Viana.Project.CalibrationData.OriginInPixel = new Point(originalX, originalY);
                this.originIsSet           = true;
                this.originPath.Visibility = Visibility.Visible;
                Canvas.SetLeft(this.originPath, scaledX - this.originPath.ActualWidth / 2);
                Canvas.SetTop(this.originPath, scaledY - this.originPath.ActualHeight / 2);

                this.DescriptionTitle.Content = Labels.CalibrateWindowSpecifyLengthHeader;
                this.DescriptionMessage.Text  = Labels.CalibrateWindowSpecifyLengthDescription;
            }
            else if (!this.startPointIsSet)
            {
                this.startPoint       = new Point(originalX, originalY);
                this.ruler.X1         = scaledX;
                this.ruler.Y1         = scaledY;
                this.ruler.X2         = scaledX;
                this.ruler.Y2         = scaledY;
                this.ruler.Visibility = Visibility.Visible;
                this.startPointIsSet  = true;
            }
            else if (this.startPointIsSet)
            {
                this.endPoint = new Point(originalX, originalY);

                // Sicher gehen, dass Messpunkt nicht zu dicht liegen
                var distance = Math.Sqrt(Math.Pow(this.endPoint.Y - this.startPoint.Y, 2) + Math.Pow(this.endPoint.X - this.startPoint.X, 2));
                if (distance < 5)
                {
                    var info = new VianaDialog(
                        Labels.CalibrationLengthToShortTitle,
                        Labels.CalibrationLengthToShortDescription,
                        Labels.CalibrationLengthToShortMessage,
                        true);
                    info.ShowDialog();
                    this.startPointIsSet  = false;
                    this.ruler.Visibility = Visibility.Hidden;
                    return;
                }

                var lengthDialog = new LengthDialog();

                if (lengthDialog.ShowDialog().GetValueOrDefault(false))
                {
                    // Save ruler points to Settings
                    Viana.Project.CalibrationData.RulerEndPointInPixel   = this.endPoint;
                    Viana.Project.CalibrationData.RulerStartPointInPixel = this.startPoint;

                    var lengthVector = new Vector();
                    lengthVector = Vector.Add(
                        lengthVector,
                        new Vector(Viana.Project.CalibrationData.RulerStartPointInPixel.X, Viana.Project.CalibrationData.RulerStartPointInPixel.Y));
                    lengthVector.Negate();
                    lengthVector = Vector.Add(
                        lengthVector,
                        new Vector(Viana.Project.CalibrationData.RulerEndPointInPixel.X, Viana.Project.CalibrationData.RulerEndPointInPixel.Y));
                    var length = lengthVector.Length;
                    Viana.Project.CalibrationData.ScalePixelToUnit  = Viana.Project.CalibrationData.RulerValueInRulerUnits / length;
                    Viana.Project.CalibrationData.IsVideoCalibrated = true;
                    this.DialogResult = true;
                }

                this.Close();
            }
        }
Beispiel #5
0
        // this.openFileDialog1.Filter = @"Video Files (*.avi; *.qt; *.mov; *.mpg; *.mpeg; *.m1v)|*.avi; *.qt; *.mov; *.mpg; *.mpeg; *.m1v|Audio files (*.wav; *.mpa; *.mp2; *.mp3; *.au; *.aif; *.aiff; *.snd)|*.wav; *.mpa; *.mp2; *.mp3; *.au; *.aif; *.aiff; *.snd|MIDI Files (*.mid, *.midi, *.rmi)|*.mid; *.midi; *.rmi|Image Files (*.jpg, *.bmp, *.gif, *.tga)|*.jpg; *.bmp; *.gif; *.tga|All Files (*.*)|*.*";

        /// <summary>
        /// The load movie.
        /// </summary>
        /// <param name="fileName">
        /// The file name.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/> .
        /// </returns>
        public bool LoadMovie(string fileName)
        {
            this.ReleaseEventThread();

            try
            {
                if (!File.Exists(fileName))
                {
                    if (fileName != string.Empty)
                    {
                        var messageTitle = Labels.AskVideoNotFoundMessageTitle;
                        messageTitle = messageTitle.Replace("%1", Path.GetFileName(fileName));
                        messageTitle = messageTitle.Replace("%2", Path.GetDirectoryName(fileName));

                        var dlg = new VianaDialog(Labels.AskVideoNotFoundTitle, messageTitle, Labels.AskVideoNotFoundMessage, false);
                        if (!dlg.ShowDialog().GetValueOrDefault(false))
                        {
                            return(false);
                        }
                    }

                    var ofd = new OpenFileDialog();
                    ofd.CheckFileExists = true;
                    ofd.CheckPathExists = true;
                    ofd.FilterIndex     = 1;
                    ofd.Filter          = Labels.VideoFilesFilter;
                    ofd.Title           = Labels.LoadVideoFilesTitle;
                    if (ofd.ShowDialog().Value)
                    {
                        fileName = ofd.FileName;
                    }
                    else
                    {
                        return(false);
                    }
                }

                this.VideoFilename = fileName;

                // Reset status variables
                this.CurrentState = PlayState.Stopped;

                // Read out video properties
                var aviFile = new MediaFile(this.VideoFilename);
                this.FrameTimeInNanoSeconds             = (long)(10000000d / aviFile.Video[0].FrameRate) + 1;
                this.MediaDurationInMS                  = aviFile.General.DurationMillis;
                this.FrameCount                         = aviFile.FrameCount;
                Viana.Project.VideoData.FramerateFactor = 1;
                try
                {
                    this.BuildGraph();
                }
                catch (ArgumentOutOfRangeException)
                {
                    // Found no directshow codec to decode
                    return(false);
                }

                Viana.Project.VideoFile = this.VideoFilename;
                Video.Instance.HasVideo = true;
                Viana.Project.ProcessingData.InitializeImageFilters();
                this.Revert();
                this.OnVideoAvailable();
            }
            catch (Exception ex)
            {
                ErrorLogger.ProcessException(ex, false);
                this.Dispose();
            }

            return(true);
        }