Beispiel #1
0
        /// <summary>
        /// Po nacteni hlavniho okna se inicializuje hlavni manazer, ktery se postara
        /// o zbytek inicializace; take se inicializuje manazer kamery
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // pokud loading timer uz nebezi, zrus loading okno
            if (!loadingTimer.Enabled)
            {
                loadingWindow.Close();
            }

            // nacteni veskereho nastaveni z XML souboru
            CalibrationSettings.Instance().Load();
            CaptureSettings.Instance().Load();
            GraphicsSettings.Instance().Load();
            PhysicSettings.Instance().Load();


            CommonAttribService.mainWindow = this;

            // vytvoreni manazeru, ktery propoji funkcionalitu VSEM hlavnim modelum
            myManager          = new WindowManager();
            myManager.MyWindow = this;
            myManager.LoadDefaultValues();
            myManager.ManageMainWindow();

            CameraManager.Reinitialize();
        }
        public CaptureSettings GetSettings()
        {
            CaptureSettings settings = CaptureSettings.Instance();

            settings.Mode = (Mode.INSTRUMENTATION_CATEGORIES | Mode.INSTRUMENTATION_EVENTS);

            foreach (Flag flag in FlagSettings)
            {
                if (flag.IsEnabled)
                {
                    settings.Mode = settings.Mode | flag.Mask;
                }
            }

            settings.SamplingFrequencyHz = (uint)SamplingFrequencyHz;

            settings.CpuGranularityLv = (uint)CpuGranularityLv;
            settings.GpuGranularityLv = (uint)GpuGranularityLv;

            settings.FrameLimit       = (uint)FrameCountLimit.Value;
            settings.TimeLimitUs      = (uint)(TimeLimitSec.Value * 1000000);
            settings.MaxSpikeLimitUs  = (uint)(MaxSpikeLimitMs.Value * 1000);
            settings.MinFilterLimitUs = (uint)(MinFilterLimitMs.Value);
            settings.MaxFilterLimitUs = (uint)(MaxFilterLimitMs.Value);

            settings.MemoryLimitMb = 0;

            return(settings);
        }
Beispiel #3
0
 /// <summary>
 /// Reset of al settings
 /// </summary>
 private void resetBut_Click(object sender, RoutedEventArgs e)
 {
     CalibrationSettings.Instance().Restart();
     CaptureSettings.Instance().Restart();
     GraphicsSettings.Instance().Restart();
     PhysicSettings.Instance().Restart();
 }
Beispiel #4
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     CalibrationSettings.Instance().Save();
     CaptureSettings.Instance().Save();
     GraphicsSettings.Instance().Save();
     PhysicSettings.Instance().Save();
 }
Beispiel #5
0
        /// <summary>
        /// Loads gradient colors
        /// </summary>
        private void LoadFadeColors()
        {
            // fade color path
            if (CaptureSettings.Instance().DEFAULT_FADECOLOR_PATH == "")
            {
                CaptureSettings.Instance().DEFAULT_FADECOLOR_PATH = "colors.xml";
            }

            string fadeName = CaptureSettings.Instance().DEFAULT_FADECOLOR_PATH;

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(HashSet <FadeColor>), new Type[] { typeof(FadeColor) });
                StreamReader  reader     = new StreamReader(fadeName);

                // we need to order the colors as they are not serialized in order
                LinkedList <FadeColor> output = new LinkedList <FadeColor>();
                HashSet <FadeColor>    temp   = (HashSet <FadeColor>)serializer.Deserialize(reader);
                foreach (FadeColor fade in temp.OrderBy(fadec => fadec.position))
                {
                    output.AddLast(fade);
                }
                CommonAttribService.DEFAULT_FADE_COLORS = output;
                reader.Close();
            }
            catch
            {
                System.Windows.MessageBox.Show("An error ocurred during loading of color gradients");
            }
        }
