コード例 #1
0
        private void w()
        {
            szachownica = new Chessboard();

            while (true)
            {
                try
                {
                    Mat matImage            = Chessboard.kamera.QueryFrame();
                    Image <Bgr, byte> obraz = matImage.ToImage <Bgr, byte>();

                    bool showChecked = false;
                    showLinesCheckBox.Dispatcher.Invoke(() => {
                        if ((bool)showLinesCheckBox.IsChecked)
                        {
                            showChecked = true;
                        }
                    });

                    bool calibrated = szachownica.Calibration(obraz, showChecked);

                    if (calibrated)
                    {
                        bool exist = false;

                        List <string> P1moves = szachownica.FindMoves(1);

                        P1movesList.Dispatcher.Invoke(() => {
                            List <string> old = P1movesList.Items.Cast <string>().ToList();

                            if (!P1moves.SequenceEqual(old))
                            {
                                P1movesList.Items.Clear();
                                foreach (string move in P1moves)
                                {
                                    P1movesList.Items.Add(move);
                                }
                            }
                            if (_move != null && P1movesList.Items.Contains(_move))
                            {
                                exist = true;
                            }
                        });

                        List <string> P2moves = szachownica.FindMoves(2);

                        P2movesList.Dispatcher.Invoke(() => {
                            List <string> old = P2movesList.Items.Cast <string>().ToList();

                            if (!P2moves.SequenceEqual(old))
                            {
                                P2movesList.Items.Clear();
                                foreach (string move in P2moves)
                                {
                                    P2movesList.Items.Add(move);
                                }
                            }
                            if (_move != null && P2movesList.Items.Contains(_move))
                            {
                                exist = true;
                            }
                        });

                        if (exist)
                        {
                            showMove(ref obraz, _move);
                        }
                    }
                    else
                    {
                        P1movesList.Dispatcher.Invoke(() => { P1movesList.Items.Clear(); });
                        P2movesList.Dispatcher.Invoke(() => { P2movesList.Items.Clear(); });
                    }

                    view.Dispatcher.Invoke(() => { view.Source = Tools.ImageToBitmapSource(obraz); });
                }
                catch (Exception /*ex*/) { /*System.Windows.MessageBox.Show(ex.Message);*/ }
            }
        }