BrickPiExample.MainPage.MakePicture C# (CSharp) Method

MakePicture() private method

private MakePicture ( ) : System.Threading.Tasks.Task
return System.Threading.Tasks.Task
        private async Task MakePicture()
        {
            Title.Text = "Detecting...";
            StorageFile filePath = await TakePhoto();
            FaceRectangle[] faceRects = await UploadAndDetectFaces(filePath); 
            Title.Text = String.Format("Detection Finished. {0} face(s) detected", faceRects.Length);

            if (faceRects.Length > 0)
            {
                var maxRes = await USBCam.GetPictureRes();
                //move left if face too right and vice versa
                // need to have the rectangle centered, in a good proportion
                // proportion can be X% left and right of what is left
                // only use the first face detected
                int fWidth = faceRects[0].Width;
                int fLeft = faceRects[0].Left;
                int iWidth = (int)maxRes.Width;
                double percent = 0.20;
                int degreesperRotation = 4;

                if ((fLeft<(iWidth * percent)) && ((fLeft + fWidth) < iWidth * (1-percent)))
                { 
                    // 360° = 1 turn of motor = 90° real turn
                    // using a simple projection for the math
                    robot.TurnLeft(150, GetAngleToTurn(fLeft, iWidth, percent) * degreesperRotation);
                } else if (((fLeft + fWidth)>(iWidth * (1-percent))) && (fLeft>(iWidth*percent)))
                {
                    robot.TurnRight(150, GetAngleToTurn(iWidth - (fLeft + fWidth), iWidth, percent) * degreesperRotation);
                }
            }
        }