Пример #1
0
    void Update()
    {
        if (CoreXT.IsDevice)
        {
            if (webCam.didUpdateThisFrame)
            {
                CGImageOrientation orientation = CGImageOrientation.RotatedLeft;
                switch (webCam.videoRotationAngle)
                {
                case 0:
                    orientation = CGImageOrientation.Default;
                    break;

                case 90:
                    orientation = CGImageOrientation.RotatedLeft;
                    break;

                case 180:
                    orientation = CGImageOrientation.UpsideDown;
                    break;

                case 270:
                    orientation = CGImageOrientation.RotatedRight;
                    break;
                }

                var ciimage = new CIImage(CGImage.FromWebCamTexture(webCam));
                faceDetector.ProjectedScale = Screen.width / webCam.width;
                faces = faceDetector.DetectInImage(ciimage, orientation);
//				foreach (var face in faces) {
//					Log("face: " + face.Bounds + ", " + face.HasMouthPosition + ", " + face.LeftEyePosition + ", " + face.RightEyePosition);
//				}

                if (faces.Length == 1)
                {
                    var face = faces[0];
                    if (face.Bounds.center.x < (Screen.width / 2))
                    {
                        GameObject.Find("Main Camera").GetComponent <Main>().rotateArmToLeft();
                    }
                    else
                    {
                        GameObject.Find("Main Camera").GetComponent <Main>().rotateArmToRight();
                    }



//					var newX = (face.Bounds.center.x / Screen.width) * diffX + minX;
//					var newZ = (face.Bounds.center.y / Screen.height) * diffY + minY;
//					var newY = (face.Bounds.width / diffFaceWidth) * diffFaceWidth + maxFaceWidth;
//					GameObject.Find("Main Camera").camera.transform.position = new Vector3(newX, newY, newZ);
//					GameObject.Find("Main Camera").GetComponent<Main>().Log("face: " + face.Bounds.center.x + ", " + face.Bounds.center.y + ", " + face.Bounds.width + ", " + face.Bounds.height
//						+ "; " + newX + ", " + newY + ", " + newZ);
                }
            }
        }
    }
Пример #2
0
    void Update()
    {
        if (CoreXT.IsDevice)
        {
            if (webCam.didUpdateThisFrame)
            {
                CGImageOrientation orientation = CGImageOrientation.RotatedLeft;
                switch (webCam.videoRotationAngle)
                {
                case 0:
                    orientation = CGImageOrientation.Default;
                    break;

                case 90:
                    orientation = CGImageOrientation.RotatedLeft;
                    break;

                case 180:
                    orientation = CGImageOrientation.UpsideDown;
                    break;

                case 270:
                    orientation = CGImageOrientation.RotatedRight;
                    break;
                }

                var ciimage = new CIImage(CGImage.FromWebCamTexture(webCam));
                faceDetector.ProjectedScale = Screen.width / webCam.width;
                faces = faceDetector.DetectInImage(ciimage, orientation);
                foreach (var face in faces)
                {
                    Log("face: " + face.Bounds + ", " + face.HasMouthPosition + ", " + face.LeftEyePosition + ", " + face.RightEyePosition);
                }
            }
        }
    }