private void w() { try { Chessboard szachownica = new Chessboard(new Bgr(4, 0, 115), new Bgr(0, 140, 21), new Bgr(98, 93, 255), new Bgr(113, 254, 110), 10.0, 10.0, 14, 14, 18, 18); Capture kamera = new Capture(1); while (true) { Mat matImage = kamera.QueryFrame(); Image <Bgr, byte> obraz = matImage.ToImage <Bgr, byte>(); szachownica.Calibration(obraz, true, true); List <string> moves = szachownica.FindMoves(1); movesList.Dispatcher.Invoke(() => { movesList.Items.Clear(); }); foreach (string move in moves) { movesList.Dispatcher.Invoke(() => { movesList.Items.Add(move); }); } imgViewChessboad.Dispatcher.Invoke(() => { imgViewChessboad.Source = Tools.ImageToBitmapSource(obraz); }); } } catch (Exception /*ex*/) { //System.Windows.MessageBox.Show(ex.Message); } }
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);*/ } } }