コード例 #1
0
        void timer_Tick(object sender, EventArgs e)
        {
            Image <Bgr, byte> currentFrame = null;

            if (capture != null)
            {
                currentFrame = capture.QueryFrame().ToImage <Bgr, byte>();
            }
            else if (capture == null)
            {
                currentFrame = loadedImage.ToImage <Bgr, byte>();
            }
            if (currentScreen != null)
            {
                Mat frame = currentFrame.Mat;
                frame = ImageProcessor.WarpPerspective(frame, Utils.GetPoints(currentScreen.coordinates));

                SetImageAndCanvasSize(frame.Height, frame.Width);
                currentFrame = frame.ToImage <Bgr, byte>();
            }

            if (currentFrame != null)
            {
                image1.Source = Utils.ToBitmapSource(currentFrame);
            }
        }
コード例 #2
0
        private void BtnRunTests_Click(object sender, RoutedEventArgs e)
        {
            bool success = true;

            if (currentScreen != null)
            {
                List <Dial> dials = currentScreen.dials;

                if (dials.Count != 0)
                {
                    tree.Items.Clear();
                    foreach (Dial dial in dials)
                    {
                        Mat    image       = ImageProcessor.WarpPerspective(selectedScreen, Utils.GetPoints(dial.coordinates));
                        Mat    binaryImage = ImageProcessor.PreprocessImageForTesseract(image);
                        String tessResult  = Utils.GetTesseractResult(binaryImage.Bitmap);
                        if (tessResult == "")
                        {
                            tessResult = "Tesseract couldn't get any result";
                        }

                        if (tessResult.TrimEnd('\r', '\n') == dial.ExpectedValue)
                        {
                            UpdateTreeViewItem(dial, "Run Value: " + tessResult.TrimEnd('\r', '\n'), "The values are the same");
                        }
                        else
                        {
                            success = false;
                            UpdateTreeViewItem(dial, "Run Value: " + tessResult.TrimEnd('\r', '\n'), "The values are not the same");
                        }
                    }

                    if (success == true)
                    {
                        System.Windows.Forms.MessageBox.Show("The run was a success", "Run test", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show("One or more runs have failed", "Run test", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    System.Windows.MessageBox.Show("This screen has no dial defined", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            else
            {
                System.Windows.MessageBox.Show("You have to define or load a screen", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
コード例 #3
0
        private void btnLoad_Click(object sender, RoutedEventArgs e)
        {
            ResetAll();
            OpenFileDialog openDialog = new OpenFileDialog();

            openDialog.Title  = "Load the Display Definition";
            openDialog.Filter = "Json|*.json";
            openDialog.ShowDialog();


            if (openDialog.FileName != "")
            {
                System.IO.FileStream       fs = (System.IO.FileStream)openDialog.OpenFile();
                DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(Screen));
                currentScreen  = (Screen)js.ReadObject(fs);
                selectedScreen = ImageProcessor.WarpPerspective(GetCurrentImage().Mat, Utils.GetPoints(currentScreen.coordinates));
                string path = openDialog.FileName.Split('.')[0];
                currentScreen.LoadTemplate();

                currentScreen.dials.ForEach(dial => { AddTreeView(dial); });
            }
        }
コード例 #4
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;
                    }
                }
            }
        }