Beispiel #6
0
 private void LoadTemplates()
 {
     if (CaptureSettings.Instance().DEFAULT_TEMPLATE_PATH == "")
     {
         System.Windows.MessageBox.Show("No template path configured!");
     }
     else
     {
         string fileName = CaptureSettings.Instance().DEFAULT_TEMPLATE_PATH;
         try
         {
             if (!File.Exists(fileName))
             {
                 System.Windows.MessageBox.Show("There is no file with templates for stones! Create one in contour settings!");
             }
             else
             {
                 using (FileStream fs = new FileStream(fileName, FileMode.Open))
                     CommonAttribService.DEFAULT_TEMPLATES = (Templates) new BinaryFormatter().Deserialize(fs);
             }
         }
         catch
         {
             System.Windows.MessageBox.Show("An error ocurred during template initialization");
         }
     }
 }
Beispiel #7
0
 /// <summary>
 /// Click on RESET - resets all settings
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void resetButton_Click(object sender, System.Windows.RoutedEventArgs e)
 {
     settingsLock = true;
     CaptureSettings.Instance().Restart();
     SetDefaultValues();
     settingsLock = false;
 }
Beispiel #8
0
        /// <summary>
        /// Click on openIcon will open a template from a file
        /// </summary>
        private void openTemplateImage_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Templates(*.bin)|*.bin";
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string fileName = ofd.FileName;
                CaptureSettings.Instance().DEFAULT_TEMPLATE_PATH = fileName;

                try
                {
                    using (FileStream fs = new FileStream(fileName, FileMode.Open))
                    {
                        // WARNING: here a default path and also a default template will change, if we open a new template
                        Templates tmp = (Templates) new BinaryFormatter().Deserialize(fs);
                        CommonAttribService.DEFAULT_TEMPLATES = tmp;
                        captureWindow.Processor.templates     = tmp;
                    }
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show(ex.Message);
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// Load all values from storage
        /// </summary>
        public void LoadValues()
        {
            contourPathTbx.Text            = CaptureSettings.Instance().DEFAULT_TEMPLATE_PATH;
            camIndexCombo.SelectedIndex    = CaptureSettings.Instance().DEFAULT_CAMERA_INDEX;
            dependOutputSizeChck.IsChecked = GraphicsSettings.Instance().OUTPUT_TABLE_SIZE_DEPENDENT;
            contourPathTbx.IsEnabled       = GraphicsSettings.Instance().OUTPUT_TABLE_SIZE_DEPENDENT;
            dependOutputSizeTbx.Text       = CommonAttribService.ACTUAL_OUTPUT_WIDTH.ToString();

            partColorRedTbx.Text          = GraphicsSettings.Instance().DEFAULT_PARTICLE_COLOR_R.ToString();
            partColorGreenTbx.Text        = GraphicsSettings.Instance().DEFAULT_PARTICLE_COLOR_G.ToString();
            partColorBlueTbx.Text         = GraphicsSettings.Instance().DEFAULT_PARTICLE_COLOR_B.ToString();
            motionDetectionChck.IsChecked = CaptureSettings.Instance().MOTION_DETECTION;
            detectionThreshold.Text       = CaptureSettings.Instance().MOTION_TOLERANCE.ToString();
        }
Beispiel #10
0
        /// <summary>
        /// Executes processing thread
        /// </summary>
        public bool RunThread()
        {
            if (processor == null)
            {
                LoadProcessor();
            }

            if (CommonAttribService.DEFAULT_TEMPLATES == null)
            {
                MessageBox.Show("There are no templates configured. To work with AR, set templates first!");
                return(false);
            }
            if (CommonAttribService.DEFAULT_TEMPLATES.rockSettings.Count == 0)
            {
                MessageBox.Show("Templates don't have any stones assigned. Assign some in Contour settings.");
                return(false);
            }
            else
            {
                try
                {
                    processor.finder.maxRotateAngle            = CaptureSettings.Instance().DEFAULT_ROTATE_ANGLE *Math.PI / 180;
                    processor.minContourArea                   = CaptureSettings.Instance().DEFAULT_CONTOUR_MIN_AREA;
                    processor.minContourLength                 = CaptureSettings.Instance().DEFAULT_CONTOUR_MIN_LENGTH;
                    processor.finder.maxACFDescriptorDeviation = CaptureSettings.Instance().DEFAULT_MAX_ACF;
                    processor.finder.minACF              = CaptureSettings.Instance().DEFAULT_MIN_ACF;
                    processor.finder.minICF              = CaptureSettings.Instance().DEFAULT_MIN_ICF;
                    processor.noiseFilter                = CaptureSettings.Instance().DEFAULT_NOISE_ENABLED;
                    processor.cannyThreshold             = CaptureSettings.Instance().DEFAULT_NOISE_FILTER;
                    processor.adaptiveThresholdBlockSize = CaptureSettings.Instance().DEFAULT_ADAPTIVE_THRESHOLD_BLOCKSIZE;
                    processor.adaptiveThresholdParameter = CaptureSettings.Instance().DEFAULT_ADAPTIVE_THRESHOLD_PARAMETER;
                    processor.blur = CaptureSettings.Instance().DEFAULT_BLUR_ENABLED;
                }
                catch (Exception e)
                {
                    MessageBox.Show("An error occurred during camera initialization: " + e.Message + ";;;" + e.StackTrace);
                    return(false);
                }
                realTableManager.Init(CommonAttribService.DEFAULT_TEMPLATES);

                workThread = new Thread(Application_Idle);
                workThread.IsBackground = true;
                workThread.Start();
                return(true);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Processing loop, captures an image and processes it
        /// </summary>
        private void Application_Idle()
        {
            while (true)
            {
                try
                {
                    Image <Bgr, byte> tempFrame = captured_frame = CameraManager.GetImage();
                    if (CaptureSettings.Instance().DEFAULT_DILATATION != 0)
                    {
                        tempFrame._Dilate((int)CaptureSettings.Instance().DEFAULT_DILATATION);
                    }
                    if (CaptureSettings.Instance().DEFAULT_ERODE != 0)
                    {
                        tempFrame._Erode((int)CaptureSettings.Instance().DEFAULT_ERODE);
                    }
                    if (CaptureSettings.Instance().DEFAULT_GAMMA != 1)
                    {
                        tempFrame._GammaCorrect((double)CaptureSettings.Instance().DEFAULT_GAMMA);
                    }
                    if (CaptureSettings.Instance().DEFAULT_INVERT_ENABLED)
                    {
                        tempFrame._Not();
                    }
                    if (CaptureSettings.Instance().DEFAULT_NORMALIZE_ENABLED)
                    {
                        tempFrame._EqualizeHist();
                    }

                    // fix rotation
                    if (CalibrationSettings.Instance().CALIBRATION_ROTATION != 0)
                    {
                        tempFrame = tempFrame.Rotate(CalibrationSettings.Instance().CALIBRATION_ROTATION, new Bgr(0, 0, 0), true);
                    }

                    processor.ProcessImage(tempFrame);
                    if (interactiveWindow != null && interactiveWindow.IsVisible)
                    {
                        interactiveWindow.DrawImage(tempFrame, processor);
                    }
                    InputLogic();
                }
                catch {
                    // no-op here
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// Gets a copy of last captured image
        /// </summary>
        /// <returns></returns>
        public static Image <Bgr, byte> GetImage()
        {
            if (ACTUAL_CAMERA_INDEX != CaptureSettings.Instance().DEFAULT_CAMERA_INDEX)
            {
                Reinitialize();
            }
            if (lastFrame == null || (DateTime.Now - lastFrameTime).TotalMilliseconds > 25)
            {
                CaptureFrame();
            }
            // just for sure...to avoid errors
            if (lastFrame == null)
            {
                lastFrame = new Image <Bgr, byte>(50, 50);
            }

            return(lastFrame.Clone());
        }
Beispiel #13
0
        /// <summary>
        /// Calculates a difference descriptor between two images in order to detect motion
        /// </summary>
        private static void CalculateDiff(Image <Bgr, byte> originalFrame, Image <Bgr, byte> lastFrame)
        {
            Image <Gray, Byte> frameG     = originalFrame.Convert <Gray, Byte>();
            Image <Gray, Byte> lastFrameG = lastFrame.Convert <Gray, Byte>();

            // Perform thresholding to remove noise and boost "new introductions"
            Image <Gray, Byte> threshOrig = new Image <Gray, byte>(originalFrame.Width, originalFrame.Height);

            CvInvoke.cvThreshold(frameG, threshOrig, 20, 255, THRESH.CV_THRESH_BINARY);

            Image <Gray, Byte> threshLast = new Image <Gray, byte>(lastFrame.Width, lastFrame.Height);

            CvInvoke.cvThreshold(lastFrameG, threshLast, 20, 255, THRESH.CV_THRESH_BINARY);

            // Perform erosion to remove camera noise
            Image <Gray, Byte> erodedOrig = new Image <Gray, byte>(originalFrame.Width, originalFrame.Height);

            CvInvoke.cvErode(threshOrig, erodedOrig, IntPtr.Zero, 2);

            Image <Gray, Byte> erodedLast = new Image <Gray, byte>(lastFrame.Width, lastFrame.Height);

            CvInvoke.cvErode(threshLast, erodedLast, IntPtr.Zero, 2);

            double l2_norm = (erodedOrig - erodedLast).Norm;

            lastDiff   = actualDiff;
            actualDiff = l2_norm;

            if (l2_norm < 2000 || Math.Abs(actualDiff - lastDiff) > CaptureSettings.Instance().MOTION_TOLERANCE)
            {
                isInPeace = false;
                unpeaceCounter++;
                peaceCounter = -1;
            }
            else
            {
                isInPeace      = true;
                unpeaceCounter = -1;
                peaceCounter++;
            }
        }
Beispiel #14
0
        /// <summary>
        /// Saves all values and re-renders everything
        /// </summary>
        public void ApplySettings()
        {
            try
            {
                captureWindow.angleLabel.Content            = captureWindow.angleSlider.Value.ToString("n0");
                captureWindow.blockLevelLabel.Content       = captureWindow.blockLevelSlider.Value.ToString("n0");
                captureWindow.contourMinAreaLabel.Content   = captureWindow.contourMinAreaSlider.Value.ToString("n0");
                captureWindow.contourMinLengthLabel.Content = captureWindow.contourMinLengthSlider.Value.ToString("n0");
                captureWindow.dilatationLabel.Content       = captureWindow.dilatationSlider.Value.ToString("n0");
                captureWindow.erodeLabel.Content            = captureWindow.erodeSlider.Value.ToString("n0");
                captureWindow.gammaLabel.Content            = captureWindow.gammaSlider.Value.ToString("n2");
                captureWindow.maxACFAverLabel.Content       = captureWindow.maxACFAverSlider.Value.ToString("n0");
                captureWindow.minACFLabel.Content           = captureWindow.minACFSlider.Value.ToString("n2");
                captureWindow.minICFLabel.Content           = captureWindow.minICFSlider.Value.ToString("n2");
                captureWindow.noiseLabel.Content            = captureWindow.noiseSlider.Value.ToString("n0");

                CaptureSettings.Instance().DEFAULT_DILATATION        = captureWindow.dilatationSlider.Value;
                CaptureSettings.Instance().DEFAULT_ERODE             = captureWindow.erodeSlider.Value;
                CaptureSettings.Instance().DEFAULT_GAMMA             = captureWindow.gammaSlider.Value;
                CaptureSettings.Instance().DEFAULT_INVERT_ENABLED    = (bool)captureWindow.invertCheck.IsChecked;
                CaptureSettings.Instance().DEFAULT_NORMALIZE_ENABLED = (bool)captureWindow.normalizeCheck.IsChecked;

                captureWindow.ShowAngle = (bool)captureWindow.showAngleCheck.IsChecked;
                CaptureSettings.Instance().DEFAULT_ROTATE_ANGLE = captureWindow.angleSlider.Value;
                captureWindow.Processor.finder.maxRotateAngle            = CaptureSettings.Instance().DEFAULT_ROTATE_ANGLE *Math.PI / 180;
                captureWindow.Processor.minContourArea                   = CaptureSettings.Instance().DEFAULT_CONTOUR_MIN_AREA = (int)captureWindow.contourMinAreaSlider.Value;
                captureWindow.Processor.minContourLength                 = CaptureSettings.Instance().DEFAULT_CONTOUR_MIN_LENGTH = (int)captureWindow.contourMinLengthSlider.Value;
                captureWindow.Processor.finder.maxACFDescriptorDeviation = CaptureSettings.Instance().DEFAULT_MAX_ACF = (int)captureWindow.maxACFAverSlider.Value;
                captureWindow.Processor.finder.minACF              = CaptureSettings.Instance().DEFAULT_MIN_ACF = (double)captureWindow.minACFSlider.Value;
                captureWindow.Processor.finder.minICF              = CaptureSettings.Instance().DEFAULT_MIN_ICF = (double)captureWindow.minICFSlider.Value;
                captureWindow.Processor.noiseFilter                = CaptureSettings.Instance().DEFAULT_NOISE_ENABLED = (bool)(captureWindow.noiseSlider.Value > 0);
                captureWindow.Processor.cannyThreshold             = CaptureSettings.Instance().DEFAULT_NOISE_FILTER = (int)captureWindow.noiseSlider.Value;
                captureWindow.Processor.adaptiveThresholdBlockSize = CaptureSettings.Instance().DEFAULT_ADAPTIVE_THRESHOLD_BLOCKSIZE = (int)captureWindow.blockLevelSlider.Value;
                captureWindow.Processor.adaptiveThresholdParameter = CaptureSettings.Instance().DEFAULT_ADAPTIVE_THRESHOLD_PARAMETER = (bool)captureWindow.adaptiveNoiseCheck.IsChecked ? 1.5 : 0.5;
                captureWindow.Processor.blur = CaptureSettings.Instance().DEFAULT_BLUR_ENABLED = (bool)(captureWindow.blurCheck.IsChecked);
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message);
            }
        }
Beispiel #15
0
 /// <summary>
 /// Captures a frame from camera
 /// </summary>
 private static void CaptureFrame()
 {
     try
     {
         if (CaptureSettings.Instance().MOTION_DETECTION)
         {
             Image <Bgr, byte> originalFrame = lastFrame.Clone();
             lastFrame = camera.QueryFrame();
             CalculateDiff(originalFrame, lastFrame);
         }
         else
         {
             lastFrame = camera.QueryFrame();
         }
         lastFrameTime = DateTime.Now;
     }
     catch
     {
         Console.WriteLine("Unable to capture camera image");
     }
 }
Beispiel #16
0
        private void LoadProcessor()
        {
            processor           = new ContourFilter();
            processor.templates = CommonAttribService.DEFAULT_TEMPLATES;

            // set default values

            processor.finder.maxRotateAngle            = CaptureSettings.Instance().DEFAULT_ROTATE_ANGLE *Math.PI / 180;
            processor.minContourArea                   = CaptureSettings.Instance().DEFAULT_CONTOUR_MIN_AREA;
            processor.minContourLength                 = CaptureSettings.Instance().DEFAULT_CONTOUR_MIN_LENGTH;
            processor.finder.maxACFDescriptorDeviation = CaptureSettings.Instance().DEFAULT_MAX_ACF;
            processor.finder.minACF              = CaptureSettings.Instance().DEFAULT_MIN_ACF;
            processor.finder.minICF              = CaptureSettings.Instance().DEFAULT_MIN_ICF;
            processor.noiseFilter                = CaptureSettings.Instance().DEFAULT_NOISE_ENABLED;
            processor.cannyThreshold             = CaptureSettings.Instance().DEFAULT_NOISE_FILTER;
            processor.adaptiveThresholdBlockSize = CaptureSettings.Instance().DEFAULT_ADAPTIVE_THRESHOLD_BLOCKSIZE;
            processor.adaptiveThresholdParameter = CaptureSettings.Instance().DEFAULT_ADAPTIVE_THRESHOLD_PARAMETER;
            processor.blur = CaptureSettings.Instance().DEFAULT_BLUR_ENABLED;

            realTableManager = new RealTableManager(tableManager.TableDepositor);
            realTableManager.Init(CommonAttribService.DEFAULT_TEMPLATES);
        }
        /// <summary>
        /// Click on OK will save the settings
        /// </summary>
        private void okBut_Click(object sender, RoutedEventArgs e)
        {
            // we need to have at least 2 markers
            if (fadeMarks != null && fadeMarks.Count > 2)
            {
                // we need to order it first
                LinkedList <FadeColor> output = new LinkedList <FadeColor>();
                HashSet <FadeColor>    temp   = new HashSet <FadeColor>();

                foreach (Ellipse el in fadeMarks)
                {
                    temp.Add((FadeColor)el.DataContext);
                }
                foreach (FadeColor fade in temp.OrderBy(fadec => fadec.position))
                {
                    output.AddLast(fade);
                }
                CommonAttribService.DEFAULT_FADE_COLORS = output;

                // we need to use HashSet as LinkedList cannot be serialized
                try
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(HashSet <FadeColor>), new Type[] { typeof(FadeColor) });
                    StreamWriter  writer     = new StreamWriter(CaptureSettings.Instance().DEFAULT_FADECOLOR_PATH);
                    serializer.Serialize(writer, temp);
                    writer.Close();
                }
                catch (Exception es)
                {
                    System.Windows.MessageBox.Show("An error occurred during saving!");
                }
            }

            if (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
            {
                this.Close();
            }
        }
Beispiel #18
0
        public void SetDefaultValues()
        {
            // USER SETTINGS
            captureWindow.angleSlider.Value            = CaptureSettings.Instance().DEFAULT_ROTATE_ANGLE;
            captureWindow.blockLevelSlider.Value       = CaptureSettings.Instance().DEFAULT_BLOCK_LEVEL;
            captureWindow.contourMinAreaSlider.Value   = CaptureSettings.Instance().DEFAULT_CONTOUR_MIN_AREA;
            captureWindow.contourMinLengthSlider.Value = CaptureSettings.Instance().DEFAULT_CONTOUR_MIN_LENGTH;
            captureWindow.dilatationSlider.Value       = CaptureSettings.Instance().DEFAULT_DILATATION;
            captureWindow.erodeSlider.Value            = CaptureSettings.Instance().DEFAULT_ERODE;
            captureWindow.gammaSlider.Value            = CaptureSettings.Instance().DEFAULT_GAMMA;
            captureWindow.maxACFAverSlider.Value       = CaptureSettings.Instance().DEFAULT_MAX_ACF;
            captureWindow.minACFSlider.Value           = CaptureSettings.Instance().DEFAULT_MIN_ACF;
            captureWindow.minICFSlider.Value           = CaptureSettings.Instance().DEFAULT_MIN_ICF;
            captureWindow.adaptiveNoiseCheck.IsChecked = CaptureSettings.Instance().DEFAULT_NOISE_ENABLED;
            captureWindow.noiseSlider.Value            = CaptureSettings.Instance().DEFAULT_NOISE_FILTER;
            captureWindow.blurCheck.IsChecked          = CaptureSettings.Instance().DEFAULT_BLUR_ENABLED;
            captureWindow.adaptiveNoiseCheck.IsChecked = (CaptureSettings.Instance().DEFAULT_ADAPTIVE_THRESHOLD_PARAMETER == 1.5) ? true : false;
            captureWindow.blockLevelSlider.Value       = CaptureSettings.Instance().DEFAULT_ADAPTIVE_THRESHOLD_BLOCKSIZE;
            captureWindow.invertCheck.IsChecked        = CaptureSettings.Instance().DEFAULT_INVERT_ENABLED;
            captureWindow.normalizeCheck.IsChecked     = CaptureSettings.Instance().DEFAULT_NORMALIZE_ENABLED;

            ApplySettings();
        }
Beispiel #19
0
        /// <summary>
        /// Click on OK will save the settings and close the window
        /// </summary>
        private void okButton_Click(object sender, RoutedEventArgs e)
        {
            if (System.Windows.Forms.MessageBox.Show("Do you want to save your changes?", "Settings change", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
                System.Windows.Forms.DialogResult.Yes)
            {
                SaveValues();
                templates.rockSettings = contourRocks;

                // Try use a default path. If something goes wrong, display a file dialog
                try
                {
                    string fileName = CaptureSettings.Instance().DEFAULT_TEMPLATE_PATH;

                    using (FileStream fs = new FileStream(fileName, FileMode.Create))
                        new BinaryFormatter().Serialize(fs, templates);
                }
                catch
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "Templates(*.bin)|*.bin";
                    if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        string fileName = sfd.FileName;
                        try
                        {
                            using (FileStream fs = new FileStream(fileName, FileMode.Create))
                                new BinaryFormatter().Serialize(fs, templates);
                        }
                        catch (Exception ex)
                        {
                            System.Windows.MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
            this.Close();
        }
Beispiel #20
0
        /// <summary>
        /// Click on OK will save all changes
        /// </summary>
        private void okBut_Click(object sender, RoutedEventArgs e)
        {
            CaptureSettings.Instance().DEFAULT_TEMPLATE_PATH        = contourPathTbx.Text;
            CaptureSettings.Instance().DEFAULT_CAMERA_INDEX         = camIndexCombo.SelectedIndex;
            GraphicsSettings.Instance().OUTPUT_TABLE_SIZE_DEPENDENT = (bool)dependOutputSizeChck.IsChecked;
            CaptureSettings.Instance().MOTION_DETECTION             = (bool)motionDetectionChck.IsChecked;

            try
            {
                GraphicsSettings.Instance().DEFAULT_PARTICLE_COLOR_R = Byte.Parse(partColorRedTbx.Text);
                GraphicsSettings.Instance().DEFAULT_PARTICLE_COLOR_G = Byte.Parse(partColorGreenTbx.Text);
                GraphicsSettings.Instance().DEFAULT_PARTICLE_COLOR_B = Byte.Parse(partColorBlueTbx.Text);
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("Wrong values of particle colors (need to be 0-255)");
                return;
            }
            try
            {
                int otp_width = Int32.Parse(dependOutputSizeTbx.Text);
                if (otp_width > 100 && otp_width < 2000)
                {
                    CommonAttribService.ACTUAL_OUTPUT_WIDTH = otp_width;
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Allowed sizes are 100-2000");
                    return;
                }
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("The size cannot be determined!");
                return;
            }

            try
            {
                int tolerance = Int32.Parse(detectionThreshold.Text);
                if (tolerance < 500 || tolerance > 10000)
                {
                    throw new Exception();
                }
                CaptureSettings.Instance().MOTION_TOLERANCE = tolerance;
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("Allowed value for tolerance must be in 500-10000");
                return;
            }

            CaptureSettings.Instance().Save();
            GraphicsSettings.Instance().Save();

            // if the left shift is pressed, we will not close the window (WTF??)
            if (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
            {
                this.Close();
            }
        }
Beispiel #21
0
 /// <summary>
 /// Saves all values into Properties
 /// </summary>
 public void SaveSettings()
 {
     CaptureSettings.Instance().Save();
 }
Beispiel #22
0
 public static void Reinitialize()
 {
     ACTUAL_CAMERA_INDEX = CaptureSettings.Instance().DEFAULT_CAMERA_INDEX;
     camera = new Emgu.CV.Capture(ACTUAL_CAMERA_INDEX);
 }