当前位置: 首页>>代码示例>>C#>>正文


C# Image.GetSubRect方法代码示例

本文整理汇总了C#中Image.GetSubRect方法的典型用法代码示例。如果您正苦于以下问题:C# Image.GetSubRect方法的具体用法?C# Image.GetSubRect怎么用?C# Image.GetSubRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Image的用法示例。


在下文中一共展示了Image.GetSubRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Detect

        public static void Detect(Image<Bgr, Byte> image, String faceFileName, List<Rectangle> recFaces, List<Image<Bgr, Byte>> imgFaces, out long detectionTime)
        {
            Stopwatch watch;

            {
                //Read the HaarCascade objects
                using (CascadeClassifier faceClassifier = new CascadeClassifier(faceFileName))
                {
                    watch = Stopwatch.StartNew();
                    using (Image<Gray, Byte> gray = image.Convert<Gray, Byte>()) //Convert it to Grayscale
                    {
                        //Normalizes brightness and increases contrast of the image
                        gray._EqualizeHist();

                        //Detect the faces  from the gray scale image and store the locations as rectangle
                        //The first dimensional is the channel
                        //The second dimension is the index of the rectangle in the specific channel
                        Rectangle[] facesDetected = faceClassifier.DetectMultiScale(
                           gray,
                           1.1,
                           10,
                           new Size(20, 20),
                           Size.Empty);
                        recFaces.AddRange(facesDetected);
                        //Now for each rectangle, get the sub face image from the coordinates and store it for display later
                        foreach (Rectangle rec in facesDetected)
                            imgFaces.Add(image.GetSubRect(rec));
                    }
                    watch.Stop();
                }
            }
            detectionTime = watch.ElapsedMilliseconds;
        }
开发者ID:RichardxLee,项目名称:RileeCapture,代码行数:33,代码来源:FaceDetection.cs

示例2: IsMouthDetected

        /// <summary>
        /// This method detect true if we found a mouth in the image
        /// NOTE: The idea is to transform this method in true, when the user is speaking (mouth open)
        /// </summary>
        /// <param name="face"></param>
        /// <returns></returns>
        public bool IsMouthDetected(Image<Gray, byte> face)
        {
            var detectRectangle = new Rectangle(0, face.Height * 2 / 3, face.Width, face.Height / 3);
            var whereMouthShouldBe = face.GetSubRect(detectRectangle);
            var mouths = Mouth.Detect(whereMouthShouldBe, 1.2, 10, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(5, 5));

            return mouths.Any();
        }
开发者ID:guozanhua,项目名称:KinectFaceRecognition,代码行数:14,代码来源:FaceDetectionRecognition.cs

示例3: Split

        public Image<Gray, byte>[] Split(Image<Gray, byte> src)
        {
            var dst = new Image<Gray, byte>[SplitCount];
            int width = src.Width / SplitCount;
            for (int i = 0; i < SplitCount; ++i) {
                var rect = new Rectangle(i * width, 0, width, src.Height);
                dst[i] = src.GetSubRect(rect);
            }

            return dst;
        }
开发者ID:pakerliu,项目名称:sharp-context,代码行数:11,代码来源:Average.cs

