/// <summary> /// Maps a GazeData gaze point (RawCoordinates or SmoothedCoordinates) to Unity screen space. /// Note that gaze points have origo in top left corner, whilst Unity uses lower left. /// </summary> /// <param name="gp"/>gaze point to map</param> /// <returns>2d point mapped to unity window space</returns> public static Point2D getGazeCoordsToUnityWindowCoords(Point2D gp) { double rx = gp.X * ((double)Screen.width / GazeManager.Instance.ScreenResolutionWidth); double ry = (GazeManager.Instance.ScreenResolutionHeight - gp.Y) * ((double)Screen.height / GazeManager.Instance.ScreenResolutionHeight); return new Point2D(rx, ry); }
public Eye() { RawCoordinates = new Point2D(); SmoothedCoordinates = new Point2D(); PupilCenterCoordinates = new Point2D(); PupilSize = 0d; }
public CalibrationPoint() { Coordinates = new Point2D(); MeanEstimatedCoords = new Point2D(); Accuracy = new Accuracy(); MeanError = new MeanError(); StandardDeviation = new StandardDeviation(); }
public GazeData() { TimeStamp = (long)Math.Round(DateTime.Now.TimeOfDay.TotalMilliseconds); IsFixated = false; RawCoordinates = new Point2D(); SmoothedCoordinates = new Point2D(); LeftEye = new Eye(); RightEye = new Eye(); }
public Eye(Eye other) { if (null != other) { RawCoordinates = new Point2D(other.RawCoordinates); SmoothedCoordinates = new Point2D(other.SmoothedCoordinates); PupilCenterCoordinates = new Point2D(other.PupilCenterCoordinates); PupilSize = other.PupilSize; } }
public GazeData() { DateTime now = DateTime.Now; TimeStamp = (long)((double)now.Ticks / TimeSpan.TicksPerMillisecond); TimeStampString = now.ToString(TIMESTAMP_STRING_FORMAT); IsFixated = false; RawCoordinates = new Point2D(); SmoothedCoordinates = new Point2D(); LeftEye = new Eye(); RightEye = new Eye(); }
/// <summary> /// Converts a coordinate on picture space to a 3D pose, using an expected inter-eyes distance to compute depth coordinate. /// We follow the standard Pinhole model here /// </summary> public static Point3D BackProjectDepthPinhole(Point2D eyePictCoord, double pictEyesDistance) { // We use the pinhole model, with a depth related to the inter-eyes distance double interEyesDistance = 0.06; // 6cm on average double depth = interEyesDistance / Math.Max(pictEyesDistance, 0.0001F); double tx = (eyePictCoord.X - 0.5) * depth; double ty = (eyePictCoord.Y - 0.5) * depth; return new Point3D((float)tx, (float)ty, (float)depth); }
/// <summary> /// Converts a coordinate on picture space to a 3D pose, using an expected inter-eyes distance to compute depth coordinate /// </summary> public static Point3D BackProjectDepth(Point2D eyePictCoord, double eyesDistance, double baseDist) { //mapping cam panning to 3:2 aspect ratio double tx = (eyePictCoord.X * 5) - 2.5f; double ty = (eyePictCoord.Y * 3) - 1.5f; //position camera X-Y plane and adjust distance double depthMod = 2 * eyesDistance; return new Point3D((float)tx, (float)ty, (float)(baseDist + depthMod)); }
public GazeData(GazeData other) { if (null != other) { State = other.State; TimeStamp = other.TimeStamp; TimeStampString = other.TimeStampString; RawCoordinates = new Point2D(other.RawCoordinates); SmoothedCoordinates = new Point2D(other.SmoothedCoordinates); LeftEye = new Eye(other.LeftEye); RightEye = new Eye(other.RightEye); IsFixated = other.IsFixated; } }
/// <summary> /// Find average pupil center of two eyes. /// </summary> /// <param name="leftEye"/></param> /// <param name="rightEye"/></param> /// <returns>the average center point in normalized values</returns> public static Point2D getEyesCenterNormalized(Eye leftEye, Eye rightEye) { Point2D eyeCenter = new Point2D(); if (null != leftEye && null != rightEye) { eyeCenter = new Point2D( (leftEye.PupilCenterCoordinates.X + rightEye.PupilCenterCoordinates.X) / 2, (leftEye.PupilCenterCoordinates.Y + rightEye.PupilCenterCoordinates.Y) / 2 ); } else if (null != leftEye) { eyeCenter = leftEye.PupilCenterCoordinates; } else if (null != rightEye) { eyeCenter = rightEye.PupilCenterCoordinates; } return eyeCenter; }
public Point2D Add(Point2D p2) { return new Point2D(x + p2.x, y + p2.y); }
/// <summary> /// Maps a 2d pixel point into normalized space [x: -1:1 , y: -1:1] /// </summary> /// <param name="point"/>point in pixels to normalize</param> /// <param name="screenWidth"/>the width value to base normalization upon</param> /// <param name="screenHeight"/>the height value to base normalization upon</param> /// <returns>normalized 2d point</returns> public static Point2D getNormalizedMapping(Point2D point, int screenWidth, int screenHeight) { Point2D normMap = getNormalizedCoords(point, screenWidth, screenHeight); if (null != normMap) { //scale up and shift normMap.X *= 2f; normMap.X -= 1f; normMap.Y *= 2f; normMap.Y -= 1f; } return normMap; }
/// <summary> /// Converts a relative point to screen point in pixels using Unity classes /// </summary> public static Point2D getRelativeToScreenSpace(Point2D gp) { return getRelativeToScreenSpace(gp, Screen.width, Screen.height); }
/// <summary> /// Convert a Point2D to Unity vector. /// </summary> /// <param name="gp"/>gaze point to convert</param> /// <returns>a vector representation of point</returns> public static Vector2 Point2DToVec2(Point2D gp) { return new Vector2((float)gp.X, (float)gp.Y); }
/// <summary> /// Converts a relative point to screen point in pixels /// </summary> public static Point2D getRelativeToScreenSpace(Point2D point, int screenWidth, int screenHeight) { Point2D screenPoint = null; if (null != point) { screenPoint = new Point2D(point); screenPoint.X = Math.Round(screenPoint.X * screenWidth); screenPoint.Y = Math.Round(screenPoint.Y * screenHeight); } return screenPoint; }
/// <summary> /// Normalizes a pixel point based on screen dims /// </summary> /// <param name="point"/>point in pixels to normalize</param> /// <param name="screenWidth"/>the width value to base normalization upon</param> /// <param name="screenHeight"/>the height value to base normalization upon</param> /// <returns>normalized 2d point</returns> public static Point2D getNormalizedCoords(Point2D point, int screenWidth, int screenHeight) { Point2D norm = null; if (null != point) { norm = new Point2D(point); norm.X /= screenWidth; norm.Y /= screenHeight; } return norm; }
public void DrawCalibrationPoint(Point2D current) { Dispatcher.BeginInvoke(new Action(() => PlaceCalibrationTarget(current))); }
public Point2D(Point2D point) { x = point.x; y = point.y; }
public Point2D Subtract(Point2D p2) { return new Point2D(x - p2.x, y - p2.y); }
/// <summary> /// Calculates distance between two points. /// </summary> public static double getDistancePoint2D(Point2D a, Point2D b) { return Math.Sqrt(Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2)); }
private void PlaceCalibrationTarget(Point2D current) { var x = (float)Math.Round(Utility.Instance.ScaleDpi * current.X, 0); var y = (float)Math.Round(Utility.Instance.ScaleDpi * current.Y, 0); Canvas.SetLeft(CalibrationCanvas.Children[0], x); Canvas.SetTop(CalibrationCanvas.Children[0], y); }
private void Set(GazeData other) { State = other.State; TimeStamp = other.TimeStamp; TimeStampString = other.TimeStampString; RawCoordinates = new Point2D(other.RawCoordinates); SmoothedCoordinates = new Point2D(other.SmoothedCoordinates); LeftEye = new Eye(other.LeftEye); RightEye = new Eye(other.RightEye); IsFixated = other.IsFixated; }