Пример #1
0
    private void ShowDetectInfo(JsonParse.BaiduFaceDectect de)
    {
        JsonParse.BaiduFaceDectect.Result.Face_list face = de.result.face_list[0];
        float leftEyeCenter_x = (float)face.landmark[0].x;
        //Debug.Log(leftEyeCenter_x);
        float leftEyeCenter_y = (float)face.landmark[0].y;
        float faceWidth       = (float)face.location.width;
        float faceHeight      = (float)face.location.height;
        float faceTop         = (float)face.location.top;
        float faceLeft        = (float)face.location.left;

        var x = leftEyeCenter_x + (faceWidth / 2);
        var y = leftEyeCenter_y + (faceHeight / 2);

        //Debug.Log(leftEyeCenter_y);
        cube.transform.localPosition = GetWorldPos(new Vector2(x, y), faceWidth, faceHeight, faceTop, faceLeft);

        Debug.Log(face.face_token);
        string genderMsg     = face.gender.type == "male" ? "男" : "女";
        string ageMsg        = face.age.ToString();
        string scoreMsg      = face.beauty.ToString();
        string expressionMsg = FaceDetector.Instance.GetExpressionStr(face.expression.type);
        string glassesMsg    = FaceDetector.Instance.GetGlassStr(face.glasses.type);
        string raceMsg       = FaceDetector.Instance.GetRaceStr(face.race.type);

        SetInfoText(genderMsg, ageMsg, scoreMsg, expressionMsg, glassesMsg, raceMsg);
    }
Пример #2
0
    /// <summary>
    /// 获取贴图
    /// </summary>
    IEnumerator GetTexture2d()
    {
        if (timingSprite.Length != 0)
        {
            for (int i = 0; i < timingSprite.Length; i++)
            {
                countDownImg.GetComponent <UnityEngine.UI.Image>().sprite = timingSprite[i];
                yield return(new WaitForSeconds(1));//倒计时
            }
        }

        yield return(new WaitForEndOfFrame());

        byte[] bytes = GetPhotoPixel(camTexture);
        //把图片数据转换为byte数组
        Texture2D texture = new Texture2D(camTexture.width, camTexture.height);

        texture.LoadImage(bytes);
        photo.texture = texture;

        //把图片数据转换为byte数组
        //photo.texture = GetPhotoTex(camTexture);
        //renderTexture = null;
        //Resources.UnloadUnusedAssets();
        //GC.Collect();



        if (isOpenAI && TcpManager.IsOnLine())//在线检测
        {
            result = AIManager.Instance.AIFaceDetect(bytes);
            //Debug.Log(result);
            if (AIManager.Instance.type == AIType.Tencent)
            {
                JsonParse.TencentFaceDetect de = JsonParse.TencentFaceDetect.ParseJsonFaceDetect(result);
                if (de.face != null && de.face.Length > 0)
                {
                    ShowDetectInfo(de);
                }
                AIManager.Instance.AIFaceMerge(bytes, photo);
            }
            else
            {
                JsonParse.BaiduFaceDectect de = JsonParse.BaiduFaceDectect.ParseJsonFaceDetect(result);
                if (de.result != null)
                {
                    ShowDetectInfo(de);
                }
                //FaceDetector.Instance.SignUpNewPerson(bytes);
            }
        }
        photo.gameObject.SetActive(true);
    }
Пример #3
0
    IEnumerator GetT()
    {
        yield return(new WaitForEndOfFrame());

        //byte[] bytes = File.ReadAllBytes(Application.streamingAssetsPath + "/" + "test1" + ".jpg");

        Texture2D texture = new Texture2D(camTexture.width, camTexture.height);

        Debug.Log(camTexture.width);
        Debug.Log(camTexture.height);
        byte[] bytes = GetPhotoPixel(camTexture);
        texture.LoadImage(bytes);
        photo.texture = texture;
        result        = AIManager.Instance.AIFaceDetect(bytes);
        JsonParse.BaiduFaceDectect de = JsonParse.BaiduFaceDectect.ParseJsonFaceDetect(result);
        if (de.result != null)
        {
            ShowDetectInfo(de);
        }
        photo.gameObject.SetActive(true);
    }
Пример #4
0
    private void ShowDetectInfo(JsonParse.BaiduFaceDectect de)
    {
        JsonParse.BaiduFaceDectect.Result.Face_list face = de.result.face_list[0];

        leftEyeCenter_x  = (float)face.landmark[0].x;
        leftEyeCenter_y  = (float)face.landmark[0].y;
        rightEyeCenter_x = (float)face.landmark[1].x;
        rightEyeCenter_y = (float)face.landmark[1].y;
        noseCenter_x     = (float)face.landmark[2].x;
        noseCenter_y     = (float)face.landmark[2].y;
        mouseCenter_x    = (float)face.landmark[3].x;
        mouseCenter_y    = (float)face.landmark[3].y;

        faceWidth  = (float)face.location.width;
        faceHeight = (float)face.location.height;

        var x = leftEyeCenter_x + (faceWidth / 2);
        var y = leftEyeCenter_y + (faceHeight / 2);

        var x1 = rightEyeCenter_x + (faceWidth / 2);
        var y1 = rightEyeCenter_y + (faceHeight / 2);

        var x2 = noseCenter_x + (faceWidth / 2);
        var y2 = noseCenter_y + (faceHeight / 2);

        var x3 = mouseCenter_x + (faceWidth / 2);
        var y3 = mouseCenter_y + (faceHeight / 2);

        //Debug.Log("x = " + x);
        //Debug.Log("y = " + y);
        //Debug.Log(leftEyeCenter_x);
        //Debug.Log(leftEyeCenter_y);
        cube1.transform.position = GetWorldPos(ref x, ref y);
        cube2.transform.position = GetWorldPos(ref x1, ref y1);
        cube3.transform.position = GetWorldPos(ref x2, ref y2);
        cube4.transform.position = GetWorldPos(ref x3, ref y3);
    }