Example #1
0
        // 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);
        }
        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);
        }
        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>
        }
Example #4
0
        public Bitmap Mosaic(Image image, List <Image> images, int width = 10, int height = 10)
        {
            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, 80 * width, 80 * height);

            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();

            while (true)
            {
                double porcentage = ((double)AvgCont / (double)max);
                BarraCarga("Creando Mosaico", porcentage);
                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]);
                }
                else
                {
                    return(baseImage);
                }
                AvgCont++;
                GC.Collect();
            }
        }