/// <summary>
        /// Constructor
        /// </summary>
        /// <param name="player">The video player in the GUI</param>
        private MMazeBehaviorViewModel(  )
        {
            //Setup the plot
            SetupPlot();

            //Subscribe to event notifications from the behavior session
            MMazeBehaviorSession.GetInstance().PropertyChanged += ExecuteReactionsToModelPropertyChanged;
        }
예제 #2
0
        private void Camera_NewFrame(object sender, Accord.Video.NewFrameEventArgs eventArgs)
        {
            //Grab the video frame itself
            var video_frame = eventArgs.Frame;

            //Create a graphics object
            using (Graphics g = Graphics.FromImage(video_frame))
            {
                //Grab a separate copy of the video frame to save to the file
                var video_frame_copy = video_frame.Clone() as System.Drawing.Bitmap;

                //Make a semi-transparent rectangle near the top of the image
                SolidBrush b = new SolidBrush(System.Drawing.Color.FromArgb(128, System.Drawing.Color.CornflowerBlue));
                g.FillRectangle(b, new RectangleF(0, 0, _camera_frame_width, _overlay_height));

                //Draw each box
                SolidBrush b2 = new SolidBrush(System.Drawing.Color.FromArgb(128, System.Drawing.Color.Red));
                for (int i = 0; i < _box_lefts.Count; i++)
                {
                    g.DrawRectangle(new System.Drawing.Pen(b2, 4), new System.Drawing.Rectangle(_box_lefts[i], _box_top, _box_width, _box_height));
                }

                //Draw some text under each box
                List <string> _box_strings = new List <string>()
                {
                    "Left NP",
                    "Left Prox",
                    "Right Prox",
                    "Right NP",
                    "Sound Cue"
                };

                for (int i = 0; i < _box_lefts.Count; i++)
                {
                    g.DrawString(_box_strings[i], System.Drawing.SystemFonts.DefaultFont, b2, _box_lefts[i], _box_top + 110);
                }

                //Now let's draw some graphics based on the current state of the session.
                var model = MMazeBehaviorSession.GetInstance();
                var vm    = MMazeBehaviorViewModel.GetInstance();
                if (model != null && vm != null)
                {
                    if (model.LeftNosepokeState)
                    {
                        g.FillRectangle(b2, _box_lefts[0], _box_top, _box_width, _box_height);
                    }
                    if (model.LeftProxState)
                    {
                        g.FillRectangle(b2, _box_lefts[1], _box_top, _box_width, _box_height);
                    }
                    if (model.RightProxState)
                    {
                        g.FillRectangle(b2, _box_lefts[2], _box_top, _box_width, _box_height);
                    }
                    if (model.RightNosepokeState)
                    {
                        g.FillRectangle(b2, _box_lefts[3], _box_top, _box_width, _box_height);
                    }
                    if (model.IsSoundPlaying)
                    {
                        g.FillRectangle(b2, _box_lefts[4], _box_top, _box_width, _box_height);
                    }

                    //Create blank canvas for saving image to video file
                    Bitmap resized_canvas = new Bitmap(video_frame_copy.Width, video_frame_copy.Height + _overlay_height);

                    //Create a new graphics object with the blank canvas
                    using (Graphics g2 = Graphics.FromImage(resized_canvas))
                    {
                        //Paste the video frame on the blank canvas
                        g2.DrawImage(video_frame_copy, 0, _overlay_height, video_frame_copy.Width, video_frame_copy.Height);

                        //Draw the overlay on the top of the image
                        g2.FillRectangle(b, new RectangleF(0, 0, _camera_frame_width, _overlay_height));
                        for (int i = 0; i < _box_lefts.Count; i++)
                        {
                            g2.DrawRectangle(new System.Drawing.Pen(b2, 4), new System.Drawing.Rectangle(_box_lefts[i], _box_top, _box_width, _box_height));
                            g2.DrawString(_box_strings[i], System.Drawing.SystemFonts.DefaultFont, b2, _box_lefts[i], _box_top + 110);
                        }

                        if (model.LeftNosepokeState)
                        {
                            g2.FillRectangle(b2, _box_lefts[0], _box_top, _box_width, _box_height);
                        }
                        if (model.LeftProxState)
                        {
                            g2.FillRectangle(b2, _box_lefts[1], _box_top, _box_width, _box_height);
                        }
                        if (model.RightProxState)
                        {
                            g2.FillRectangle(b2, _box_lefts[2], _box_top, _box_width, _box_height);
                        }
                        if (model.RightNosepokeState)
                        {
                            g2.FillRectangle(b2, _box_lefts[3], _box_top, _box_width, _box_height);
                        }
                        if (model.IsSoundPlaying)
                        {
                            g2.FillRectangle(b2, _box_lefts[4], _box_top, _box_width, _box_height);
                        }

                        //Now let's take the current video frame and write it out to a saved video for the session
                        vm.WriteVideoFrame(resized_canvas);
                    }

                    //Release some resouces
                    resized_canvas.Dispose();
                }

                //Release some resources
                video_frame_copy.Dispose();
            }
        }