Ejemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();

            //ViewModel からのスクリプト実行用のdelegate
            DataContextChanged += (o, e) =>
            {
                ViewModel vm = DataContext as ViewModel;
                if (vm != null)
                {
                    vm._ExecuteScript += (sender, arg) =>
                    {
                        Dispatcher.Invoke(new Action(() => { pythonConsole.Pad.Console.RunStatements(arg.cmd); }));
                    };

                    vm._DrawCameraBitmap += (sender, arg) =>
                    {
                        Dispatcher.BeginInvoke(new Action(() =>
                        {
                            IplImage img = vm.VisionControl.GetCameraImage();

                            DrawCameraViewEventArgs a = arg as DrawCameraViewEventArgs;

                            if (a._draw == 1)
                            {
                                CvRect rect = new CvRect(a._x1, a._y1, a._x2, a._y2);
                                img.DrawRect(rect, new CvScalar(255, 0, 0), 2);
                            }
                            else if (a._draw == 2)
                            {
                                int x1 = a._x1 - a._x2 / 2;
                                int x2 = a._x1 + a._x2 / 2;
                                int y1 = a._y1 - a._y2 / 2;
                                int y2 = a._y1 + a._y2 / 2;
                                img.DrawLine(x1, a._y1, x2, a._y1, new CvScalar(255, 0, 0), 2);
                                img.DrawLine(a._x1, y1, a._x1, y2, new CvScalar(255, 0, 0), 2);
                            }

                            if (VM.CenterLine == true)
                            {
                                img.DrawLine(0, 320, 640, 320, new CvScalar(255, 0, 0, 0), 2);
                                img.DrawLine(320, 0, 320, 640, new CvScalar(255, 0, 0, 0), 2);
                            }

                            WriteableBitmapConverter.ToWriteableBitmap(img, _col_wb);

                            cameraImage.Source = _col_wb;

                            img.Dispose();

                            //cameraImage.Source = vm.VisionControl.GetCameraBitmap();
                        }));
                    };
                }
            };

            pythonConsole.Pad.Host.ConsoleCreated += new PythonConsoleControl.ConsoleCreatedEventHandler(Host_ConsoleCreated);
        }
Ejemplo n.º 2
0
 /// <summary>
 ///  画像取り込み完了時に VisionModel 側から呼び出されるハンドラ
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void grab_event_func(object sender, DrawCameraViewEventArgs args)
 {
     _DrawCameraBitmap(sender, args);
 }