private PointF[] GetProjected3DShape( CameraConfig videoCameraConfig, float zoomFactor, Point viewOffset, IntPtr shapeUnitCoeffPtr, uint shapeUnitCoeffCount, IntPtr animUnitCoeffPtr, uint animUnitCoeffCount, float scale, Vector3DF rotation, Vector3DF translation) { this.CheckPtrAndThrow(); PointF[] faceModelProjected3DShape = null; uint vertexCount = this.VertexCount; IntPtr faceModel3DVerticesPtr = IntPtr.Zero; if (shapeUnitCoeffPtr == IntPtr.Zero || shapeUnitCoeffCount == 0) { throw new ArgumentException("Invalid shape unit co-efficients", "shapeUnitCoeffPtr"); } if (animUnitCoeffPtr == IntPtr.Zero || animUnitCoeffCount == 0) { throw new ArgumentException("Invalid animation unit co-efficients", "animUnitCoeffPtr"); } if (vertexCount > 0) { try { faceModel3DVerticesPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Vector3DF)) * (int)vertexCount); this.faceTrackingModelPtr.GetProjectedShape( videoCameraConfig, zoomFactor, viewOffset, shapeUnitCoeffPtr, shapeUnitCoeffCount, animUnitCoeffPtr, animUnitCoeffCount, scale, ref rotation, ref translation, faceModel3DVerticesPtr, vertexCount); faceModelProjected3DShape = new PointF[vertexCount]; for (int i = 0; i < (int)vertexCount; i++) { IntPtr faceModel3DVerticesIthPtr; if (IntPtr.Size == 8) { // 64bit faceModel3DVerticesIthPtr = new IntPtr(faceModel3DVerticesPtr.ToInt64() + (i * Marshal.SizeOf(typeof(PointF)))); } else { // 32bit faceModel3DVerticesIthPtr = new IntPtr(faceModel3DVerticesPtr.ToInt32() + (i * Marshal.SizeOf(typeof(PointF)))); } faceModelProjected3DShape[i] = (PointF)Marshal.PtrToStructure(faceModel3DVerticesIthPtr, typeof(PointF)); } } finally { if (faceModel3DVerticesPtr != IntPtr.Zero) { Marshal.FreeHGlobal(faceModel3DVerticesPtr); } } } return faceModelProjected3DShape; }
private void UpdateMesh(FaceTrackFrame faceTrackingFrame) { //Console.Out.WriteLine(" ###################### In UpdateMesh ############################# "); bool faceInCentre = true; EnumIndexableCollection <FeaturePoint, Vector3DF> shapePoints = faceTrackingFrame.Get3DShape(); EnumIndexableCollection <FeaturePoint, PointF> projectedShapePoints = faceTrackingFrame.GetProjected3DShape(); if (this.triangleIndices == null) { // Update stuff that doesn't change from frame to frame this.triangleIndices = faceTrackingFrame.GetTriangles(); var indices = new Int32Collection(this.triangleIndices.Length * 3); foreach (FaceTriangle triangle in this.triangleIndices) { indices.Add(triangle.Third); indices.Add(triangle.Second); indices.Add(triangle.First); } this.theGeometry.TriangleIndices = indices; this.theGeometry.Normals = null; // Let WPF3D calculate these. this.theGeometry.Positions = new Point3DCollection(shapePoints.Count); this.theGeometry.TextureCoordinates = new PointCollection(projectedShapePoints.Count); for (int pointIndex = 0; pointIndex < shapePoints.Count; pointIndex++) { this.theGeometry.Positions.Add(new Point3D()); this.theGeometry.TextureCoordinates.Add(new Point()); } } // Update the 3D model's vertices and texture coordinates for (int pointIndex = 0; pointIndex < shapePoints.Count; pointIndex++) { Vector3DF point = shapePoints[pointIndex]; this.theGeometry.Positions[pointIndex] = new Point3D(point.X, point.Y, -point.Z); PointF projected = projectedShapePoints[pointIndex]; this.theGeometry.TextureCoordinates[pointIndex] = new Point( projected.X / (double)this.colorImageWritableBitmap.PixelWidth, projected.Y / (double)this.colorImageWritableBitmap.PixelHeight); // Console.Out.WriteLine("X = " + projected.X / (double)this.colorImageWritableBitmap.PixelWidth + "Y = " + projected.Y / (double)this.colorImageWritableBitmap.PixelHeight); if (projected.X / (double)this.colorImageWritableBitmap.PixelWidth > .6 || projected.Y / (double)this.colorImageWritableBitmap.PixelHeight > .75) { faceInCentre = false; } } if (faceInCentre) { // copyFaceImage(); FaceMesh tempMeshData = new FaceMesh(); tempMeshData.FaceViewport = viewport3d; FaceMeshData = tempMeshData; } }
public bool Equals(PointF other) { if (x != other.x) { return false; } return y == other.y; }
/// <summary> /// Translates between kinect and drawing points /// </summary> private System.Drawing.Point TranslatePoint(Microsoft.Kinect.Toolkit.FaceTracking.PointF point) { return(new System.Drawing.Point((int)point.X, (int)point.Y)); }