public override void Init(Size[] imageSizes) { Clean(); _flowflags |= CMSConstants.CV_LKFLOW_PYR_A_READY; validTrackPoints = false; _pwinsz = new CvSize(10, 10); _status = new byte[NumberOfTrackingPoints]; imageSize.Width = imageSizes[0].Width; imageSize.Height = imageSizes[0].Height; _last_track_points = new CvPoint2D32f[NumberOfTrackingPoints]; _current_track_points = new CvPoint2D32f[NumberOfTrackingPoints]; _criteria = new CvTermCriteria(CMSConstants.CV_TERMCRIT_ITER | CMSConstants.CV_TERMCRIT_EPS, 20, 0.03); _curFrame = CvImageWrapper.CreateImage(imageSize, PixelDepth, PixelColorChannels); _grey = CvImageWrapper.CreateImage(imageSize, PixelDepth, PixelChannels); _prev_grey = CvImageWrapper.CreateImage(imageSize, PixelDepth, PixelChannels); _pyramid = CvImageWrapper.CreateImage(imageSize, PixelDepth, PixelChannels); _prev_pyramid = CvImageWrapper.CreateImage(imageSize, PixelDepth, PixelChannels); _swap_temp = CvImageWrapper.CreateImage(imageSize, PixelDepth, PixelChannels); eyeLocator = new EyeLocator(EyeLocationImageCount); eyeLocator.Reset(); eyeImagePoints = new PointF[2]; CMSTrackingSuiteAdapter.SendMessage(InitMessage); }
public override void Init(Size[] imageSizes) { eyeLocator = new EyeLocator(3); eyeLocator.Reset(); eyeLocatorTickCount = Environment.TickCount; lastClickPoint = Point.Empty; int imageWidth = imageSizes[0].Width; int imageHeight = imageSizes[0].Height; lock (mutex) { CleanStandard(); InitStandard(imageWidth, imageHeight); } CMSTrackingSuiteAdapter.SendMessage(CMSConstants.PLEASE_CLICK_TF); }
public override void Process(Bitmap[] frames) { extraTrackingInfo = null; 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); if (!validTrackPoints) { eyeLocator.AddImage(frame); if (eyeLocator.TrackingPointsFound) { _current_track_points[MousePointIndex] = eyeLocator.MouseTrackingPoint; _current_track_points[LeftEyePointIndex] = eyeLocator.LeftEyeTrackingPoint; _current_track_points[RightEyePointIndex] = eyeLocator.RightEyeTrackingPoint; leftEyeOffset.x = eyeLocator.LeftEyePoint.x - eyeLocator.LeftEyeTrackingPoint.x; leftEyeOffset.y = eyeLocator.LeftEyePoint.y - eyeLocator.LeftEyeTrackingPoint.y; rightEyeOffset.x = eyeLocator.RightEyePoint.x - eyeLocator.RightEyeTrackingPoint.x; rightEyeOffset.y = eyeLocator.RightEyePoint.y - eyeLocator.RightEyeTrackingPoint.y; validTrackPoints = true; } else { trackingSuiteAdapter.SendMessage(InitMessage); } } for (int i = 0; i < NumberOfTrackingPoints; ++i) { SwapPoints(ref _current_track_points[i], ref _last_track_points[i]); } cvCalcOpticalFlowPyrLK(_prev_grey._rawPtr, _grey._rawPtr, _prev_pyramid._rawPtr, _pyramid._rawPtr, _last_track_points, _current_track_points, NumberOfTrackingPoints, _pwinsz, 3, _status, null, _criteria, _flowflags); if (validTrackPoints) { for (int i = 0; i < NumberOfTrackingPoints; ++i) { if (_status[i] == 0) { validTrackPoints = false; trackingSuiteAdapter.ToggleSetup(true); eyeLocator.Reset(); break; } } } for (int i = 0; i < NumberOfTrackingPoints; ++i) { LimitTPDelta(ref _current_track_points[i], _last_track_points[i]); } SwapImages(ref _grey, ref _prev_grey); SwapImages(ref _pyramid, ref _prev_pyramid); if (validTrackPoints) { extraTrackingInfo = new BlinkLinkClickControlModule.BlinkLinkCMSExtraTrackingInfo( new CvPoint2D32f(_current_track_points[LeftEyePointIndex].x + leftEyeOffset.x, _current_track_points[LeftEyePointIndex].y + leftEyeOffset.y), new CvPoint2D32f(_current_track_points[RightEyePointIndex].x + rightEyeOffset.x, _current_track_points[RightEyePointIndex].y + rightEyeOffset.y)); imagePoint.X = _current_track_points[MousePointIndex].x; imagePoint.Y = _current_track_points[MousePointIndex].y; eyeImagePoints[0].X = _current_track_points[LeftEyePointIndex].x; eyeImagePoints[0].Y = _current_track_points[LeftEyePointIndex].y; eyeImagePoints[1].X = _current_track_points[RightEyePointIndex].x; eyeImagePoints[1].Y = _current_track_points[RightEyePointIndex].y; } }
private void SetState(AHMTrackingState newState) { string message = null; lock (mutex) { if (CMSLogger.CanCreateLogEvent(false, false, false, "AHMLogStateEvent")) { AHMLogStateEvent stateEvent = new AHMLogStateEvent(); if (stateEvent != null) { stateEvent.State = newState.ToString(); CMSLogger.SendLogEvent(stateEvent); } } if (newState.Equals(AHMTrackingState.NoFeature)) { eyeLocatorTickCount = Environment.TickCount; lastClickPoint = Point.Empty; imagePoint = PointF.Empty; autoStartEnded = false; if (!autoStartMode.Equals(AutoStartMode.None)) { if (eyeLocator != null) { eyeLocator.Reset(); } } if (state.Equals(AHMTrackingState.AHMSetup)) { ahmSetup.Clean(); } else if (state.Equals(AHMTrackingState.Tracking)) { if (extraDisplay) { trackingSuiteAdapter.SendMessages(null, null); } if (cameraMouseAssist != null) { cameraMouseAssist.Dispose(); cameraMouseAssist = null; } } trackingSuiteAdapter.ToggleSetup(true); state = AHMTrackingState.NoFeature; message = "Select Feature to Start Setup"; } else if (newState.Equals(AHMTrackingState.Feature)) { if (state.Equals(AHMTrackingState.AHMSetup)) { ahmSetup.Clean(); } else if (state.Equals(AHMTrackingState.Tracking)) { if (extraDisplay) { trackingSuiteAdapter.SendMessages(null, null); } if (cameraMouseAssist != null) { cameraMouseAssist.Dispose(); cameraMouseAssist = null; } trackingSuiteAdapter.ToggleSetup(true); } state = AHMTrackingState.Feature; message = "Press Tab to Start Training"; } else if (newState.Equals(AHMTrackingState.AHMSetup)) { StartAHMSetup(); state = AHMTrackingState.AHMSetup; } else if (newState.Equals(AHMTrackingState.Tracking)) { //if (state.Equals(AHMTrackingState.AHMSetup)) //ahmSetup.Clean(); state = AHMTrackingState.Tracking; trackingSuiteAdapter.ToggleSetup(false); message = ", press Tab to reset"; if (!autoStartMode.Equals(AutoStartMode.None)) { //message = ", control will start shortly"; Thread t = new Thread(new ThreadStart(StartControlThread)); t.Start(); } } } if (message != null) { this.trackingSuiteAdapter.SendMessage(message); } }
private void SetState(AHMTrackingState newState) { string message = null; lock (mutex) { if (CMSLogger.CanCreateLogEvent(false, false, false, "AHMLogStateEvent")) { AHMLogStateEvent stateEvent = new AHMLogStateEvent(); if (stateEvent != null) { stateEvent.State = newState.ToString(); CMSLogger.SendLogEvent(stateEvent); } } if (newState.Equals(AHMTrackingState.NoFeature)) { autoStartEnded = false; eyeLocatorTickCount = Environment.TickCount; lastClickPoint = Point.Empty; imagePoint = PointF.Empty; if (eyeLocator != null) { eyeLocator.Reset(); } if (state.Equals(AHMTrackingState.AHMSetup)) { ahmSetup.Clean(); } else if (state.Equals(AHMTrackingState.Tracking)) { for (int i = 0; i < cameraMouseAssists.Length; i++) { if (cameraMouseAssists[i] != null) { cameraMouseAssists[i].Dispose(); cameraMouseAssists[i] = null; } } } trackingSuiteAdapter.ToggleSetup(true); state = AHMTrackingState.NoFeature; message = "Select Feature to Start Setup"; } else if (newState.Equals(AHMTrackingState.AHMSetup)) { StartAHMSetup(); state = AHMTrackingState.AHMSetup; } else if (newState.Equals(AHMTrackingState.Tracking)) { //if (state.Equals(AHMTrackingState.AHMSetup)) //ahmSetup.Clean(); state = AHMTrackingState.Tracking; //trackingSuiteAdapter.ToggleSetup(false); //message = ", Press Tab to reset"; //trackingSuiteAdapter.ToggleControl(true); } } if (message != null) { this.trackingSuiteAdapter.SendMessage(message); } }