示例4: GoodFeaturesToTrack

        /// <summary>
        /// Searches the image for the good features to track. 
        /// <para>For each location a Hessian matrix is made and min eig-value is compared against threshold.</para>
        /// </summary>
        /// <param name="image">Image.</param>
        /// <param name="winSize">Window size.</param>
        /// <param name="minEigVal">Minimum eigen value.</param>
        /// <param name="minimalDistance">Minimum distance from two features.</param>
        /// <returns>List of locations that have eigen value larger than <paramref name="minEigVal"/>.</returns>
        public static List<Point> GoodFeaturesToTrack(this Image<Gray, float> image, int winSize = 10, float minEigVal = 0.3f, float minimalDistance = 3)
        {
            var strengthImg = new Image<Gray, float>(image.Size);

            var Dx = image.Sobel(1, 0, 3);
            var Dy = image.Sobel(0, 1, 3);

            var Dxx = Dx.Mul(Dx).MakeIntegral();
            var Dxy = Dx.Mul(Dy).MakeIntegral();
            var Dyy = Dy.Mul(Dy).MakeIntegral();

            var proc = new ParallelProcessor<bool, bool>(image.Size,
                                                         () => true,
                                                         (_, __, area) =>
                                                         {
                                                             Rectangle srcArea = new Rectangle
                                                             {
                                                                 X = 0,
                                                                 Y = area.Y,
                                                                 Width = image.Width,
                                                                 Height = area.Height + winSize
                                                             };
                                                             srcArea.Intersect(new Rectangle(new Point(), image.Size));

                                                             goodFeaturesToTrack(Dxx.GetSubRect(srcArea), Dxy.GetSubRect(srcArea), Dyy.GetSubRect(area),
                                                                                 winSize, minEigVal, strengthImg.GetSubRect(srcArea));
                                                         },
                                                         new ParallelOptions2D {  /*ForceSequential = true*/ },
                                                         winSize);

            proc.Process(true);

            var filteredStrengthImg = strengthImg.SupressNonMaxima();
            //var filteredStrengthImg = strengthImg;

            List<float> values;
            var locations = filteredStrengthImg.FindNonZero(out values);

            var sortedFeatures = locations.Zip(values, (f, s) => new { f, s })
                                          .OrderByDescending(x => x.s)
                                          .Select(x => x.f)
                                          .ToList();

            sortedFeatures = sortedFeatures.EnforceMinimalDistance(minimalDistance);

            return sortedFeatures;
        }
开发者ID:remingtonsteel,项目名称:accord-net-extensions,代码行数:56,代码来源:GoodFeaturesToTrack.cs

示例5: GetImage

        public Image<Bgra, byte> GetImage(string text)
        {
            var textCharacters = text.Select(l => _characters.First(c => c.Character == l)).ToList();

            var image = new Image<Bgra, byte>(
                1 + textCharacters.Sum(c => Math.Max(c.Width, c.Rectangle.Width)) + textCharacters.Sum(c => c.Offset.X),
                textCharacters.Max(c => c.Rectangle.Height) + textCharacters.Max(c => c.Offset.Y),
                new Bgra(228, 227, 201, 255));

            int x = 1;
            foreach (var character in textCharacters)
            {
                if (character.Character == ' ')
                {
                    x += character.Width;
                    continue;
                }

                var targetRect = new Rectangle(
                    x - character.Offset.X,
                    character.Offset.Y,
                    character.Rectangle.Width,
                    character.Rectangle.Height);

                var mask = Bitmap.Copy(character.Rectangle).Convert<Gray, byte>();
                var characterImage = new Image<Bgra, byte>(mask.Width, mask.Height);
                for (int cy = 0; cy < characterImage.Height; cy++)
                {
                    for (int cx = 0; cx < characterImage.Width; cx++)
                    {
                        var alpha = mask[cy, cx].Intensity / 253;
                        characterImage[cy, cx] = new Bgra(
                            101 * alpha + (228 * (1 - alpha)),
                            32 * alpha + (227 * (1 - alpha)),
                            21 * alpha + (201 * (1 - alpha)),
                            255);
                    }
                }

                characterImage.CopyTo(image.GetSubRect(targetRect));

                x += character.Width;
            }

            return image;
        }
开发者ID:jasongdove,项目名称:wwhomper,代码行数:46,代码来源:BitmapFont.cs

示例6: IfAnyChanges

        public static bool IfAnyChanges(SaperCell[,] table, Rectangle rect, int y, int x)
        {
            //получает текущую диспозицию, исходя из окна
            var gameBmp = Form1.GetScreenImage(rect);
            Image<Bgr, Byte> img = new Image<Bgr, byte>(gameBmp);

            InitiateCellsWin7();

            var cell = img.GetSubRect(new Rectangle(FIRST_WINDOW_X7 + x * (WINDOW_WIDTH7 + WINDOW_DIST7),
                            FIRST_WINDOW_Y7 + y * (WINDOW_WIDTH7 + WINDOW_DIST7), WINDOW_WIDTH7, WINDOW_HEIGHT7));
            int value = CellRecognitionWin7(cell);

            if (table[y, x].value != value)
                return true;

            return false;
        }
开发者ID:JohnyWaster,项目名称:SaperBot,代码行数:17,代码来源:SaperImageDetectionWindows7.cs

