/// <summary>
        /// Prints the card layout to the default printer
        /// </summary>
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            PrintLayout layout = new PrintLayout();

            double videoWidth  = CameraVideoDeviceControl.ActualWidth * WebcamDevice.thisDpiWidthFactor;
            double videoHeight = CameraVideoDeviceControl.ActualHeight * WebcamDevice.thisDpiHeightFactor;

            double imageWidth  = layout.ImageToPrint.Width;
            double imageHeight = layout.ImageToPrint.Height;

            double widthRatio  = videoWidth / imageWidth;
            double heightRatio = videoHeight / imageHeight;



            PrintDialog printDialog = new PrintDialog();

            // Set image and adjust to new size
            layout.ImageToPrint.Source = OutputImage.Source;

            // Add face markers
            if (RecognizedFaces != null && RecognizedFaces.Length > 0)
            {
                int index = 0;
                foreach (var face in RecognizedFaces)
                {
                    // Draw rectangles around faces
                    FaceMarker fm = new FaceMarker(face.Attributes.Age.ToString(), face.Attributes.Gender);
                    fm.Height = Math.Round(face.FaceRectangle.Height / heightRatio);
                    fm.Width  = Math.Round(face.FaceRectangle.Width / widthRatio);
                    layout.FaceCanvas.Children.Add(fm);
                    fm.HairlineColor = brushList[index];
                    Canvas.SetZIndex(fm, 1);
                    Canvas.SetTop(fm, Math.Round(face.FaceRectangle.Top / heightRatio));
                    Canvas.SetLeft(fm, Math.Round(face.FaceRectangle.Left / widthRatio));
                }
            }



            // Get printer settings and adjust to page size

            TransformGroup transGroup = new TransformGroup();

            layout.CardToPrint.LayoutTransform = transGroup;

            System.Printing.PrintCapabilities capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket);
            transGroup.Children.Add(new ScaleTransform(capabilities.PageImageableArea.ExtentWidth / layout.CardToPrint.Width,
                                                       capabilities.PageImageableArea.ExtentHeight / layout.CardToPrint.Height));

            layout.CardToPrint.LayoutTransform = transGroup;

            Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);

            layout.CardToPrint.Measure(sz);
            layout.CardToPrint.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

            // Print card layout
            printDialog.PrintVisual(layout.CardToPrint, "Results");
        }
        private void UpdateUIWithFaces(Face[] faces, double widthRatio, double heightRatio)
        {
            StringBuilder usersAgeBuilder = new StringBuilder();

            // Cleaning children from stack pannels
            for (int i = canvas.Children.Count - 1; i >= 0; i--)
            {
                UIElement child = canvas.Children[i];
                if (child.GetType() == typeof(MLMarketplaceDemo.FaceMarker))
                {
                    canvas.Children.Remove(child);
                }
            }

            //userInputPannel.Children.Clear();
            Ids.Children.Clear();

            if (faces != null)
            {
                int index = 0;
                foreach (var face in faces)
                {
                    //string age = face.Attributes.Age.ToString();
                    //FaceMarker  fm = new FaceMarker(age, face.Attributes.Gender);

                    FaceMarker fm = new FaceMarker(face as NamedFace);

                    fm.Height = Math.Round(face.FaceRectangle.Height / heightRatio);
                    fm.Width  = Math.Round(face.FaceRectangle.Width / widthRatio);
                    canvas.Children.Add(fm);
                    fm.HairlineColor = brushList[index];
                    Canvas.SetZIndex(fm, 1);
                    Canvas.SetTop(fm, Math.Round(face.FaceRectangle.Top / heightRatio));
                    Canvas.SetLeft(fm, Math.Round(face.FaceRectangle.Left / widthRatio));

                    /*  HumanIdentification identification = new HumanIdentification();
                     * identification.Age = face.Attributes.Age.ToString() + " years old";
                     * identification.Id = face.Attributes.Gender;
                     * identification.HairlineColor = brushList[index++];
                     * Ids.Children.Add(identification);*/
                }
            }
        }
        /// <summary>
        /// Prints the card layout to the default printer
        /// </summary>
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            PrintLayout layout = new PrintLayout();

            double videoWidth = CameraVideoDeviceControl.ActualWidth * WebcamDevice.thisDpiWidthFactor;
            double videoHeight = CameraVideoDeviceControl.ActualHeight * WebcamDevice.thisDpiHeightFactor;

            double imageWidth = layout.ImageToPrint.Width;
            double imageHeight = layout.ImageToPrint.Height;

            double widthRatio = videoWidth / imageWidth;
            double heightRatio = videoHeight / imageHeight;



            PrintDialog printDialog = new PrintDialog();

            // Set image and adjust to new size
            layout.ImageToPrint.Source = OutputImage.Source;

            // Add face markers
            if (RecognizedFaces != null && RecognizedFaces.Length > 0)
            {

                int index = 0;
                foreach (var face in RecognizedFaces)
                {
                    // Draw rectangles around faces
                    FaceMarker fm = new FaceMarker(face.Attributes.Age.ToString(), face.Attributes.Gender);
                    fm.Height = Math.Round(face.FaceRectangle.Height / heightRatio);
                    fm.Width = Math.Round(face.FaceRectangle.Width / widthRatio);
                    layout.FaceCanvas.Children.Add(fm);
                    fm.HairlineColor = brushList[index];
                    Canvas.SetZIndex(fm, 1);
                    Canvas.SetTop(fm, Math.Round(face.FaceRectangle.Top / heightRatio));
                    Canvas.SetLeft(fm, Math.Round(face.FaceRectangle.Left / widthRatio));

                }
            }



            // Get printer settings and adjust to page size

            TransformGroup transGroup = new TransformGroup();
            layout.CardToPrint.LayoutTransform = transGroup;

            System.Printing.PrintCapabilities capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket);
            transGroup.Children.Add(new ScaleTransform(capabilities.PageImageableArea.ExtentWidth / layout.CardToPrint.Width,
                capabilities.PageImageableArea.ExtentHeight / layout.CardToPrint.Height));

            layout.CardToPrint.LayoutTransform = transGroup;

            Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
            layout.CardToPrint.Measure(sz);
            layout.CardToPrint.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

            // Print card layout
            printDialog.PrintVisual(layout.CardToPrint, "Results");

        }
        private void UpdateUIWithFaces(Face[] faces, double widthRatio, double heightRatio)
        {
            StringBuilder usersAgeBuilder = new StringBuilder();

            // Cleaning children from stack pannels
            for (int i = canvas.Children.Count - 1; i >= 0; i--)
            {
                UIElement child = canvas.Children[i];
                if (child.GetType() == typeof(MLMarketplaceDemo.FaceMarker))
                {
                    canvas.Children.Remove(child);
                }
            }

            //userInputPannel.Children.Clear();
            Ids.Children.Clear();

            if (faces != null)
            {
                int index = 0;
                foreach (var face in faces)
                {

                    //string age = face.Attributes.Age.ToString();
                    //FaceMarker  fm = new FaceMarker(age, face.Attributes.Gender);

                    FaceMarker fm = new FaceMarker(face as NamedFace);

                    fm.Height = Math.Round(face.FaceRectangle.Height / heightRatio);
                    fm.Width = Math.Round(face.FaceRectangle.Width / widthRatio);
                    canvas.Children.Add(fm);
                    fm.HairlineColor = brushList[index];
                    Canvas.SetZIndex(fm, 1);
                    Canvas.SetTop(fm, Math.Round(face.FaceRectangle.Top / heightRatio));
                    Canvas.SetLeft(fm, Math.Round(face.FaceRectangle.Left / widthRatio));

                    /*  HumanIdentification identification = new HumanIdentification();
                      identification.Age = face.Attributes.Age.ToString() + " years old";
                      identification.Id = face.Attributes.Gender;
                      identification.HairlineColor = brushList[index++];
                      Ids.Children.Add(identification);*/
                }
            }
        }