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


C# Image.InRange方法代码示例

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


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

示例1: InRange

 public Image<Gray, byte> InRange(Image<Bgr, byte> image)
 {
     return image.InRange((Bgr)Min, (Bgr)Max);
 }
开发者ID:GreenBlitz4590Programmers,项目名称:StrongHoldVision,代码行数:4,代码来源:ThreshData.cs

示例2: detectHair

        void detectHair(PersonFace personFace, Mat hairImage)
        {
            Rect faceRect = personFace.GetFace();

            double adjWidth = faceRect.width * 0.85;
            double adjHeight = faceRect.height * 1.2;
            double adjX = faceRect.x + (faceRect.width - adjWidth) / 2;
            double adjY = faceRect.y + (faceRect.height - adjHeight) / 2;

            Rect adjFaceRect = new Rect((int)adjX, (int)adjY, (int)adjWidth, (int)adjHeight);

            double[] faceLineData = personFace.GetFaceLineData();
            PointGenerator faceLine = new PointGenerator(faceLineData[0], faceLineData[1]);
            Point faceTopPoint = faceLine.GetFromY(adjFaceRect.y);
            Point faceBottomPoint = faceLine.GetFromY(adjFaceRect.y + adjFaceRect.height);

            //Draw face line
            //Imgproc.line(hairImage, faceTopPoint, faceBottomPoint, new Scalar(255, 0, 0), 2);

            //Get face feature angle
            double faceFeatureAngle = Math.Atan(faceLineData[0]);
            faceFeatureAngle = RadianToDegree(faceFeatureAngle);
            faceFeatureAngle += faceFeatureAngle > 0 ? -90 : 90;

            //Imgproc.rectangle(hairImage, adjFaceRect, new Scalar(0, 255, 255), 2);

            /*Imgproc.ellipse(hairImage,
                new Point(adjFaceRect.x + adjFaceRect.width / 2, adjFaceRect.y + adjFaceRect.height / 2),
                new Size(adjFaceRect.width/2, adjFaceRect.height/2), faceFeatureAngle, 0, 360, new Scalar(255, 0, 0), 2);

            Imgproc.ellipse(hairImage,
                new Point(adjFaceRect.x + adjFaceRect.width / 2, adjFaceRect.y + adjFaceRect.height / 2),
                new Size((int)(adjFaceRect.width / 1.8), (int)(adjFaceRect.height / 1.8)), faceFeatureAngle, 0, 360, new Scalar(255, 0, 0), 2);*/

            Mat[] imgComponents = hairImage.Split();

            for (int i = 0; i < 5; i++)
            {
                double factor = 1.8 - i * 0.2;

                Mat maskImage = new Image<Gray, byte>(hairImage.width(), hairImage.height(), new Gray(0)).Mat;

                Imgproc.ellipse(maskImage,
                    new Point(adjFaceRect.x + adjFaceRect.width / 2, adjFaceRect.y + adjFaceRect.height / 2),
                    new Size((int)(adjFaceRect.width / factor), (int)(adjFaceRect.height / factor)), faceFeatureAngle + 180, 0, 180, new Scalar(255), -1);

                Imgproc.ellipse(maskImage,
                    new Point(adjFaceRect.x + adjFaceRect.width / 2, adjFaceRect.y + adjFaceRect.height / 2),
                    new Size(adjFaceRect.width / 2, adjFaceRect.height / 2), faceFeatureAngle, 0, 360, new Scalar(0), -1);

                //imageBox13.Image = maskImage;

                Mat testImg = new Mat();

                hairImage.CopyTo(testImg, maskImage);

                imageBox13.Image = testImg;

                Stack<string> titleStack = new Stack<string>();
                titleStack.Push("Red");
                titleStack.Push("Green");
                titleStack.Push("Blue");

                HistogramForm histForm = new HistogramForm();

                foreach (Mat img in imgComponents)
                {
                    //try histogram only the upper half to detect the most probable hair color range

                    Mat hist = new Mat();
                    CvInvoke.CalcHist(new VectorOfMat(img), new int[] { 0 }, maskImage, hist, new int[] { 256 }, new float[] { 0, 255 }, false);

                    string color = titleStack.Pop();

                    histForm.AddHist(hist, color, System.Drawing.Color.FromName(color));

                    /*byte[] testBuffer = new byte[256];
                    hist.CopyTo(testBuffer);

                    string msg = "";

                    foreach (byte value in testBuffer)
                        msg += value + " ";

                    msg += Environment.NewLine;
                    msg += Environment.NewLine;

                    textBox1.AppendText(msg);*/

                }

                histForm.Show(i.ToString());

            }

            Image<Bgr, byte> testImg2 = new Image<Bgr, byte>(hairImage.Bitmap);

            imageBox13.Image = testImg2.InRange(new Bgr(25, 25, 25), new Bgr(100, 85, 100));

            //createHistogram(new Image<Bgr, byte>(maskImage.Bitmap), 256, "teste");
//.........这里部分代码省略.........
开发者ID:lucasolivier,项目名称:ImagineAlpha,代码行数:101,代码来源:Form1.cs


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