示例7: IfGameOverWin7

 public static bool IfGameOverWin7(Image<Bgr, Byte> image)
 {
     int sum = 0;
     for (int i = 2; i < 12; ++i)
         for (int j = 4; j < 25; ++j)
         {
             var cell = image.GetSubRect(new Rectangle(FIRST_WINDOW_X7 + j * (WINDOW_WIDTH7 + WINDOW_DIST7),
                    FIRST_WINDOW_Y7 + i * (WINDOW_WIDTH7 + WINDOW_DIST7), WINDOW_WIDTH7, WINDOW_HEIGHT7));
             if (CellRecognitionWin7(cell) != -1)
             {
                 sum++;
             }
         }
     if (sum < 100)
     {
         return true;
     }
     return false;
 }
开发者ID:JohnyWaster,项目名称:SaperBot,代码行数:19,代码来源:SaperImageDetectionWindows7.cs

示例8: CreateImage

        public Image<Bgr, Byte> CreateImage(int[] radii, Bitmap shipsFile)
        {
            if (radii.Count() != 8)
                throw new ArgumentException();
            ;
            var source = new Image<Bgr, Byte>(shipsFile);

            int tileHeight = source.Height / (8 * 4); // 8 ships, 4 rows per ship
            int tileWidth = source.Width / 10; // 10 angles per row

            int max_radius = radii.Max()+1;

            var target = new Image<Bgr, Byte>(2*max_radius * 10, 2*max_radius * 8 * 4, new Bgr(Color.Black));

            for (int row_idx = 0; row_idx < 8 * 4; row_idx++)
            {
                int shipIndex = row_idx / 4;
                for (int col_idx = 0; col_idx < 10; col_idx++)
                {
                   Image<Bgr, Byte> subImage = source.GetSubRect(new Rectangle(new Point(col_idx * tileWidth, row_idx * tileHeight), new Size(tileWidth, tileHeight)));

                   target.ROI = new Rectangle(new Point(col_idx * (2 * max_radius) + (max_radius - tileWidth / 2), row_idx * (2 * max_radius) + (max_radius - tileHeight / 2)), new Size(subImage.Width, subImage.Height));

                   target.AddWeighted(subImage, 0, 1, 0).Copy(target, new Image<Gray, Byte>(target.Width, target.Height, new Gray(1)));

                   target.ROI = new Rectangle(new Point(col_idx * (2 * max_radius), row_idx * (2 * max_radius)), new Size(2*max_radius, 2*max_radius));

                   target.Draw(new Rectangle(new Point(max_radius - radii[shipIndex], max_radius - radii[shipIndex]), new Size(radii[shipIndex]*2, radii[shipIndex]*2)), new Bgr(Color.White), 1);

                   target.ROI = Rectangle.Empty;

                }

            }

            return target;
        }
开发者ID:HGuillen217,项目名称:ProxSquares,代码行数:37,代码来源:Program.cs

示例9: CropImage

        /// <summary>
        /// crops image to wanted size
        /// </summary>
        /// <param name="src">
        /// image that will be croped
        /// </param>
        /// <param name="x">
        /// The starting X location
        /// </param>
        /// <param name="y">
        /// Starting Y location
        /// </param>
        /// <param name="width">
        /// How wide we want to crop from origin that we set
        /// </param>
        /// <param name="height">
        /// How high we want to crop from origin that we set
        /// </param>
        /// <returns>
        /// returns croped image
        /// </returns>
        protected Image<Bgr, Byte> CropImage(Image<Bgr, Byte> src, int x, int y, int width, int height)
        {
            Rectangle rect = new Rectangle();

            rect.X = x;
            rect.Y = y;
            rect.Width = width;
            rect.Height = height;
            if (x < 0)
            {
                rect.X = 0;
            }
            else if (x > src.Cols)
            {
                rect.X = src.Cols;
            }

            if (y < 0)
            {
                rect.Y = 0;
            }
            else if (y > src.Rows)
            {
                rect.Y = src.Rows;
            }

            if ((rect.X + width) > src.Cols)
            {
                rect.Width = src.Cols - rect.X;
            }

            if ((rect.Y + height) > src.Rows)
            {
                rect.Height = src.Rows - rect.Y;
            }

            return src.GetSubRect(rect).Clone();
        }
