c# - 使用C#中的处理计算直线中有多少曲线进入图像

标签 c# image-processing

我有如下图片 enter image description here enter image description here

这里有一行。这条线不是到处都是直的。线的中间部分有一条曲线。我的工作是计算直线有多少或曲线有多少??? 我如何使用 C# 来做到这一点。我到处搜索,但不知道该怎么做。 有谁知道该怎么做? 我的目标不仅是检测一条线,还要计算这条线有多少曲线??

最佳答案

这只是使用 EmguCV 的示例包装在OpenCV检测线条的图像处理库。当然,这不是 100% 准确,您还需要稍微调整一下。当你得到这些线时,你可以计算出曲线。

或者另一种方法是实现您自己的算法来检测线条。

使用这个算法,我从提供的图像中得到了 16 行。通过一些调整,您可以获得更准确的数字。

var bmp = new Bitmap(pathToImage);

                //Load the image from file and resize it for display
        using (Image<Bgr, Byte> img = new Image<Bgr, byte>(bmp))
        {
            //Convert the image to grayscale and filter out the noise
            using (Image<Gray, Byte> gray = img.Convert<Gray, Byte>().PyrDown().PyrUp())
            {
                Gray cannyThreshold = new Gray(180);

                #region Canny and edge detection

                Gray cannyThresholdLinking = new Gray(120);
                Image<Gray, Byte> cannyEdges = gray.Canny(cannyThreshold, cannyThresholdLinking);
                LineSegment2D[] lines = cannyEdges.HoughLinesBinary(
                    1, //Distance resolution in pixel-related units
                    Math.PI/60.0, //Angle resolution measured in radians.
                    20, //threshold
                    30, //min Line width
                    10 //gap between lines
                    )[0]; //Get the lines from the first channel

                #endregion
            }
        }

关于c# - 使用C#中的处理计算直线中有多少曲线进入图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22266963/

相关文章:

image-processing - 使用 OpenCV 循环创建新图像

c# - 嵌套 for 循环 : giving concatenated result

c# - ElasticSearch NEST删除所有文件

c# - 桌面应用程序部署——尝试编写只读数据库 sqlite

image - 如何提取图像的特定区域

java - 如何确定图像 (java.awt.Image) 是否为黑白且没有颜色?

c - 消除 OpenCV 中包含在其他矩形内的矩形

c# - 具有泛型类型约束的泛型方法的尴尬语法

c# - 如何将 python 绑定(bind)添加到 C#?

delphi - 向 TBitmap 添加阴影