예제 #1
0
        private static List <Face> MapResponse(ConvertedImage image, RecognizeCelebritiesResponse response)
        {
            var faces = new List <Face>();

            foreach (var celebrityFace in response.CelebrityFaces)
            {
                var face = new Face
                {
                    MatchConfidence = celebrityFace.MatchConfidence,
                    Name            = celebrityFace.Name,
                    FaceInfo        = new FaceInfo
                    {
                        Confidence   = celebrityFace.Face.Confidence,
                        ImageQuality = new Models.ImageQuality
                        {
                            Brightness = celebrityFace.Face.Quality.Brightness,
                            Sharpness  = celebrityFace.Face.Quality.Sharpness
                        },
                        Pose = new Models.Pose
                        {
                            Pitch = celebrityFace.Face.Pose.Pitch,
                            Roll  = celebrityFace.Face.Pose.Roll,
                            Yaw   = celebrityFace.Face.Pose.Yaw
                        },
                        BoundingBox = new Models.BoundingBox
                        {
                            Width  = Convert.ToInt32(celebrityFace.Face.BoundingBox.Width * image.Width),
                            Height = Convert.ToInt32(celebrityFace.Face.BoundingBox.Height * image.Height),
                            Left   = Convert.ToInt32(celebrityFace.Face.BoundingBox.Left * image.Width),
                            Top    = Convert.ToInt32(celebrityFace.Face.BoundingBox.Top * image.Height)
                        }
                    }
                };

                var landmarks = new List <Landmark>();

                foreach (var faceLandmark in celebrityFace.Face.Landmarks)
                {
                    Enum.TryParse(faceLandmark.Type.Value, true, out LandmarkType type);

                    var landmark = new Landmark
                    {
                        Type = type,
                        X    = faceLandmark.X * image.Width,
                        Y    = faceLandmark.Y * image.Height
                    };

                    landmarks.Add(landmark);
                }

                face.FaceInfo.Landmarks = landmarks;

                faces.Add(face);
            }

            return(faces);
        }
