public override bool Process(PointF [] imagePoints, System.Drawing.Bitmap [] frames) { lock (mutex) { if (finished) { return(false); } for (int i = 0; i < imagePoints.Length; i++) { curPoints[i].X = imagePoints[i].X; curPoints[i].Y = imagePoints[i].Y; } if (curFrame == null) { curFrame = new CvImageWrapper(frames[0]); } else { curFrame.setImage(frames[0]); } return(true); } }
private void CaptureImages(PointF [] imagePoints, Bitmap frame) { try { if (curFrame == null) { curFrame = new CvImageWrapper(frame); } else { curFrame.setImage(frame); } for (int i = 0; i < imagePoints.Length; i++) { PointF imagePoint = imagePoints[i]; CvRect cropDimensions = new CvRect(); cropDimensions.x = (int)imagePoint.X - obsSize / 2; cropDimensions.y = (int)imagePoint.Y - obsSize / 2; cropDimensions.width = obsSize; cropDimensions.height = obsSize; CvImageWrapper curObs = curFrame.cropSubImage(cropDimensions); this.templatesList[i].Add(curObs); } } catch (Exception e) { } }
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; } }
public override bool Process(PointF [] imagePoints, System.Drawing.Bitmap[] frames) { lock (mutex) { if (finished) { return(false); } if (centerPoint.IsEmpty) { centerPoint.X = imagePoints[0].X; centerPoint.Y = imagePoints[0].Y; return(true); } if (curFrame == null) { curFrame = new CvImageWrapper(frames[0]); } else { curFrame.setImage(frames[0]); } if (setupFrame == null) { setupFrame = new Bitmap(curFrame.Size.Width, curFrame.Size.Height); InitSetupFrame(); } relCurPoint = mouseControlStandard.ComputeRelCursorInWindow(imagePoints[0], centerPoint); int xRectIndex = (int)Math.Floor((double)rectangleLength * relCurPoint.X); int yRectIndex = (int)Math.Floor((double)rectangleLength * relCurPoint.Y); if (xRectIndex >= rectangleLength) { xRectIndex = rectangleLength - 1; } if (yRectIndex >= rectangleLength) { yRectIndex = rectangleLength - 1; } if (xRectIndex < 0) { xRectIndex = 0; } if (yRectIndex < 0) { yRectIndex = 0; } if (rectangles[xRectIndex, yRectIndex] && !finished) { rectangles[xRectIndex, yRectIndex] = false; curNumRectangles++; for (int i = 0; i < imagePoints.Length; i++) { PointF imagePoint = imagePoints[i]; if (!(imagePoint.X <= obsSize / 2 || imagePoint.X >= curFrame.Size.Width - obsSize / 2) && !(imagePoint.Y <= obsSize / 2 || imagePoint.Y >= curFrame.Size.Height - obsSize / 2)) { CvRect cropDimensions = new CvRect(); cropDimensions.x = (int)imagePoint.X - obsSize / 2; cropDimensions.y = (int)imagePoint.Y - obsSize / 2; cropDimensions.width = obsSize; cropDimensions.height = obsSize; CvImageWrapper curObs = curFrame.cropSubImage(cropDimensions); this.templatesList[i].Add(curObs); UpdateSetupFrame(); } } if (curNumRectangles == this.numTemplates) { this.finished = true; return(false); } else { SendMessage(); } } else if (shouldSendMessage) { shouldSendMessage = false; SendMessage(); } return(true); } }