/// <summary> /// /// </summary> /// <param name="glyphs"></param> /// <param name="gaze"></param> /// <param name="diameter"></param>in percent (e.g. 150% of marker size) /// <returns></returns> public string GetGazedGlyph(AForge.Point gaze, double diameter) { ExtractedGlyphData myGlyph = null; //foundGlyphs[0]; double min = 100000; AForge.IntPoint minXY, maxXY; AForge.IntPoint center; foreach (ExtractedGlyphData glyphData in foundGlyphs) { // get glyph's center point PointsCloud.GetBoundingRectangle(glyphData.Quadrilateral, out minXY, out maxXY); center = (minXY + maxXY) / 2; double dis = GetDistance(new Point(center.X, center.Y), new Point((int)gaze.X, (int)gaze.Y)); if (dis < min) { myGlyph = glyphData; min = dis; } } if (myGlyph != null) { PointsCloud.GetBoundingRectangle(myGlyph.Quadrilateral, out minXY, out maxXY); double glyphDiameter = Math.Sqrt(2) * ((maxXY - minXY).X); double acceptedDis = (diameter * (glyphDiameter / 2)); if (min > acceptedDis) { myGlyph = null; } } gazedMarkerHistory_Update(myGlyph, gaze); string name = ""; if (myGlyph != null) { name = myGlyph.RecognizedGlyph.Name; } return(name); }
public void gazedMarkerHistory_Update(ExtractedGlyphData glyph, AForge.Point gaze) { gazedMarkerHistory_Shift(); gazedMarkerHistory[0].name = ""; gazedMarkerHistory[0].tag = ""; if (glyph != null) { AForge.IntPoint minXY, maxXY; PointsCloud.GetBoundingRectangle(glyph.Quadrilateral, out minXY, out maxXY); AForge.IntPoint center = (minXY + maxXY) / 2; gazedMarkerHistory[0].tag = ""; gazedMarkerHistory[0].gaze = gaze; gazedMarkerHistory[0].markerCenter = new Point(center.X, center.Y); gazedMarkerHistory[0].name = glyph.RecognizedGlyph != null? glyph.RecognizedGlyph.Name:""; } }
/// <summary> /// distance is metured in Marker diameter unit. e.g. 1 diameter 2 diameter .... /// </summary> /// <param name="glyph"></param> /// <param name="gaze"></param> /// <returns></returns> public double getGazeDistance(ExtractedGlyphData glyph, AForge.Point gaze) { double dis = 0; AForge.IntPoint minXY, maxXY; PointsCloud.GetBoundingRectangle(glyph.Quadrilateral, out minXY, out maxXY); AForge.IntPoint center = (minXY + maxXY) / 2; dis = GetDistance(new Point(center.X, center.Y), new Point((int)gaze.X, (int)gaze.Y)); PointsCloud.GetBoundingRectangle(glyph.Quadrilateral, out minXY, out maxXY); double glyphDiameter = Math.Sqrt(2) * ((maxXY - minXY).X); dis = dis / glyphDiameter; return(dis); }
private PositionAndOrientation GetPositionAndOrientationFromGlyph(ExtractedGlyphData glyph) { double x = glyph.RecognizedQuadrilateral.Average(g => g.X); double y = glyph.RecognizedQuadrilateral.Average(g => g.Y); Matrix4x4 transformationMatrix = glyph.TransformationMatrix; float roll; float pitch; float yaw; transformationMatrix.ExtractYawPitchRoll(out yaw, out pitch, out roll); double xP = Math.Cos((double)yaw) * Math.Cos((double)pitch); double yP = Math.Sin((double)yaw) * Math.Cos((double)pitch); double zP = Math.Sin((double)pitch); //double angle = yaw * 180.0d / Math.PI + 180.0d; double angle = 180.0d - Math.Atan2(yP, zP) / Math.PI * 180.0d; return(new PositionAndOrientation(x, y, angle)); }
/// <summary> /// anglebetween gazepoint, glyph center and top point of the glyph /// </summary> /// <param name="glyph"></param> /// <param name="gaze"></param> /// <returns></returns> public int getGazeAngle(ExtractedGlyphData glyph, AForge.Point gaze) { int angle = 0; //gaze AForge.IntPoint g = new AForge.IntPoint(Convert.ToInt32(gaze.X), Convert.ToInt32(gaze.Y)); //top point Point topCenter = new Point(0, 0); int i = 0, j = 1; topCenter.X = (glyph.Quadrilateral[i].X + glyph.Quadrilateral[j].X) / 2; topCenter.Y = (glyph.Quadrilateral[i].Y + glyph.Quadrilateral[j].Y) / 2; AForge.IntPoint top = new AForge.IntPoint(topCenter.X, topCenter.Y); //center AForge.IntPoint minXY, maxXY; PointsCloud.GetBoundingRectangle(glyph.Quadrilateral, out minXY, out maxXY); AForge.IntPoint center = (minXY + maxXY) / 2; AForge.IntPoint cnt = new AForge.IntPoint(center.X, center.Y); angle = (int)(AForge.Math.Geometry.GeometryTools.GetAngleBetweenVectors(cnt, g, top)); int direc = 1; if ((cnt.X - top.X) != 0 && (g.Y - cnt.Y - ((cnt.Y - top.Y) / (cnt.X - top.X)) * (g.X - cnt.X)) < 0) { direc = -1; } // if (top.X < cnt.X) direc *= -1; angle *= direc; return(angle); }