Exemplo n.º 1
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     CalibrationSettings.Instance().Save();
     CaptureSettings.Instance().Save();
     GraphicsSettings.Instance().Save();
     PhysicSettings.Instance().Save();
 }
Exemplo n.º 2
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();
 }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Loads calibration settings
        /// </summary>
        public void LoadValues()
        {
            calibrationPoints    = new Point[2];
            calibrationPoints[0] = CalibrationSettings.Instance().CALIBRATION_POINT_A;
            calibrationPoints[1] = CalibrationSettings.Instance().CALIBRATION_POINT_C;

            if (calibrationPoints[0].X != calibrationPoints[1].X && calibrationPoints[0].Y != calibrationPoints[1].Y)
            {
                pointCounter = 2;
                rotation     = CalibrationSettings.Instance().CALIBRATION_ROTATION;
                perspective  = CalibrationSettings.Instance().CALIBRATION_PERSPECTIVE;

                if (perspective != 1)
                {
                    perspectiveRadio.IsChecked = true;
                    mode = CalibrationMode.PERSPECTIVE;
                }
                else
                {
                    mode = CalibrationMode.RECTANGLE;
                    rectangleRadio.IsChecked = true;
                }

                DrawPoint((int)calibrationPoints[0].X, (int)calibrationPoints[0].Y, 0);
                DrawPoint((int)calibrationPoints[1].X, (int)calibrationPoints[1].Y, 1);
                CreateLines();
            }
            CaptureImage();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Saves calibration parameters (we need only coordinates of two edges, rotation and the mode)
        /// </summary>
        private void SaveValues()
        {
            CalibrationSettings.Instance().CALIBRATION_POINT_A.X = calibrationPoints[0].X;
            CalibrationSettings.Instance().CALIBRATION_POINT_A.Y = calibrationPoints[0].Y;
            CalibrationSettings.Instance().CALIBRATION_POINT_C.X = calibrationPoints[1].X;
            CalibrationSettings.Instance().CALIBRATION_POINT_C.Y = calibrationPoints[1].Y;
            CalibrationSettings.Instance().CALIBRATION_ROTATION    = rotation;
            CalibrationSettings.Instance().CALIBRATION_PERSPECTIVE = perspective;

            CalibrationSettings.Instance().Save();
        }
Exemplo n.º 6
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
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Takes all detected contours, transforms their positions into the coordinate system of the table,
        /// taking also into accoutn perspective distortion. At last, it creates descriptors of detected
        /// stones and passes everything to the merging processor that will increase the simulation step
        /// </summary>
        private void InputLogic()
        {
            foundRocks.Clear();

            if (tableManager.IsRunning)
            {
                foreach (FoundTemplateDesc found in processor.foundTemplates)
                {
                    System.Drawing.Rectangle foundRect = found.sample.contour.SourceBoundingRect;

                    #region hledani transformovaneho bodu

                    try
                    {
                        double found_pos_x = foundRect.Left + foundRect.Size.Width / 2;
                        double found_pos_y = foundRect.Top + foundRect.Size.Height / 2;

                        double mx = found_pos_x;                                          // X-axis coord in the trapezoid
                        double my = captured_frame.Height - found_pos_y;                  // Y-axis coord in the trapezoid

                        double ax = CalibrationSettings.Instance().CALIBRATION_POINT_A.X; // X-axis coord of A-point in trapezoid

                        // estimation of other points according to ( a = (2*r1r2)/(r1+1))
                        double r1 = CalibrationSettings.Instance().CALIBRATION_PERSPECTIVE;
                        double r2 = CalibrationSettings.Instance().CALIBRATION_POINT_C.X - CalibrationSettings.Instance().CALIBRATION_POINT_A.X;
                        double bx = ax + (2 * (r1 * r2)) / (r1 + 1);                                              // X-axis coord of B-point in trapezoid
                        double cx = CalibrationSettings.Instance().CALIBRATION_POINT_C.X;                         // X-axis coord of C-point in trapezoid
                        double dx = ax + bx - cx;                                                                 // X-axis coord of D-point in trapezoid

                        double cy = captured_frame.Height - CalibrationSettings.Instance().CALIBRATION_POINT_C.Y; // Y-axis coord of C-point in trapezoid
                        double ay = captured_frame.Height - CalibrationSettings.Instance().CALIBRATION_POINT_A.Y; // Y-axis coord of A-point in trapezoid

                        double pom  = (my - ay) / (cy - ay);                                                      // ratio between the bottom base and the upper base
                        double r1m  = mx - (ax + (dx - ax) * pom);                                                // distance of the M point from the left side
                        double r1r2 = pom * (cx - bx - dx + ax) + bx - ax;                                        // length of a line that crosses the M-point and both sides

                        double ab      = Math.Abs(bx - ax);                                                       // length of AB line
                        double cd      = Math.Abs(cx - dx);                                                       // length of CD line
                        double alfa    = r1r2 / ab;                                                               // perspective distortion
                        double maximum = captured_frame.Height / (cd / ab);                                       // max distortion
                        double real    = (captured_frame.Height) * (pom / alfa);                                  // relative distortion to the M-point

                        // projection to a rectangle the frame represents
                        double mxx = (ax < bx) ? captured_frame.Width * (r1m / r1r2) : captured_frame.Width - captured_frame.Width * r1m / r1r2;
                        double mxy = (ay > cy) ? (captured_frame.Height * real / maximum) : captured_frame.Height - (captured_frame.Height * real / maximum);


                        // recalculation from camera space to table space
                        mxx *= CommonAttribService.ACTUAL_TABLE_WIDTH / ((double)captured_frame.Width);
                        mxy *= CommonAttribService.ACTUAL_TABLE_HEIGHT / ((double)captured_frame.Height);
                        foundRocks.Add(CreateFoundRock(found.template.name, new FPoint(mxx - CommonAttribService.ACTUAL_TABLE_WIDTH / 2, CommonAttribService.ACTUAL_TABLE_HEIGHT / 2 - mxy), processor.templates, found.rate, found.scale, found.angle));
                    }
                    catch
                    {
                        MessageBox.Show("An error occurred during calibration. Try to set the calibration again!");
                        StopThread();
                    }
                    #endregion
                }
                // merge both systems between two time steps
                realTableManager.MergeSystems(foundRocks);
            }
        }