// TODO: NEW FUNCTION, DONT KNOW IF IT WORKS
        public Dictionary <int, Dictionary <string, object> > FindFacesWithBmp(Bitmap image)
        {
            Dictionary <int, Dictionary <string, object> > returningDic = FindFaces(image);

            foreach (KeyValuePair <int, Dictionary <string, object> > pair in returningDic)
            {
                FacePosition facePosition        = (FacePosition)pair.Value["position"];
                double[]     croppingCoordinates = new double[] { facePosition.Left, facePosition.Top, facePosition.Width, facePosition.Height };
                returningDic[pair.Key].Add("bitmap", scissors.Crop(image, croppingCoordinates));
            }
            return(returningDic);
        }
Ejemplo n.º 2
0
        public Bitmap pixelCensorship(Image image, int[] coordinates)
        {
            Bitmap bitmap = image.BitmapImage;

            double[] coordinatesDouble = new double[coordinates.Length];
            for (int i = 0; i < coordinates.Length; i++)
            {
                coordinatesDouble[i] = Convert.ToDouble(coordinates[i]);
            }
            Scissors scissors      = new Scissors();
            Resizer  resizer       = new Resizer();
            AddImage AI            = new AddImage();
            Bitmap   cropped       = scissors.Crop(bitmap, coordinatesDouble);
            Bitmap   ResizedSmall  = resizer.ResizeImage(cropped, 10, 10);
            Bitmap   ResizedNormal = resizer.ResizeImage(ResizedSmall, cropped.Width, cropped.Height);
            Bitmap   Final         = AI.InsertImage(bitmap, ResizedNormal, coordinates[0], coordinates[1], coordinates[2], coordinates[3]);

            return(Final);
        }
Ejemplo n.º 3
0
        public List <System.Drawing.Bitmap> FaceSearcher(string PersonName, List <Image> images)
        {
            List <Image> resultImages = Search(images, "Name: " + PersonName);                                           //Must search by the following format: "Matias", list of images where "Matias" appears in
            Dictionary <System.Drawing.Bitmap, double[]> imageDict = new Dictionary <System.Drawing.Bitmap, double[]>(); //Dictionary made out of Bitmap and coordinates

            foreach (Image image in resultImages)
            {
                List <PersonLabel> labels = image.SelectPersonLabels(); //List of PersonLabel of one image
                foreach (PersonLabel label in labels)                   //PersonLabel of labels
                {
                    if (label.Name == PersonName && label.FaceLocation != null)
                    {
                        double[] faceCoord             = label.FaceLocation;
                        System.Drawing.Bitmap bitImage = image.BitmapImage;
                        imageDict.Add(bitImage, faceCoord);
                    }
                }
            }
            return(scissors.Crop(imageDict));            //returns a List<System.Drawing.Bitmap>
        }
Ejemplo n.º 4
0
        public Bitmap Mosaic(Image image, List <Image> images, int width, int height, int BaseWidth, int BaseHeight, ProgressBar progressBar)
        {
            //Console.WriteLine("Loading images, please wait");
            //Converting loaded image into bitmap
            Resizer  resizer  = new Resizer();
            Bitmap   imageBit = image.BitmapImage;
            Bitmap   bmp      = (Bitmap)imageBit.Clone();
            Scissors scissors = new Scissors();

            bmp = resizer.ResizeImage(bmp, BaseWidth, BaseHeight);

            int bmpWidth  = bmp.Width / (bmp.Width / width);
            int bmpHeight = bmp.Height / (bmp.Height / height);
            //Console.WriteLine("Dividing Image");
            List <int[]> coords             = new List <int[]>();
            Dictionary <Bitmap, int[]> dict = new Dictionary <Bitmap, int[]>();

            for (int i = 0; i < (bmp.Width / width); i++)
            {
                for (int y = 0; y < (bmp.Height / height); y++)
                {
                    Graphics  gr = Graphics.FromImage(bmp);
                    Rectangle r  = new Rectangle(i * bmpWidth,
                                                 y * bmpHeight,
                                                 bmpWidth,
                                                 bmpHeight);
                    double[] coord    = { r.X, r.Y, r.Width, r.Height };
                    int[]    bitCoord = { (i * bmpWidth),
                                          (y * bmpHeight),
                                          (bmpWidth),
                                          (bmpHeight) };
                    dict.Add(scissors.Crop(bmp, coord), bitCoord);
                    coords.Add(bitCoord);
                }
            }
            List <Bitmap> list = new List <Bitmap>();

            foreach (KeyValuePair <Bitmap, int[]> keys in dict)
            {
                list.Add(keys.Key);
            }

            //Console.WriteLine("Getting Avg RGBS");
            List <int[]> rgbAVG = avgRGB(list);


            List <Bitmap> imagesList = new List <Bitmap>();

            foreach (Image imageInsert in images)
            {
                imagesList.Add(imageInsert.BitmapImage);
            }
            Bitmap           baseImage        = new Bitmap(bmp.Width, bmp.Height);
            int              AvgCont          = 0;
            int              max              = list.Count;
            ColorFilter      CF               = new ColorFilter();
            BackgroundWorker backgroundWorker = new BackgroundWorker();

            progressBar.Value   = 0;
            progressBar.Visible = true;
            progressBar.Maximum = max;
            progressBar.Step    = 1;
            while (true)
            {
                //double porcentage = ((double)AvgCont / (double)max);

                if (AvgCont < max)
                {
                    Color color = Color.FromArgb(rgbAVG[AvgCont][0], rgbAVG[AvgCont][1], rgbAVG[AvgCont][2]);
                    baseImage = InsertImage(baseImage, CF.ApplyFilter(Random(images), color)
                                            , coords[AvgCont][0], coords[AvgCont][1], coords[AvgCont][2], coords[AvgCont][3]);
                    //progressBar.Value=((AvgCont * 100) / max);
                    progressBar.PerformStep();
                }
                else
                {
                    progressBar.Visible = false;
                    progressBar.Value   = 0;
                    return(baseImage);
                }
                AvgCont++;
                GC.Collect();
            }
        }