开发者ID:jack06215,项目名称:tmc,代码行数:59,代码来源:VisionBase.cs

示例10: ImageToMatrix

 //функция распознает картинку и заполняет поле сапера числами
 private void ImageToMatrix(Image<Bgr, Byte> image, int[,] tableOfNumbers)
 {
     for (int i = 0; i < 16; ++i)
         for (int j = 0; j < 30; ++j)
         {
             if(tableOfNumbers[i,j] == 9)
             {
                 var cell = image.GetSubRect(new Rectangle(FIRST_WINDOW_X7 + j * (WINDOW_WIDTH7 + WINDOW_DIST7),
                     FIRST_WINDOW_Y7 + i * (WINDOW_WIDTH7 + WINDOW_DIST7), WINDOW_WIDTH7, WINDOW_HEIGHT7));
                 saperField[i, j] = CellRecognitionWin7(cell);
             }
             else
             {
                 saperField[i, j] = tableOfNumbers[i, j];
             }
         }
 }
开发者ID:JohnyWaster,项目名称:SaperBot,代码行数:18,代码来源:SaperImageDetectionWindows7.cs

示例11: button10_Click


//.........这里部分代码省略.........
                            var.ROI = new Rectangle(j, i, size, size);
                            //Sets the region of interest of the image to the abpve by which the image is treated just as that rectangle and nothing else
                            Bitmap smallbox = var.ToBitmap();
                            Image<Bgr, float> ismallbox = new Image<Bgr, float>(smallbox);
                            channels = tochange.Split();

                            for (int k = 0; k < channels.Length; k++)
                            {
                                max = 0;
                                amin = 300;
                                for (int a = 0; a < ismallbox.Height; a++)
                                {
                                    for (int b = 0; b < ismallbox.Width; b++)
                                    {
                                        if ((int)ismallbox.Data[a, b, k] > max)
                                        {
                                            max = (int)ismallbox.Data[a, b, k];
                                        }
                                        if ((int)ismallbox.Data[a, b, k] < amin)
                                        {
                                            amin = (int)ismallbox.Data[a, b, k];
                                        }
                                    }
                                }
                                CvInvoke.cvNormalize(channels[k], channels[k], amin, max, Emgu.CV.CvEnum.NORM_TYPE.CV_MINMAX, IntPtr.Zero);

                            }
                            Image<Bgr, Byte> n = new Image<Bgr, byte>(channels);
                            resized = new Bitmap(n.Bitmap, size, size); //Resize file

                            var.ROI = roi;
                            {
                                Image<Bgr, Byte> temp = new Image<Bgr, byte>(resized);
                                temp.CopyTo(Mosaic.GetSubRect(new Rectangle(j, i, size, size)));

                            }

                        }

                   imageBox2.Image = Mosaic;
                    imageBox2.Show();

                }
            //Single nonmixed done.
                else
                {
                    progressBar2.Value = 0;
                    double min = 10000;
                    int index = 10000;

                    for (int i = 0; i < (grayvar.Height); i += size)
                        for (int j = 0; j < grayvar.Width; j += size)
                        {
                            Rectangle roi = var.ROI;
                            var.ROI = new Rectangle(j, i, size, size);
                            //Sets the region of interest of the image to the abpve by which the image is treated just as that rectangle and nothing else
                            Bitmap smallbox = var.ToBitmap();

                            double brightnesshere = avgBrightness(smallbox); //this is storing the avg brightness of the small grid
                            double sDev = standardDeviation(brightnesshere, smallbox);
                            Color here = getDominantColor(smallbox);
                            min = 100000;
                            progressBar2.Value++;

                            for (int k = 0; k < total - 2; k++)
                            {
开发者ID:jayasi,项目名称:photomosaic,代码行数:67,代码来源:Form1.cs

示例12: Update

        internal void Update(Image<Bgr, byte> image)
        {
            Image<Gray, byte> threshImage;
            bool pointObserved = false;

            // Try looking in local window
            if (Pos != Point.Empty)
            {
                int width = 120;
                int height = 60;
                int x = Math.Max(1, (int)Pos.X - (width / 2));
                int y = Math.Max(1, (int)Pos.Y - (height / 2));
                if (x +width > image.Width) width = image.Width - x-1;
                if (y + height > image.Height ) height = image.Height - y-1;

                if (x < 0 || x + width > image.Width || y < 0 || y + height > image.Height
                    || width < 1 || height < 1)
                {
                    goto notGoodSearch;
                }

                Image<Bgr, byte> searchWindow = image.GetSubRect(new Rectangle(x, y, width, height));
                threshImage = ImageProcess.ThresholdHsv(searchWindow, 14, 37, 150, 256, 98, 256);
                PointF searchPos = ImageProcess.GetCentreOfMass(threshImage.Erode(1).Dilate(1).Erode(1), 4);

                if (searchPos != Point.Empty)
                {
                    pointObserved = true;
                    Pos = new PointF(x + searchPos.X, y + searchPos.Y);
                }
            }

            notGoodSearch:

            if (Pos == Point.Empty || pointObserved == false) // If window fails to find point, then search the whole image
            {
                threshImage = ImageProcess.ThresholdHsv(image, 17, 34, 150, 256, 98, 256);
                PointF searchPos = ImageProcess.GetCentreOfMass(threshImage.Erode(2).Dilate(1).Erode(1), 6);
                if (searchPos != Point.Empty)
                {
                    pointObserved = true;
                    Pos = searchPos;
                }
            }

            Matrix<float> prediction = m_KalmanFilter.Predict();
            Matrix<float> measured = new Matrix<float>(new float[,] { { Pos.X }, { Pos.Y } });

            if (pointObserved)
            {
                Matrix<float> estimated = m_KalmanFilter.Correct(measured);
                Pos = new PointF(estimated[0, 0], estimated[1, 0]);
            }
            else
            {
                Pos = new PointF(prediction[0, 0], prediction[1, 0]);
            }

            if (Pos.X < 1) Pos.X = 1;
            if (Pos.Y < 1) Pos.Y = 1;
            if (Pos.X > 1279) Pos.X = 1279;
            if (Pos.Y > 719) Pos.Y = 719;
        }
开发者ID:JasonCrease,项目名称:Foosball,代码行数:63,代码来源:Ball.cs

示例13: ClassifyGem

        public Gem ClassifyGem(Image<Bgr, byte> gemSlotImage)
        {
            if(gemSlotImage.Bitmap.Width != 40 || gemSlotImage.Bitmap.Height != 40)
                throw new Exception("only 40x40 gem slots are accepted");
            Image<Bgr, byte> centerPart = gemSlotImage.GetSubRect(new Rectangle(10, 10, 20, 20));

            Bgr sum = centerPart.GetSum();
            int pixels = gemSlotImage.Bitmap.Width*gemSlotImage.Bitmap.Height;
            Bgr averageBgr = new Bgr(sum.Blue/pixels, sum.Green/pixels, sum.Red/pixels);

            double smallestDistance = double.MaxValue;
            GemColor color = GemColor.Unknown;

            double blueDistance = Distance(averageBgr, BlueGemBgr);
            if(blueDistance < smallestDistance)
            {
                smallestDistance = blueDistance;
                color = GemColor.Blue;
            }
            double greenDistance = Distance(averageBgr, GreenGemBgr);
            if(greenDistance < smallestDistance)
            {
                smallestDistance = greenDistance;
                color = GemColor.Green;
            }
            double orangeDistance = Distance(averageBgr, OrangeGemBgr);
            if(orangeDistance < smallestDistance)
            {
                smallestDistance = orangeDistance;
                color = GemColor.Orange;
            }
            double redDistance = Distance(averageBgr, RedGemBgr);
            if(redDistance < smallestDistance)
            {
                smallestDistance = redDistance;
                color = GemColor.Red;
            }
            double violetDistance = Distance(averageBgr, VioletGemBgr);
            if(violetDistance < smallestDistance)
            {
                smallestDistance = violetDistance;
                color = GemColor.Violet;
            }

            double whiteDistance = Distance(averageBgr, WhiteGemBgr);
            if(whiteDistance < smallestDistance)
            {
                smallestDistance = whiteDistance;
                color = GemColor.White;
            }

            double yellowDistance = Distance(averageBgr, YellowGemBgr);
            if(yellowDistance < smallestDistance)
            {
                smallestDistance = yellowDistance;
                color = GemColor.Yellow;
            }
            if (smallestDistance >= 20.0)
            {
                Debug.WriteLine("------");
                Debug.WriteLine("Average BGR:{0}", averageBgr);
                Debug.WriteLine("Distances");
                Debug.WriteLine("Blue:{0}", blueDistance);
                Debug.WriteLine("Green:{0}", greenDistance);
                Debug.WriteLine("Orange:{0}", orangeDistance);
                Debug.WriteLine("Red:{0}", redDistance);
                Debug.WriteLine("Violet:{0}", violetDistance);
                Debug.WriteLine("White:{0}", whiteDistance);
                Debug.WriteLine("Yellow:{0}", yellowDistance);
                return new Gem(GemColor.Unknown, GemType.Unknown);
            }
            return new Gem(color, GemType.Normal);
        }
开发者ID:doskir,项目名称:BejeweledBlitzBot,代码行数:73,代码来源:SimpleGemClassifier.cs

示例14: Main

        static void Main(string[] args)
        {
            String apiKey = "847e6315f892e21449da5f4077c5104f";
            String apiSecret = "BmskojfFyrZVQhkLfNSnRzX-lK8musO6";
            FaceService faceService = new FaceService(apiKey, apiSecret);

            string filePath = "D:\\Codes\\datasets\\face_morph\\bbt.jpg";
            DetectResult detectResult = faceService.Detection_DetectImg(filePath);

            Image<Bgr, Byte> srcImg = new Image<Bgr, Byte>(filePath);

            for(int cnt=0; cnt < detectResult.face.Count; cnt++)
            {
                string pointFileName = String.Format("D:\\Codes\\datasets\\face_morph\\result_bbt_face_{0}.txt", cnt);
                FileStream fileStream = new FileStream(pointFileName, FileMode.Create);
                StreamWriter streamWriter = new StreamWriter(fileStream);

                Rectangle faceRect = new Rectangle(
                    (int)(detectResult.face[cnt].position.center.x * srcImg.Width /100 - detectResult.face[cnt].position.width * srcImg.Width * 0.5 / 100),
                    (int)(detectResult.face[cnt].position.center.y * srcImg.Height / 100 - detectResult.face[cnt].position.height * srcImg.Height * 0.5 / 100),
                    (int)detectResult.face[cnt].position.width * srcImg.Width / 100,
                    (int)detectResult.face[cnt].position.height * srcImg.Height / 100);

                Image<Bgr, byte> faceImg = srcImg.GetSubRect(faceRect);

                string fileName = String.Format("D:\\Codes\\datasets\\face_morph\\result_bbt_face_{0}.jpg", cnt);
                faceImg.Save(fileName);

                IList<FaceppSDK.Point> featurePoints = new List<FaceppSDK.Point>();
                //featurePoints.Add(detectResult.face[cnt].position.center);
                FaceppSDK.Point tempPoint1 = new FaceppSDK.Point();
                tempPoint1.x = (detectResult.face[cnt].position.eye_left.x
                    - detectResult.face[cnt].position.center.x) / detectResult.face[cnt].position.width;
                tempPoint1.y = (detectResult.face[cnt].position.eye_left.y
                    - detectResult.face[cnt].position.center.y) / detectResult.face[cnt].position.height;
                featurePoints.Add(tempPoint1);

                FaceppSDK.Point tempPoint2 = new FaceppSDK.Point();
                tempPoint2.x = (detectResult.face[cnt].position.eye_right.x
                    - detectResult.face[cnt].position.center.x) / detectResult.face[cnt].position.width;
                tempPoint2.y = (detectResult.face[cnt].position.eye_right.y
                    - detectResult.face[cnt].position.center.y) / detectResult.face[cnt].position.height;
                featurePoints.Add(tempPoint2);

                FaceppSDK.Point tempPoint3 = new FaceppSDK.Point();
                tempPoint3.x = (detectResult.face[cnt].position.mouth_left.x
                    - detectResult.face[cnt].position.center.x) / detectResult.face[cnt].position.width;
                tempPoint3.y = (detectResult.face[cnt].position.mouth_left.y
                    - detectResult.face[cnt].position.center.y) / detectResult.face[cnt].position.height;
                featurePoints.Add(tempPoint3);

                FaceppSDK.Point tempPoint4 = new FaceppSDK.Point();
                tempPoint4.x = (detectResult.face[cnt].position.mouth_right.x
                    - detectResult.face[cnt].position.center.x) / detectResult.face[cnt].position.width;
                tempPoint4.y = (detectResult.face[cnt].position.mouth_right.y
                    - detectResult.face[cnt].position.center.y) / detectResult.face[cnt].position.height;
                featurePoints.Add(tempPoint4);

                FaceppSDK.Point tempPoint5 = new FaceppSDK.Point();
                tempPoint5.x = (detectResult.face[cnt].position.nose.x
                    - detectResult.face[cnt].position.center.x) / detectResult.face[cnt].position.width;
                tempPoint5.y = (detectResult.face[cnt].position.nose.y
                    - detectResult.face[cnt].position.center.y) / detectResult.face[cnt].position.height;
                featurePoints.Add(tempPoint5);

                foreach (FaceppSDK.Point featurePoint in featurePoints)
                {
                    streamWriter.WriteLine(featurePoint.x.ToString());
                    streamWriter.WriteLine(featurePoint.y.ToString());

                    System.Drawing.PointF point = new System.Drawing.PointF((float)featurePoint.x * srcImg.Width / 100,
                        (float)featurePoint.y * srcImg.Height / 100);
                    Cross2DF cross = new Cross2DF(point, (float)3.0, (float)3.0);
                    srcImg.Draw(cross, new Bgr(0, 255, 0), 3);
                }

                streamWriter.Flush();
                streamWriter.Close();
                fileStream.Close();
                //srcImg.Save("D:\\Codes\\datasets\\face_morph\\result_bbt.jpg");
            }
        }
开发者ID:TeamColdTea,项目名称:coldtea-algorithm,代码行数:82,代码来源:Program.cs

示例15: RemoveBackgroundColour


//.........这里部分代码省略.........
                }
            }

            cropY1 = count;

            // Bottom Y Crop
            for (int y = 0; y < (canvas.Height / 2); y++)
            {
                for (int x = 0; x < canvas.Width; x += 2)
                {
                    if (Colour.IsColourSimilar(canvas.GetPixel(x, canvas.Height - (y + 1)), BackgroundColour))
                    {
                        count = y;
                    }
                    else
                    {
                        breakLoop = true;
                        break;
                    }
                }

                if (breakLoop)
                {
                    breakLoop = false;
                    break;
                }
            }

            cropY2 = count;

            // Left X Crop
            for (int x = 0; x < (canvas.Width / 2); x++)
            {
                for (int y = 0; y < canvas.Height; y += 2)
                {
                    if (Colour.IsColourSimilar(canvas.GetPixel(x, y), BackgroundColour))
                    {
                        count = x;
                    }
                    else
                    {
                        breakLoop = true;
                        break;
                    }
                }

                if (breakLoop)
                {
                    breakLoop = false;
                    break;
                }
            }

            cropX1 = count;

            // Right X Crop
            for (int x = 0; x < (canvas.Width / 2); x++)
            {
                for (int y = 0; y < canvas.Height; y += 2)
                {
                    if (Colour.IsColourSimilar(canvas.GetPixel(canvas.Width - (x + 1), canvas.Height - (y + 1)), BackgroundColour))
                    {
                        count = x;
                    }
                    else
                    {
                        breakLoop = true;
                        break;
                    }
                }

                if (breakLoop)
                {
                    breakLoop = false;
                    break;
                }
            }

            cropX2 = count;

            Image<Bgr, Byte> newImage = new Image<Bgr, byte>(canvas);

            if (cropX1 > 0 || cropX2 < newImage.Width || cropY1 > 0 || cropY2 < newImage.Height)
            {
                if (cropX1 + cropX2 < newImage.Width && cropY1 + cropY2 < newImage.Height)
                {
                    int x, y, newWidth, newHeight;

                    x = cropX1;
                    y = cropY1;

                    newWidth = newImage.Width - cropX2 - cropX1;
                    newHeight = newImage.Height - cropY2 - cropY1;

                    newImage = newImage.GetSubRect(new Rectangle(x, y, newWidth, newHeight));
                }
            }

            return newImage;
        }
开发者ID:stankowalczyk,项目名称:composition,代码行数:101,代码来源:WidgetAnalyser.cs


注:本文中的Image.GetSubRect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。