我有如下图片
这里有一行。这条线不是到处都是直的。线的中间部分有一条曲线。我的工作是计算直线有多少或曲线有多少??? 我如何使用 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/