secret
Created

  • Download Gist
FaceTrackFrame.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
/// <summary>
/// Get the 2D shape points
/// </summary>
/// <returns>
/// The 2D shape points
/// </returns>
public PointF[] Get2DShapePoints()
{
IntPtr shapePointsPtr;
uint shapePointsCount;
this.CheckPtrAndThrow();
this.faceTrackingResultPtr.Get2DShapePoints(out shapePointsPtr, out shapePointsCount); // volanie unmanaged kodu
 
PointF[] shapePoints = null;
if (shapePointsCount > 0)
{
shapePoints = new PointF[shapePointsCount];
for (int i = 0; i < shapePointsCount; i++)
{
shapePoints[i] = new PointF();
IntPtr shapePointsIthPtr;
if (IntPtr.Size == 8)
{
// 64bit
shapePointsIthPtr = new IntPtr(shapePointsPtr.ToInt64() + (i * Marshal.SizeOf(typeof(PointF))));
}
else
{
// 32bit
shapePointsIthPtr = new IntPtr(shapePointsPtr.ToInt32() + (i * Marshal.SizeOf(typeof(PointF))));
}
 
shapePoints[i] = (PointF)Marshal.PtrToStructure(shapePointsIthPtr, typeof(PointF));
}
}
 
return shapePoints;
}
FaceTrackLib.h
C++
1 2 3 4 5 6 7 8 9 10 11
/// <summary>
/// Represents a 2D vector with x,y elements
/// </summary>
struct FT_VECTOR2D
{
#ifdef __cplusplus
FT_VECTOR2D(FLOAT xParam = 0, FLOAT yParam = 0) : x(xParam), y(yParam) {}
#endif
FLOAT x;
FLOAT y;
};
FtInterop.cs
C#
1 2
// STDMETHOD(Get2DShapePoints)(THIS_ FT_VECTOR2D** ppPoints, UINT* pPointCount) PURE;
void Get2DShapePoints(out IntPtr pointsPtr, out uint pointCount);
Utils.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
/// <summary>
/// Represents a point in 2D space with floating point x & y co-ordinates
/// </summary>
[DebuggerDisplay("({x},{y})")]
[StructLayout(LayoutKind.Sequential)]
public struct PointF
{
private readonly float x;
private readonly float y;
 
public PointF(float x, float y)
{
this.x = x;
this.y = y;
}
 
/// <summary>
/// Gets an point with 0,0 co-ordinates
/// </summary>
public static PointF Empty
{
get { return new PointF(0, 0); }
}
 
/// <summary>
/// Returns X co-ordinate
/// </summary>
public float X
{
get { return x; }
}
 
/// <summary>
/// Returns Y co-ordinate
/// </summary>
public float Y
{
get { return y; }
}
 
public static bool operator ==(PointF point1, PointF point2)
{
return point1.Equals(point2);
}
 
public static bool operator !=(PointF point1, PointF point2)
{
return !point1.Equals(point2);
}
 
public override int GetHashCode()
{
return x.GetHashCode() ^ y.GetHashCode();
}
 
public override bool Equals(object obj)
{
if (!(obj is PointF))
{
return false;
}
 
return Equals((PointF)obj);
}
 
public bool Equals(PointF other)
{
if (x != other.x)
{
return false;
}
 
return y == other.y;
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.