Example #1
0
        public override void ProcessMouse(System.Drawing.Point p, bool leftMouseButton, int cameraNum)
        {
            if (cameraNum != 0)
            {
                return;
            }

            if (p.X < 0 || p.X >= this.imageSize.Width ||
                p.Y < 0 || p.Y >= this.imageSize.Height)
            {
                return;
            }

            imagePoint.X = p.X;
            imagePoint.Y = p.Y;
            _current_track_points[0].x = p.X;
            _current_track_points[0].y = p.Y;
            _last_track_points[0].x    = p.X;
            _last_track_points[0].y    = p.Y;
            if (!validTrackPoint)
            {
                if (CMSLogger.CanCreateLogEvent(false, false, false, "CMSLogStandardStateEvent"))
                {
                    CMSLogStandardStateEvent logEvent = new CMSLogStandardStateEvent();
                    if (logEvent != null)
                    {
                        logEvent.ValidTrackingPoint = true;
                        CMSLogger.SendLogEvent(logEvent);
                    }
                }
            }
            validTrackPoint = true;
            trackingSuiteAdapter.ToggleSetup(false);
        }
Example #2
0
        public override void Process(System.Drawing.Bitmap [] frames)
        {
            Bitmap frame = frames[0];

            if (frame == null)
            {
                throw new Exception("Frame is null!");
            }

            if (frame.Width != imageSize.Width || frame.Height != imageSize.Height)
            {
                throw new Exception("Invalid frame sizes");
            }


            _curFrame.setImage(frame);

            CvImageWrapper.ConvertImageColor(_curFrame, _grey, ColorConversion.BGR2GRAY);

            SwapPoints(ref _current_track_points[0], ref _last_track_points[0]);

            cvCalcOpticalFlowPyrLK(_prev_grey._rawPtr, _grey._rawPtr, _prev_pyramid._rawPtr,
                                   _pyramid._rawPtr, _last_track_points, _current_track_points, 1, _pwinsz, 3,
                                   _status, null, _criteria, _flowflags);

            if (validTrackPoint && _status[0] == 0)
            {
                if (CMSLogger.CanCreateLogEvent(false, false, false, "CMSLogStandardStateEvent"))
                {
                    CMSLogStandardStateEvent logEvent = new CMSLogStandardStateEvent();
                    if (logEvent != null)
                    {
                        logEvent.ValidTrackingPoint = false;
                        CMSLogger.SendLogEvent(logEvent);
                    }
                }

                eyeLocatorTickCount = Environment.TickCount;
                validTrackPoint     = false;
                imagePoint          = PointF.Empty;
                trackingSuiteAdapter.ToggleSetup(true);
                trackingSuiteAdapter.SendMessage(CMSConstants.PLEASE_CLICK_TF);
            }


            LimitTPDelta(ref _current_track_points[0], _last_track_points[0]);

            //CvPoint2D32f p = _current_track_points[0];


            SwapImages(ref _grey, ref _prev_grey);
            SwapImages(ref _pyramid, ref _prev_pyramid);

            if (validTrackPoint)
            {
                imagePoint.X = _current_track_points[0].x;
                imagePoint.Y = _current_track_points[0].y;
                DrawOnFrame(frame);
            }
            else
            {
                if (!autoStartMode.Equals(AutoStartMode.None))
                {
                    long eyeLocatorNewTickCount = Environment.TickCount;

                    if (eyeLocatorNewTickCount - eyeLocatorTickCount > 10000)
                    {
                        if (!autoStartEnded)
                        {
                            trackingSuiteAdapter.SendMessage("Please Blink");
                            autoStartEnded = true;
                        }

                        eyeLocator.AddImage(frame);
                        if (eyeLocator.TrackingPointsFound)
                        {
                            CvPoint2D32f p = new CvPoint2D32f();

                            if (autoStartMode.Equals(AutoStartMode.LeftEye))
                            {
                                p = eyeLocator.LeftEyeTrackingPoint;
                            }
                            else if (autoStartMode.Equals(AutoStartMode.RightEye))
                            {
                                p = eyeLocator.RightEyeTrackingPoint;
                            }
                            else if (autoStartMode.Equals(AutoStartMode.NoseMouth))
                            {
                                p = eyeLocator.MouseTrackingPoint;
                            }

                            eyeLocator.Reset();

                            imagePoint.X = (int)p.x;
                            imagePoint.Y = (int)p.y;
                            _current_track_points[0].x = p.x;
                            _current_track_points[0].y = p.y;
                            _last_track_points[0].x    = p.x;
                            _last_track_points[0].y    = p.y;

                            validTrackPoint = true;
                            trackingSuiteAdapter.ToggleSetup(false);
                            trackingSuiteAdapter.ToggleControl(true);
                        }
                    }
                    else
                    {
                        autoStartEnded = false;
                        int second = (int)Math.Round(((double)(10000 - (eyeLocatorNewTickCount - eyeLocatorTickCount))) / 1000.0);
                        trackingSuiteAdapter.SendMessage("Auto Start in " + second + " seconds");
                    }
                }
            }
        }