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


C# Mat.Line方法代码示例

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


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

示例1: SampleCpp

        /// <summary>
        /// sample of new C++ style wrapper
        /// </summary>
        private void SampleCpp()
        {
            // (1)画像の読み込み 
            using (Mat imgGray = new Mat(Const.ImageGoryokaku, LoadMode.GrayScale))
            using (Mat imgStd = new Mat(Const.ImageGoryokaku, LoadMode.Color))
            using (Mat imgProb = imgStd.Clone())
            {
                // ハフ変換のための前処理 
                CvCpp.Canny(imgGray, imgGray, 50, 200, ApertureSize.Size3, false);

                // (3)標準的ハフ変換による線の検出と検出した線の描画
                CvLineSegmentPolar[] segStd = CvCpp.HoughLines(imgGray, 1, Math.PI / 180, 50, 0, 0);
                int limit = Math.Min(segStd.Length, 10);
                for (int i = 0; i < limit; i++ )
                {
                    float rho = segStd[i].Rho;
                    float theta = segStd[i].Theta;

                    double a = Math.Cos(theta);
                    double b = Math.Sin(theta);
                    double x0 = a * rho;
                    double y0 = b * rho;
                    CvPoint pt1 = new CvPoint { X = Cv.Round(x0 + 1000 * (-b)), Y = Cv.Round(y0 + 1000 * (a)) };
                    CvPoint pt2 = new CvPoint { X = Cv.Round(x0 - 1000 * (-b)), Y = Cv.Round(y0 - 1000 * (a)) };
                    imgStd.Line(pt1, pt2, CvColor.Red, 3, LineType.AntiAlias, 0);
                }

                // (4)確率的ハフ変換による線分の検出と検出した線分の描画
                CvLineSegmentPoint[] segProb = CvCpp.HoughLinesP(imgGray, 1, Math.PI / 180, 50, 50, 10);
                foreach (CvLineSegmentPoint s in segProb)
                {
                    imgProb.Line(s.P1, s.P2, CvColor.Red, 3, LineType.AntiAlias, 0);
                }


                // (5)検出結果表示用のウィンドウを確保し表示する
                using (new CvWindow("Hough_line_standard", WindowMode.AutoSize, imgStd.ToIplImage()))
                using (new CvWindow("Hough_line_probabilistic", WindowMode.AutoSize, imgProb.ToIplImage()))
                {
                    CvWindow.WaitKey(0);
                }
            }
        }
开发者ID:neoxeo,项目名称:opencvsharp,代码行数:46,代码来源:HoughLines.cs

示例2: SampleCpp

        /// <summary>
        /// sample of new C++ style wrapper
        /// </summary>
        private void SampleCpp()
        {
            // (1) Load the image
            using (Mat imgGray = new Mat(FilePath.Image.Goryokaku, LoadMode.GrayScale))
            using (Mat imgStd = new Mat(FilePath.Image.Goryokaku, LoadMode.Color))
            using (Mat imgProb = imgStd.Clone())
            {
                // Preprocess
                Cv2.Canny(imgGray, imgGray, 50, 200, 3, false);

                // (3) Run Standard Hough Transform 
                CvLineSegmentPolar[] segStd = Cv2.HoughLines(imgGray, 1, Math.PI / 180, 50, 0, 0);
                int limit = Math.Min(segStd.Length, 10);
                for (int i = 0; i < limit; i++ )
                {
                    // Draws result lines
                    float rho = segStd[i].Rho;
                    float theta = segStd[i].Theta;
                    double a = Math.Cos(theta);
                    double b = Math.Sin(theta);
                    double x0 = a * rho;
                    double y0 = b * rho;
                    Point pt1 = new Point { X = Cv.Round(x0 + 1000 * (-b)), Y = Cv.Round(y0 + 1000 * (a)) };
                    Point pt2 = new Point { X = Cv.Round(x0 - 1000 * (-b)), Y = Cv.Round(y0 - 1000 * (a)) };
                    imgStd.Line(pt1, pt2, Scalar.Red, 3, LineType.AntiAlias, 0);
                }

                // (4) Run Probabilistic Hough Transform
                CvLineSegmentPoint[] segProb = Cv2.HoughLinesP(imgGray, 1, Math.PI / 180, 50, 50, 10);
                foreach (CvLineSegmentPoint s in segProb)
                {
                    imgProb.Line(s.P1, s.P2, CvColor.Red, 3, LineType.AntiAlias, 0);
                }

                // (5) Show results
                using (new Window("Hough_line_standard", WindowMode.AutoSize, imgStd))
                using (new Window("Hough_line_probabilistic", WindowMode.AutoSize, imgProb))
                {
                    CvWindow.WaitKey(0);
                }
            }
        }
开发者ID:0sv,项目名称:opencvsharp,代码行数:45,代码来源:HoughLinesSample.cs

示例3: ThresholdStairs

        public static Mat ThresholdStairs(this Mat src)
        {
            var dst = new Mat(src.Rows, src.Cols, src.Type());

            var partCount = 10;
            var partWidth = src.Width / partCount;

            for (var i = 0; i < partCount; ++i)
            {
                var th_mat = new Mat();
                Cv2.Threshold(src, th_mat, 255 / 10 * (i + 1), 255, ThresholdType.Binary);
                th_mat.Rectangle(new Rect(0, 0, partWidth * i, src.Height), new Scalar(0), -1);
                th_mat.Rectangle(new Rect(partWidth * (i + 1), 0, src.Width - partWidth * (i + 1), src.Height), new Scalar(0), -1);

                Cv2.Add(dst, th_mat, dst);
            }
            var color_dst = new Mat();
            Cv2.CvtColor(dst, color_dst, ColorConversion.GrayToRgb);
            for (var i = 0; i < partCount; ++i)
            {
                color_dst.Line(partWidth * i, 0, partWidth * i, src.Height, new CvScalar(50, 200, 50), thickness: 2);
            }
            return color_dst;
        }
开发者ID:DrReiz,项目名称:DrReiz.Robo-Gamer,代码行数:24,代码来源:Zuma.cs


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