Ejemplo n.º 1
0
    /// <summary>
    /// Gets the face-only texture from the given texture.
    /// </summary>
    /// <returns>The face texture.</returns>
    /// <param name="tex">The camera shot texture</param>
    /// <param name="face">The detected face</param>
    public static Texture2D GetFaceTexture(Texture2D tex, ref Face face)
    {
        if (tex != null && face != null)
        {
            FaceRectangle rect = face.faceRectangle;
            int           texY = tex.height - rect.top - rect.height;

            return(CloudTexTools.GetTexturePart(tex, rect.left, texY, rect.width, rect.height));
        }

        return(null);
    }
Ejemplo n.º 2
0
    // draw face rectangles
    /// <summary>
    /// Draws the face rectacgles in the given texture.
    /// </summary>
    /// <param name="faces">List of faces.</param>
    /// <param name="tex">The camera shot texture</param>
    public static void DrawFaceRects(Texture2D tex, Face[] faces, Color[] faceColors)
    {
        for (int i = 0; i < faces.Length; i++)
        {
            Face  face      = faces[i];
            Color faceColor = faceColors[i % faceColors.Length];

            FaceRectangle rect = face.faceRectangle;
            CloudTexTools.DrawRect(tex, rect.left, rect.top, rect.width, rect.height, faceColor);
        }

        tex.Apply();
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Gets the image as texture2d.
    /// </summary>
    /// <returns>The image.</returns>
    public Texture2D GetImage()
    {
        Texture2D snap = new Texture2D(webcamTex.width, webcamTex.height);

        if (webcamTex)
        {
            snap.SetPixels(webcamTex.GetPixels());
            snap.Apply();

            if (flipHorizontally)
            {
                snap = CloudTexTools.FlipTexture(snap);
            }
        }
        return(snap);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Gets webcam snapshot.
    /// </summary>
    public Texture2D GetSnapshot()
    {
        Texture2D snap = new Texture2D(webcamTex.width, webcamTex.height, TextureFormat.ARGB32, false);

        if (webcamTex)
        {
            snap.SetPixels(webcamTex.GetPixels());
            snap.Apply();

            if (flipHorizontally)
            {
                snap = CloudTexTools.FlipTexture(snap);
            }
        }

        return(snap);
    }
Ejemplo n.º 5
0
    // draw face rectangles
    /// <summary>
    /// Draws the face rectangles in the given texture.
    /// </summary>
    /// <param name="faces">List of faces.</param>
    /// <param name="tex">Tex.</param>
    /// <param name="faceColors">List of face colors for each face</param>
    /// <param name="drawHeadPoseArrow">If true, draws arrow according to head pose of each face</param>
    public void DrawFaceRects(Texture2D tex, Face[] faces, Color[] faceColors, bool drawHeadPoseArrow)
    {
        for (int i = 0; i < faces.Length; i++)
        {
            Face  face      = faces[i];
            Color faceColor = faceColors[i % faceColors.Length];

            FaceRectangle rect = face.faceRectangle;
            CloudTexTools.DrawRect(tex, rect.left, rect.top, rect.width, rect.height, faceColor);

            if (drawHeadPoseArrow)
            {
                HeadPose headPose = face.faceAttributes.headPose;

                int cx     = rect.width / 2;
                int cy     = rect.height / 4;
                int arrowX = rect.left + cx;
                int arrowY = rect.top + (3 * cy);
                int radius = Math.Min(cx, cy);

                float x = arrowX + radius * Mathf.Sin(headPose.yaw * Mathf.Deg2Rad);
                float y = arrowY + radius * Mathf.Cos(headPose.yaw * Mathf.Deg2Rad);

                int arrowHead = radius / 4;
                if (arrowHead > 15)
                {
                    arrowHead = 15;
                }
                if (arrowHead < 8)
                {
                    arrowHead = 8;
                }

                CloudTexTools.DrawArrow(tex, arrowX, arrowY, (int)x, (int)y, faceColor, arrowHead, 30);
            }
        }

        tex.Apply();
    }