當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。