public async Task <ActionResult> CheckImage()
        {
            if (System.Web.HttpContext.Current.Request.Files.AllKeys.Any())
            {
                var   pic   = System.Web.HttpContext.Current.Request.Files["Image"];
                Image image = Image.FromStream(pic.InputStream);

                using (var uploadedImage = HelperMethods.ProcessImage(new Bitmap(image)))
                {
                    FrameAnalysisJSON result = await FaceProcessor.ProcessFrame(new Bitmap(uploadedImage));

                    if (result == null || result.Faces.Count == 0)
                    {
                        return(Json(new { result = new List <CroppedFace>() }
                                    , JsonRequestBehavior.AllowGet));
                    }

                    List <CroppedFace> croppedFaces = new List <CroppedFace>();
                    foreach (var face in result.CroppedFaces(uploadedImage, 25))
                    {
                        croppedFaces.Add(face);
                    }
                    return(Json(new { result = croppedFaces }
                                , JsonRequestBehavior.AllowGet));
                }
            }
            return(null);
        }
        //this should probably return action result, otherwise nothing will happen in the frontend IIRC
        public async Task <ActionResult> CaptureSnapshot(string imgBase64, string latitude, string longitude)
        {
            FaceApiCalls apiCalls = new FaceApiCalls(new HttpClientWrapper());

            // Prepare base64 string
            imgBase64 = imgBase64.Substring(imgBase64.IndexOf("base64,", StringComparison.Ordinal) + 7);
            imgBase64 = imgBase64.Substring(0, imgBase64.LastIndexOf("\"", StringComparison.Ordinal));
            imgBase64 = imgBase64.Replace(" ", "+");

            // Create a bitmap
            byte[] bitmapData = Convert.FromBase64String(FixBase64ForImage(imgBase64));
            System.IO.MemoryStream streamBitmap = new System.IO.MemoryStream(bitmapData);
            Bitmap bitmap = new Bitmap((Bitmap)Image.FromStream(streamBitmap));

            bitmap = HelperMethods.ProcessImage(bitmap);
            // Analyze bitmap
            FrameAnalysisJSON analysisResult = await FaceProcessor.ProcessFrame(bitmap);

            if (analysisResult == null)
            {
                //error must've occured, should alert user.
                return(null);
            }

            if (analysisResult.Faces.Count == 0)
            {
                return(Json(new { result = "No faces have been found in the provided picture" }, JsonRequestBehavior.AllowGet));
            }

            var biggestConfidence = LikelinessConfidence.LowProbability;

            foreach (var face in analysisResult.Faces)
            {
                var searchResult = await apiCalls.SearchFaceInFaceset(face.Face_token);

                if (searchResult != null)
                {
                    foreach (var likelinessResult in searchResult.LikelinessConfidences()) //might want to set the camera properties to some value.
                    {
                        biggestConfidence = (likelinessResult.Confidence > biggestConfidence)
                            ? likelinessResult.Confidence
                            : biggestConfidence;

                        await SearchResultHandler.HandleOneResult(result : likelinessResult,
                                                                  minimumConfidence : LikelinessConfidence.VeryHighProbability,
                                                                  cameraProperties : new CameraProperties(Convert.ToDouble(latitude), Convert.ToDouble(longitude)));
                    }
                }
            }

            return
                (Json(new
                      { result =
                            string.Format("There's a {0} probability that the person/people from your picture are currently missing. Thank you for the submission, appropriate actions will be taken.",
                                          biggestConfidence.ToPrettyString()) }, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// Uploads the picture
        /// Author: Tomas Drasutis
        /// </summary>
        private async void uploadButton_Click(object sender, EventArgs e)
        {
            int    chosenImageIndex = 0;
            Bitmap uploadedImage    = ImageUpload.UploadImage();

            if (uploadedImage == null)
            {
                return;
            }
            else
            {
                uploadedImage = HelperMethods.ProcessImage(uploadedImage);
            }
            FrameAnalysisJSON result = await FaceProcessor.ProcessFrame((Bitmap)uploadedImage.Clone());

            missingPersonPictureBox.Image?.Dispose();
            missingPersonPictureBox.Image = null;
            if (result == null)
            {
                MessageBox.Show(Messages.errorWhileAnalysingImage);
                validImage = false;
                return;
            }
            switch (result.Faces.Count)
            {
            case 0:
                MessageBox.Show(Messages.noFacesInImage);
                validImage = false;
                uploadedImage.Dispose();
                return;

            case 1:
                break;

            default:
                var chooseFaceForm = new ChooseFaceFormcs(result.Faces, uploadedImage);
                chooseFaceForm.ShowDialog();
                if (chooseFaceForm.DialogResult == DialogResult.OK)
                {
                    chosenImageIndex = chooseFaceForm.SelectedFace;
                    chooseFaceForm.Dispose();
                }
                else
                {
                    return;
                }
                break;
            }
            validImage = true;
            missingPersonPictureBox.Image = HelperMethods.CropImage(uploadedImage, result.Faces[chosenImageIndex].Face_rectangle, 25);
            faceToken = result.Faces[chosenImageIndex].Face_token;
        }