コード例 #1
0
        private void MainCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (add_markers == true && currentScreen == null)
            {
                if (num_of_clicks < 4)
                {
                    System.Windows.Shapes.Ellipse ellipse = new System.Windows.Shapes.Ellipse();
                    AddEllipse(ellipse);
                    Point point = new Point(Mouse.GetPosition(image1).X, Mouse.GetPosition(image1).Y);
                    Canvas.SetLeft(ellipse, point.X);
                    Canvas.SetTop(ellipse, point.Y);
                    markers.Add(point);
                    num_of_clicks++;
                }

                if (num_of_clicks == 4)
                {
                    currentScreen             = new Screen("selectedScreen");
                    currentScreen.coordinates = markers;
                    Image <Bgr, byte> currentFrame = GetCurrentImage();
                    Mat img  = currentFrame.Mat;
                    Mat warp = ImageProcessor.WarpPerspective(img, Utils.GetPoints(currentScreen.coordinates));
                    selectedScreen = warp;
                    btnAddDialMarkers.IsEnabled = true;
                    btn_AddMarkers.IsEnabled    = false;
                    add_markers = false;
                    ResetMarkers();
                    num_of_clicks = 0;
                }
            }
            else if (add_markers)
            {
                if (num_of_clicks < 4)
                {
                    System.Windows.Shapes.Ellipse ellipse = new System.Windows.Shapes.Ellipse();
                    AddEllipse(ellipse);
                    Point point = new Point(Mouse.GetPosition(image1).X, Mouse.GetPosition(image1).Y);
                    Canvas.SetLeft(ellipse, point.X);
                    Canvas.SetTop(ellipse, point.Y);
                    markers.Add(point);
                    num_of_clicks++;
                }
                if (num_of_clicks == 4)
                {
                    TreeViewItem treeItemTest = new TreeViewItem();

                    /*Image<Bgr, byte> currentFrame = GetCurrentImage();
                     * Mat img = currentFrame.Mat;*/
                    Mat warp = ImageProcessor.WarpPerspective(selectedScreen, Utils.GetPoints(markers));

                    try { dialDefinition = new DialDefinition(warp); dialDefinition.Owner = GetWindow(this); dialDefinition.ShowDialog(); }
                    catch (Exception ex)
                    {
                        System.Windows.MessageBox.Show("A handled exception just occurred: " + ex.Message, "Exception Sample", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }

                    //Checks the value transmited from the dial definition window that the values are not null
                    if (dialDefinition.CadranName.Text != "" && dialDefinition.CadranType.Text != "")
                    {
                        ResetMarkers();
                        Dial dial = new Dial(dialDefinition.CadranName.Text, dialDefinition.CadranType.Text, dialDefinition.ExpectedValue.Text, markers);
                        currentScreen.dials.Add(dial);
                        num_of_clicks = 0;
                        markers.Clear();
                        //Add elements in the treeview
                        AddTreeView(dial);
                    }
                    else
                    {
                        ResetMarkers();
                        markers.Clear();
                        num_of_clicks = 0;
                    }
                }
            }
        }