Beispiel #1
0
        //public override bool ReadyForControl()
        //{
        //    return validTrackPoint;
        //}


        public override void Clean()
        {
            if (eyeLocator != null)
            {
                eyeLocator.Dispose();
                eyeLocator = null;
            }


            _flowflags = 0;
            if (this._curFrame != null)
            {
                CvImageWrapper.ReleaseImage(_curFrame);
            }
            if (_grey != null)
            {
                CvImageWrapper.ReleaseImage(_grey);
            }
            if (_prev_grey != null)
            {
                CvImageWrapper.ReleaseImage(_prev_grey);
            }
            if (_pyramid != null)
            {
                CvImageWrapper.ReleaseImage(_pyramid);
            }
            if (_prev_pyramid != null)
            {
                CvImageWrapper.ReleaseImage(_prev_pyramid);
            }
            if (_swap_temp != null)
            {
                CvImageWrapper.ReleaseImage(_swap_temp);
            }
        }
Beispiel #2
0
        private void SwapImages(ref CvImageWrapper a, ref CvImageWrapper b)
        {
            CvImageWrapper temp;

            temp = a;
            a    = b;
            b    = temp;
        }
        public void cropSubImage(CvRect rect, CvImageWrapper croppedImage)
        {
            if (rect.x < 0 || rect.y < 0 ||
                (rect.x + rect.width > this._size.Width) ||
                (rect.y + rect.height > this._size.Height))
            {
                throw new Exception("invalid rect: " + rect);
            }

            cvSetImageROI(this._rawPtr, rect);
            cvCopy(this._rawPtr, croppedImage._rawPtr, IntPtr.Zero);
            cvResetImageROI(this._rawPtr);
        }
Beispiel #4
0
        public override void Init(Size [] imageSizes)
        {
            Clean();

            int imageWidth  = imageSizes[0].Width;
            int imageHeight = imageSizes[0].Height;

            eyeLocator = new EyeLocator(3);
            eyeLocator.Reset();
            eyeLocatorTickCount = Environment.TickCount;

            _flowflags      |= CMSConstants.CV_LKFLOW_PYR_A_READY;
            validTrackPoint  = false;
            _pwinsz          = new CvSize(10, 10);
            _status          = new byte[1];
            imageSize.Width  = imageWidth;
            imageSize.Height = imageHeight;

            _last_track_points    = new CvPoint2D32f[1];
            _current_track_points = new CvPoint2D32f[1];

            _criteria = new CvTermCriteria(CMSConstants.CV_TERMCRIT_ITER | CMSConstants.CV_TERMCRIT_EPS, 20, 0.03);

            _curFrame = CvImageWrapper.CreateImage(imageSize, PIXEL_DEPTH, PIXEL_COLOR_CHANNELS);

            _grey = CvImageWrapper.CreateImage(imageSize, PIXEL_DEPTH, PIXEL_CHANNELS);

            _prev_grey = CvImageWrapper.CreateImage(imageSize, PIXEL_DEPTH, PIXEL_CHANNELS);

            _pyramid = CvImageWrapper.CreateImage(imageSize, PIXEL_DEPTH, PIXEL_CHANNELS);

            _prev_pyramid = CvImageWrapper.CreateImage(imageSize, PIXEL_DEPTH, PIXEL_CHANNELS);

            _swap_temp = CvImageWrapper.CreateImage(imageSize, PIXEL_DEPTH, PIXEL_CHANNELS);

            CMSTrackingSuiteAdapter.SendMessage(CMSConstants.PLEASE_CLICK_TF);
        }
Beispiel #5
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");
                    }
                }
            }
        }
        public static void ConvertImageColor(CvImageWrapper src, CvImageWrapper dest, ColorConversion code)

        {
            cvCvtColor(src._rawPtr, dest._rawPtr, code);
        }
        public static void ReleaseImage(CvImageWrapper img)

        {
            cvReleaseImage(ref img._rawPtr);
        }