Ejemplo n.º 5
0
        public List <Image> Search(List <Image> images, string searchDeclaration)
        {
            List <List <List <string> > > Declarations = Declaration(searchDeclaration);

            List <List <Image> > Total = new List <List <Image> >();
            List <Image>         Final = new List <Image>();

            foreach (List <List <string> > subDec in Declarations)
            {
                List <Image> temp = new List <Image>();
                foreach (Image image in images)
                {
                    int cont = 0;
                    foreach (List <string> atributes in subDec)
                    {
                        switch (atributes[0])
                        {
                        case "HairColor":
                            if (image.SomePersonLabelContains(atributes[0], null, ENationality.None, (EColor)Enum.Parse(typeof(EColor), atributes[1])))
                            {
                                cont++;
                            }
                            break;

                        case "EyesColor":
                            if (image.SomePersonLabelContains(atributes[0], null, ENationality.None, (EColor)Enum.Parse(typeof(EColor), atributes[1])))
                            {
                                cont++;
                            }
                            break;

                        case "Sex":
                            if (image.SomePersonLabelContains(atributes[0], null, ENationality.None, EColor.None, (ESex)Enum.Parse(typeof(ESex), atributes[1])))
                            {
                                cont++;
                            }
                            break;

                        case "Name":
                            if (image.SomePersonLabelContains(atributes[0], atributes[1]))
                            {
                                cont++;
                            }
                            break;

                        case "Face":

                            foreach (Label b in image.Labels)
                            {
                                if (b.labelType == "PersonLabel")
                                {
                                    PersonLabel plb = (PersonLabel)b;
                                    if (plb.FaceLocation != null && plb.Name == atributes[1])
                                    {
                                        // x, y, width, height
                                        double[] coord = { plb.FaceLocation[0], plb.FaceLocation[1], plb.FaceLocation[2], plb.FaceLocation[3] };
                                        System.Drawing.Bitmap BmapClone = (System.Drawing.Bitmap)image.BitmapImage.Clone();
                                        BmapClone = scissors.Crop(BmapClone, coord);
                                        Image faceImage = new Image(BmapClone, new List <Label>(), image.Calification);
                                        temp.Add(faceImage);
                                    }
                                }
                            }
                            break;

                        case "Surname":
                            //Console.WriteLine(atributes[1]);
                            if (image.SomePersonLabelContains(atributes[0], atributes[1]))
                            {
                                cont++;
                            }
                            break;

                        case "Birthdate":
                            if (image.SomePersonLabelContains(atributes[0], atributes[1]))
                            {
                                cont++;
                            }
                            break;

                        case "FaceLocation":
                            string[] subFACEstring = atributes[1].Split(new string[] { "," }, StringSplitOptions.None);
                            double[] faceCoords    = { Convert.ToDouble(subFACEstring[0]), Convert.ToDouble(subFACEstring[1]), Convert.ToDouble(subFACEstring[2]), Convert.ToDouble(subFACEstring[3]) };
                            if (image.SomePersonLabelContains(atributes[0], null, ENationality.None, EColor.None, ESex.None, faceCoords))
                            {
                                cont++;
                            }
                            break;

                        case "Nationality":
                            if (image.SomePersonLabelContains(atributes[0], null, (ENationality)Enum.Parse(typeof(ENationality), atributes[1])))
                            {
                                cont++;
                            }
                            break;

                        case "GeographicLocation":

                            string[] substring = atributes[1].Split(new string[] { "," }, StringSplitOptions.None);
                            double[] coords    = { Convert.ToDouble(substring[0]), Convert.ToDouble(substring[1]) };
                            if (image.SomeSpecialLabelContains(atributes[0], coords))
                            {
                                cont++;
                            }
                            break;

                        case "Address":
                            if (image.SomeSpecialLabelContains(atributes[0], null, atributes[1]))
                            {
                                cont++;
                            }
                            break;

                        case "Photographer":
                            if (image.SomeSpecialLabelContains(atributes[0], null, atributes[1]))
                            {
                                cont++;
                            }
                            break;

                        case "Photomotive":
                            if (image.SomeSpecialLabelContains(atributes[0], null, atributes[1]))
                            {
                                cont++;
                            }
                            break;

                        case "Selfie":
                            if (image.SomeSpecialLabelContains(atributes[0], null, null, Convert.ToBoolean(atributes[1])))
                            {
                                cont++;
                            }
                            break;

                        case "Sentence":
                            if (image.SomeSimpleLabelContains(atributes[0], atributes[1]))
                            {
                                cont++;
                            }
                            break;

                        case "ImageName":                                 //string
                            if (image.Name == atributes[1])
                            {
                                cont++;
                            }
                            break;

                        case "Calification":                                 // int
                            try
                            {
                                if (image.Calification == Convert.ToInt32(atributes[1]))
                                {
                                    cont++;
                                }
                            }
                            catch
                            {
                                Console.WriteLine("Calification => Parameter: {0} must be an integer", atributes[1]);
                            }
                            break;

                        case "Resolution":                                 // int[]
                            try
                            {
                                string[] resString  = atributes[1].Split(new string[] { "," }, StringSplitOptions.None);
                                int[]    resolution = { Convert.ToInt32(resString[0]), Convert.ToInt32(resString[1]) };
                                if (image.Resolution[0] == resolution[0] && image.Resolution[1] == resolution[1])
                                {
                                    cont++;
                                }
                            }
                            catch
                            {
                                Console.WriteLine("Resolution => Parameter: {0} must be an integer array", atributes[1]);
                            }
                            break;

                        case "AspectRatio":                                 // int[]
                            try
                            {
                                string[] aspectString = atributes[1].Split(new string[] { "," }, StringSplitOptions.None);
                                int[]    aspectRatio  = { Convert.ToInt32(aspectString[0]), Convert.ToInt32(aspectString[1]) };
                                if (image.Resolution[0] == aspectRatio[0] && image.Resolution[1] == aspectRatio[1])
                                {
                                    cont++;
                                }
                            }
                            catch
                            {
                                Console.WriteLine("AspectRatio => Parameter: {0} must be an integer array", atributes[1]);
                            }
                            break;

                        case "DarkClear":                                 // bool
                            try
                            {
                                if (image.DarkClear == Convert.ToBoolean(atributes[1]))
                                {
                                    cont++;
                                }
                            }
                            catch
                            {
                                Console.WriteLine("DarkClear => Parameter: {0} must be a boolean", atributes[1]);
                            }
                            break;

                        case "AutomaticAdjustment":
                            if (image.ApplyedFilters[EFilter.AutomaticAdjustment].ToString() == atributes[1])
                            {
                                cont++;
                            }
                            break;

                        case "Grayscale":
                            if (image.ApplyedFilters[EFilter.Grayscale].ToString() == atributes[1])
                            {
                                cont++;
                            }
                            break;

                        case "Brightness":
                            if (image.ApplyedFilters[EFilter.Brightness].ToString() == atributes[1])
                            {
                                cont++;
                            }
                            break;

                        case "Color":
                            if (image.ApplyedFilters[EFilter.Color].ToString() == atributes[1])
                            {
                                cont++;
                            }
                            break;

                        case "Invert":
                            if (image.ApplyedFilters[EFilter.Invert].ToString() == atributes[1])
                            {
                                cont++;
                            }
                            break;

                        case "Sepia":
                            if (image.ApplyedFilters[EFilter.Sepia].ToString() == atributes[1])
                            {
                                cont++;
                            }
                            break;

                        case "RotateFlip":
                            if (image.ApplyedFilters[EFilter.RotateFlip].ToString() == atributes[1])
                            {
                                cont++;
                            }
                            break;

                        case "Mirror":
                            if (image.ApplyedFilters[EFilter.Mirror].ToString() == atributes[1])
                            {
                                cont++;
                            }
                            break;

                        case "OldFilm":
                            if (image.ApplyedFilters[EFilter.OldFilm].ToString() == atributes[1])
                            {
                                cont++;
                            }
                            break;

                        case "Windows":
                            if (image.ApplyedFilters[EFilter.Windows].ToString() == atributes[1])
                            {
                                cont++;
                            }
                            break;

                        case "Contrast":
                            if (image.ApplyedFilters[EFilter.Contrast].ToString() == atributes[1])
                            {
                                cont++;
                            }
                            break;

                        case "Burned":
                            if (image.ApplyedFilters[EFilter.Burned].ToString() == atributes[1])
                            {
                                cont++;
                            }
                            break;
                        }
                    }
                    if (cont == subDec.Count) //Contador de parametros que calzan, es igual a la cantidad de parametros en subDec
                    {
                        temp.Add(image);
                    }
                }
                Total.Add(temp);
            }
            //Image Filter
            foreach (List <Image> subList  in Total)
            {
                foreach (Image tempImage in subList)
                {
                    if (!Final.Contains(tempImage))
                    {
                        Final.Add(tempImage);
                    }
                }
            }

            return(Final);
        }