Exemple #1
0
        public static ColorImage ColorFrameReady(ColorImageFrame colorFrame, GenderClassifier genderClassifier, Rectangle areaOfInterest)
        {
            ColorImage       img         = ImageTools.GetColorImage(colorFrame);
            List <Rectangle> facesResult = genderClassifier.GetFaces(img, areaOfInterest);

            if (facesResult.Count == 0)
            {
                return(img);
            }

            ImageTools.OrderRectanglesByArea(ref facesResult);

            ImageTools.RemoveInnerRectangles(ref facesResult);

            PredictionResult[] predictions;
            try {
                predictions = genderClassifier.ClassifyByFaces(img, areaOfInterest, facesResult.ToArray());
                ExcelRow.instance.ReceiveImpressionsPredictions(predictions);
            }
            catch {
                return(img);
                //Para cualquier error ignoramos el frame.
            }
            for (int i = 0; i < facesResult.Count; i++)
            {
                Bgr color = genderClassifier.ColorChooser(predictions[i]);
                img.Draw(facesResult[i], color, 2);
                img.Draw(predictions[i].Distance.ToString(), facesResult[i].Location, FontFace.HersheyDuplex, fontSize, color, fontThickness);
            }
            return(img);
        }
Exemple #2
0
        public static ColorImage ColorFrameReady(ColorImageFrame colorFrame, GenderClassifier genderClassifier, Rectangle areaOfInterest, KinectSensor sensor, Joint head)
        {
            ColorImage       img         = ImageTools.GetColorImage(colorFrame);
            List <Rectangle> facesResult = genderClassifier.GetFaces(img, areaOfInterest);
            Rectangle        playerFace  = genderClassifier.GetFaceByJoint(img, sensor, head);

            ImageTools.OrderRectanglesByArea(ref facesResult);

            for (int i = 0; i < facesResult.Count; i++)
            {
                if (playerFace.IntersectsWith(facesResult[i]) || playerFace.Contains(facesResult[i]))
                {
                    facesResult.RemoveAt(i);
                }
            }
            ImageTools.RemoveInnerRectangles(ref facesResult);

            PredictionResult[] predictions;
            PredictionResult   playerPrediction;

            try {
                predictions      = genderClassifier.ClassifyByFaces(img, areaOfInterest, facesResult.ToArray());
                playerPrediction = genderClassifier.PredictFace(img, playerFace);
                ExcelRow.instance.ReceiveImpressionsPredictions(predictions);
                ExcelRow.instance.ReceivePlayerPrediction(playerPrediction);
            }
            catch {
                return(null);
                //Para cualquier error ignoramos el frame.
            }
            Bgr color = genderClassifier.ColorChooser(playerPrediction);

            img.Draw(playerFace, color, 5);
            img.Draw(playerPrediction.Distance.ToString(), playerFace.Location, FontFace.HersheyDuplex, fontSize, color, fontThickness);
            for (int i = 0; i < facesResult.Count; i++)
            {
                color = genderClassifier.ColorChooser(predictions[i]);
                img.Draw(facesResult[i], color, 2);
                img.Draw(predictions[i].Distance.ToString(), facesResult[i].Location, FontFace.HersheyDuplex, fontSize, color, fontThickness);
            }
            return(img);
        }