Пример #1
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            double screenX = Screen.PrimaryScreen.WorkingArea.Width / 2;
            double screenY = Screen.PrimaryScreen.WorkingArea.Height / 2;
            double offsetY = Screen.PrimaryScreen.Bounds.Y;

            Left = Math.Max((screenX - ActualWidth) / 2, 0);
            Top  = 40;

            resultWindow = new CamerPreviewWindow();
            resultWindow.Show();
            resultWindow.Left = Left;
            resultWindow.Top  = Top + ActualHeight + 10;

            detector    = new CascadeDetector(FACE_FILE, EYE_FILE);
            cameraFrame = new Mat();
            grayFrame   = new Mat();
            try
            {
                capture = new VideoCapture();
                if (App.VideoPath != null)
                {
                    captureOutput = new VideoWriter(
                        App.VideoPath,
                        App.FrameRate,
                        new System.Drawing.Size((int)capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameWidth), (int)capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameHeight)),
                        true);
                }
                capture.FlipHorizontal = true;
                capture.ImageGrabbed  += OnFrameCaptured;
                capture.Grab();
            }
            catch (Exception excpt)
            {
                System.Windows.MessageBox.Show(excpt.Message);
            }


            canv_left.DataBuffer    = leftData;
            canv_right.DataBuffer   = rightData;
            canv_lt.DataBuffer      = leftTopData;
            canv_rt.DataBuffer      = rightTopData;
            canv_lt_dist.DataBuffer = leftDistData;
            canv_rt_dist.DataBuffer = rightDistData;

            btn_start.Click += (_sender, _e) =>
            {
                string content = btn_start.Content as string;
                if (content == "开始")
                {
                    btn_start.IsEnabled = false;
                    isStarted           = true;
                    startTime           = DateTime.Now;
                    btn_start.Content   = "停止";
                }
            };
        }
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            Pattern.PatternArguments pattern = Pattern.PatternArguments.ReadFromFile(App.PatternPath);
            drawWindow = new PatternDrawWindow(pattern, App.Speed);
            drawWindow.Show();
            double maxx = drawWindow.DrawingParamters.Points.Max(p => p.X) + PatternDrawWindow.OFFSET_X;
            double maxy = drawWindow.DrawingParamters.Points.Max(p => p.Y) + PatternDrawWindow.OFFSET_Y + 50;

            double screenX = Screen.PrimaryScreen.WorkingArea.Width / 2;
            double screenY = Screen.PrimaryScreen.WorkingArea.Height / 2;
            double offsetY = Screen.PrimaryScreen.Bounds.Y;

            if (maxx > screenX || maxy > screenY)
            {
                Close();
                return;
            }
            drawWindow.Top    = offsetY + 50;
            drawWindow.Left   = (screenX - maxx) / 2;
            drawWindow.Width  = maxx;
            drawWindow.Height = maxy;
            Left = Math.Max(drawWindow.Left - ActualWidth - 10, 0);
            Top  = drawWindow.Top;

            drawWindow.MoveBegin += OnMoveBegin;
            drawWindow.MoveEnded += OnMoveEnded;

            resultWindow = new CamerPreviewWindow();
            resultWindow.Show();
            resultWindow.Left = Left;
            resultWindow.Top  = Top + Math.Max(ActualHeight, maxy) + 10;

            detector    = new CascadeDetector(FACE_FILE, EYE_FILE);
            cameraFrame = new Mat();
            grayFrame   = new Mat();
            try
            {
                if (App.VideoPath == null)
                {
                    capture = new VideoCapture();
                }
                else
                {
                    capture = new VideoCapture(App.VideoPath);
                }
                capture.FlipHorizontal = true;
                capture.ImageGrabbed  += OnFrameCaptured;
                capture.Grab();
            }
            catch (Exception excpt)
            {
                System.Windows.MessageBox.Show(excpt.Message);
            }


            canv_left.DataBuffer  = leftData;
            canv_right.DataBuffer = rightData;
            canv_lt.DataBuffer    = leftTopData;
            canv_rt.DataBuffer    = rightTopData;

            btn_start.Click += (_sender, _e) =>
            {
                string content = btn_start.Content as string;
                if (content == "开始")
                {
                    drawWindow.Start();
                    btn_start.IsEnabled = false;
                }
            };
        }
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            drawWindow = new PatternDrawWindow(App.Speed);
            drawWindow.Show();

            double maxx = PatternDrawWindow.OFFSET_X;
            double maxy = PatternDrawWindow.OFFSET_Y + 50;

            double screenX = Screen.PrimaryScreen.WorkingArea.Width / 2;
            double screenY = Screen.PrimaryScreen.WorkingArea.Height / 2;
            double offsetY = Screen.PrimaryScreen.Bounds.Y;

            if (maxx > screenX || maxy > screenY)
            {
                Close();
                return;
            }
            drawWindow.Top    = offsetY + 50;
            drawWindow.Left   = (screenX - maxx) / 2;
            drawWindow.Width  = maxx;
            drawWindow.Height = maxy;
            Left = Math.Max(drawWindow.Left - ActualWidth - 10, 0);
            Top  = drawWindow.Top;

            drawWindow.MoveBegin += OnMoveBegin;
            drawWindow.MoveEnded += OnMoveEnded;

            resultWindow = new CamerPreviewWindow();
            resultWindow.Show();
            resultWindow.Left = Left;
            resultWindow.Top  = Top + Math.Max(ActualHeight, maxy) + 10;

            detector    = new CascadeDetector(FACE_FILE, EYE_FILE);
            cameraFrame = new Mat();
            grayFrame   = new Mat();
            try
            {
                capture = new VideoCapture();
                if (App.VideoPath != null)
                {
                    captureOutput = new VideoWriter(
                        App.VideoPath,
                        App.FrameRate,
                        new System.Drawing.Size((int)capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameWidth), (int)capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameHeight)),
                        true);
                }
                capture.FlipHorizontal = true;
                capture.ImageGrabbed  += OnFrameCaptured;
                capture.Grab();
            }
            catch (Exception excpt)
            {
                System.Windows.MessageBox.Show(excpt.Message);
            }


            canv_left.DataBuffer  = leftData;
            canv_right.DataBuffer = rightData;
            canv_lt.DataBuffer    = leftTopData;
            canv_rt.DataBuffer    = rightTopData;

            drawWindow.Width  = 600;
            drawWindow.Height = 600;

            btn_start.Click += (_sender, _e) =>
            {
                string content = btn_start.Content as string;
                if (content == "开始")
                {
                    drawWindow.Start();
                    btn_start.IsEnabled = false;
                }
            };
        }