예제 #2
0
 protected override void OnClosing(CancelEventArgs e)
 {
     if (!isSave && ConvertedImage.Image != null)
     {
         if (MessageBox.Show("是否保存文件后再退出", "当前文件未保存", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             Bitmap Bit = PictureProcessing.GetBit(ConvertedImage.Size, ConvertedImage.PointToScreen(new Point(0, 0)));
             PictureProcessing.SaveFile(saveImageDialog.ShowDialog() == DialogResult.OK, saveImageDialog.FileName, Bit, out isSave);
         }
         else
         {
             isSave = true;
         }
     }
 }
예제 #3
0
        public void ExportarNcgrComOuSemNscr()
        {
            if (!Directory.Exists(ExportPath))
            {
                _ = Directory.CreateDirectory(ExportPath);
            }

            try
            {
                ConvertedImage.Save($"{ExportPath}{Path.GetFileName(NitroFilePath).Replace("ncgr", "png")}");
            }
            catch (Exception)
            {
                throw new Exception($"{NitroFilePath}");
            }
        }
        public ConvertedImage Convert(byte[] imageData)
        {
            var stream = new MemoryStream();
            var model  = new ConvertedImage();

            var image = Image.FromStream(imageData.ToMemoryStream());

            model.Width  = image.Width;
            model.Height = image.Height;

            image.Save(stream, ImageFormat.Png);

            model.ImageData = new byte[stream.Length];

            stream.Seek(0, SeekOrigin.Begin);
            stream.Read(model.ImageData, 0, model.ImageData.Length);
            stream.Dispose();

            return(model);
        }
예제 #5
0
        public ConvertedImage Convert(byte[] imageData)
        {
            var stream = new MemoryStream();
            var model  = new ConvertedImage();

            var magickImage = new MagickImage(imageData)
            {
                Format = MagickFormat.Png
            };

            model.Width  = magickImage.Width;
            model.Height = magickImage.Height;

            magickImage.Write(stream);

            model.ImageData = new byte[stream.Length];

            stream.Seek(0, SeekOrigin.Begin);
            stream.Read(model.ImageData, 0, model.ImageData.Length);
            stream.Dispose();

            return(model);
        }
예제 #6
0
 public static bool AreDimensionsOk(this ConvertedImage image)
 {
     return(image.Width >= 320 && image.Height >= 240);
 }
예제 #7
0
 public static bool IsSizeOk(this ConvertedImage image)
 {
     // 5 Mb
     return(image.ImageData.Length <= 5242880);
 }
예제 #8
0
        private void 另存为AToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Bitmap Bit = PictureProcessing.GetBit(ConvertedImage.Size, ConvertedImage.PointToScreen(new Point(0, 0)));

            PictureProcessing.SaveFile(saveImageDialog.ShowDialog() == DialogResult.OK, saveImageDialog.FileName, Bit, out isSave);
        }
        private void connected_area()
        {
            Bit = (Bitmap)ConvertedImage.Image.Clone();
            int capacity = Bit.Height * Bit.Width;

            queue_i = new Queue <int>(capacity);
            queue_j = new Queue <int>(capacity);

            countt  = new int[capacity];
            visited = new bool[Bit.Width + 5][];

            #region initialization of visited boolean array
            for (int i = 0; i < Bit.Width + 5; i++)
            {
                visited[i] = new bool[Bit.Height + 5];
                for (int j = 0; j < Bit.Height + 5; j++)
                {
                    visited[i][j] = false;
                }
            }
            #endregion
            big = new int[Bit.Width + 5][];

            #region initialization of count region array
            for (int i = 0; i < Bit.Width + 5; i++)
            {
                big[i] = new int[Bit.Height + 5];
                for (int j = 0; j < Bit.Height + 5; j++)
                {
                    big[i][j] = 0;
                }
            }
            #endregion

            int max = 0, max_bit = 0;
            count_region = 1;
            for (int i = 0; i < Bit.Width; i++)
            {
                for (int j = 0; j < Bit.Height; j++)
                {
                    if (!visited[i][j] && (Bit.GetPixel(i, j).R == 0 && Bit.GetPixel(i, j).G == 0 && Bit.GetPixel(i, j).B == 0))
                    {
                        countt[count_region] = 0;
                        //MessageBox.Show(i+" "+j+" ");
                        BFS(i, j);
                        if (max < countt[count_region])
                        {
                            max     = countt[count_region];
                            max_bit = count_region;
                            //MessageBox.Show(max+" ");
                        }
                        count_region++;
                    }
                }
            }


            Bitmap bmp = new Bitmap(ConvertedImage.Image.Width, ConvertedImage.Image.Height);

            int min_x = Bit.Width;
            int max_x = 0;
            int max_y = 0;
            int min_y = Bit.Height;

            //MessageBox.Show(max_bit.ToString());
            for (int i = 0; i < Bit.Width; i++)
            {
                for (int j = 0; j < Bit.Height; j++)
                {
                    if (big[i][j] == max_bit)
                    {
                        bmp.SetPixel(i, j, Bit.GetPixel(i, j));

                        #region calculating max min x and y of shorted image frame
                        if (min_x >= i)
                        {
                            min_x = i;
                        }
                        if (max_x < i)
                        {
                            max_x = i;
                        }
                        if (min_y >= j)
                        {
                            min_y = j;
                        }
                        if (max_y < j)
                        {
                            max_y = j;
                        }
                        #endregion
                    }
                    else
                    {
                        bmp.SetPixel(i, j, System.Drawing.Color.White);
                    }
                }
            }

            //pictureBox2.Image = (Image)bmp;
            //MessageBox.Show("d");
            //bmp = shape((Bitmap)bmp.Clone());
            //pictureBox2.Image = (Image)bmp;
            //pictureBox2.Invalidate();
            //MessageBox.Show("d");


            int    w, h, t;
            double a, p;
            int    flagforidentification = 0;

            if (max_x - min_x >= 30 && max_y - min_x >= 30)
            {
                min_x = min_x - 30;
                min_y = min_y - 30;
                max_x = max_x + 30;
                max_y = max_y + 30;
                flagforidentification = 1;
            }

            if (min_x < 0)
            {
                min_x = 0;
            }

            if (min_y < 0)
            {
                min_y = 0;
            }

            if (max_x > Bit.Width)
            {
                max_x = Bit.Width;
            }

            if (max_y > Bit.Height)
            {
                max_y = Bit.Height;
            }
            a = max_x - min_x;
            p = a * 0.12;
            t = Convert.ToInt16(p);
            if (flagforidentification == 1)
            {
                max_x -= t;
                min_x += t;
                min_y += t;
            }
            a = max_x - min_x;
            w = Convert.ToInt16(a);
            h = Convert.ToInt16(w * 1.5);
            // MessageBox.Show(w.ToString());

            if (h + min_y > max_y)
            {
                h = max_y - min_y;
            }


            Bitmap bbbb = new Bitmap(w, h);
            Bitmap pic1 = (Bitmap)InputImage.Image.Clone();
            ConvertedImage.Image = System.Drawing.Image.FromFile(file_name);
            Bitmap fre = (Bitmap)ConvertedImage.Image;
            for (int i = min_x; i < max_x; i++)
            {
                for (int j = min_y; j < min_y + h; j++)
                {
                    //if(bmp.GetPixel(i,j).B==0)
                    bbbb.SetPixel(i - min_x, j - min_y, fre.GetPixel(i, j));
                    ////// bbbb.SetPixel(i - min_x, j - min_y, pic1.GetPixel(i, j));
                    pic1.SetPixel(i, j, System.Drawing.Color.Black);
                    //else
                    //bbbb.SetPixel(i - min_x, j - min_y, Color.White);
                }
            }

            //bbbb = shape((Bitmap)bbbb.Clone());

            ConvertedImage.Image = (Bitmap)bbbb;
            ConvertedImage.Invalidate();
            InputImage.Image = (System.Drawing.Image)pic1;
            queue_i.Clear();
            queue_j.Clear();
        }
        private void skin_color_segmentation()
        {
            Bitmap bm  = (Bitmap)InputImage.Image;
            Bitmap bmp = new Bitmap(InputImage.Image.Width, InputImage.Image.Height);

            double tot_pixel = bm.Height * bm.Width;

            tot_pixel /= 100;
            tot_pixel *= 10;
            int min_x = bm.Width + 5;// Convert.ToInt16(tot_pixel);
            int max_x = 0;
            int max_y = 0;
            int min_y = bm.Height + 5;// Convert.ToInt16(tot_pixel);

            System.Drawing.Color color = new System.Drawing.Color();
            double g, r, avg = 0;
            double f_upper, f_lower, w;
            bool   R1, R3, R4, s;
            double c, cr, cb;

            R1       = R3 = R4 = s = false;
            cr_start = 140;
            cr_end   = 170;
            cb_start = 105;
            cb_end   = 150;

            for (int i = 0; i < bm.Width; i++)
            {
                for (int j = 0; j < bm.Height; j++)
                {
                    color = bm.GetPixel(i, j);
                    r     = Convert.ToDouble(color.R) / Convert.ToDouble(color.R + color.G + color.B);
                    g     = Convert.ToDouble(color.G) / Convert.ToDouble(color.R + color.G + color.B);

                    f_upper = -1.3767 * r * r + 1.0743 * r + 0.1452;
                    f_lower = -0.776 * r * r + 0.5601 * r + 0.1766;

                    if (g > f_lower && g < f_upper)
                    {
                        R1 = true;
                    }
                    else
                    {
                        R1 = false;
                    }

                    w = Math.Pow((r - 0.33), 2) + Math.Pow((g - 0.33), 2);
                    //avg += w;
                    //MessageBox.Show(w.ToString());
                    if (w <= 0.0004)
                    {
                        avg++;
                    }

                    if (color.R > color.G && color.G > color.B)
                    {
                        R3 = true;
                    }
                    else
                    {
                        R3 = false;
                    }

                    if ((color.R - color.G) >= 45)
                    {
                        R4 = true;
                    }
                    else
                    {
                        R4 = false;
                    }

                    if (R3 && R4)//&& R1 && !R2)//if(R1 && R2)//
                    {
                        s = true;
                    }
                    else
                    {
                        s = false;
                    }

                    c  = 0.257 * Convert.ToDouble(color.R) + 0.504 * color.G + 0.098 * color.B + 16;
                    cb = 0.148 * Convert.ToDouble(color.R) - 0.291 * Convert.ToDouble(color.G) + 0.439 * Convert.ToDouble(color.B) + 128;
                    cr = 0.439 * Convert.ToDouble(color.R) - 0.368 * Convert.ToDouble(color.G) - 0.071 * Convert.ToDouble(color.B) + 128;


                    if (s)
                    {
                        bmp.SetPixel(i, j, System.Drawing.Color.Black);
                        R1 = R3 = R4 = s = false;
                        #region finding face rectangle

                        /*
                         * finding the minimum co-ordinate and maximum co-ordinate xy
                         * of the image between the Cb and Cr threshold value region
                         */

                        if (i < bm.Width / 2 && i < min_x)
                        {
                            min_x = i;
                        }
                        if ((i >= bm.Width / 2 && i < bm.Width) && i > max_x)
                        {
                            max_x = i;
                        }

                        if (j < bm.Height / 2 && j < min_y)
                        {
                            min_y = j;
                        }
                        if ((j >= bm.Height / 2 && i < bm.Height) && j > max_y)
                        {
                            max_y = j;
                        }
                        #endregion
                    }
                    else
                    {
                        bmp.SetPixel(i, j, System.Drawing.Color.White);
                    }
                }
            }

            ConvertedImage.Image = (Bitmap)bmp;
            ConvertedImage.Invalidate();
            //MessageBox.Show("End");
        }