Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
0
        private async Task <StorageFile> TakePhoto()
        {
            StorageFile filestr = await USBCam.TakePhotoAsync("picture.jpg");

            Debug.WriteLine(string.Format("File name: {0}", filestr.Name));
            using (IRandomAccessStream myfileStream = await filestr.OpenAsync(FileAccessMode.Read))
            {
                WriteableBitmap bitmap = new WriteableBitmap(1, 1);

                await bitmap.SetSourceAsync(myfileStream);

                FacePhoto.Source = bitmap;
            }
            return(filestr);
        }
Exemplo n.º 3
0
        private async Task TestCam()
        {
            StorageFile filestr = await USBCam.TakePhotoAsync("maxime.jpg");

            Debug.WriteLine(string.Format("File name: {0}", filestr.Name));
        }