我正在尝试使用C#和AForge hough变换线检测来检测线是否通过图像。在相同的上下文中,我正在考虑一个更好的解决方案,检测图像是否清晰(无线)然后返回假值,反之亦然。我有以下图像,我想检查线是否通过它,我将返回true,否则返回false:
http://s10.postimg.org/3sn8wari1/image.png
我使用以下代码来获取行数,但似乎它不准确或者我使用的算法非常糟糕。
AForge.Imaging.Image.FormatImage(ref SEChild);
// lock the source image
BitmapData sourceData = SEChild.LockBits(
new System.Drawing.Rectangle(0, 0, SEChild.Width, SEChild.Height),
ImageLockMode.ReadOnly, SEChild.PixelFormat);
// binarize the image
UnmanagedImage binarySource = filter.Apply(new UnmanagedImage(sourceData));
HoughLineTransformation lineTransform = new HoughLineTransformation();
lineTransform. = 10;
// apply Hough line transofrm
lineTransform.ProcessImage(binarySource);
HoughLine[] lines = lineTransform.GetLinesByRelativeIntensity(0.5);
if (lines.Count() > 0)
{
Result += "NW: Yes!\n";
}
else
{
Result += "NW: No!\n";
}
答案 0 :(得分:0)
我应用了一个强大的解决方案,所有曲线 除了 直线。
我使用了AForge.net库并使用了以下代码中显示的以下步骤:
守则:
private bool CheckLines(Bitmap image, Color filterColor)
{
EuclideanColorFiltering ColorFilter = new EuclideanColorFiltering();
// set center colour and radius
AForge.Imaging.RGB color = new RGB(filterColor.R, filterColor.G, filterColor.B, filterColor.A);
ColorFilter.CenterColor = color;
ColorFilter.Radius = 100;
// Apply the filter
ColorFilter.ApplyInPlace(image);
// Define the Blob counter and use it!
BlobCounter blobCounter = new BlobCounter();
blobCounter.MinWidth = 5;
blobCounter.MinHeight = 5;
blobCounter.FilterBlobs = true;
//blobCounter.ObjectsOrder = ObjectsOrder.Size;
blobCounter.ProcessImage(image);
System.Drawing.Rectangle[] rects = blobCounter.GetObjectsRectangles();
if (rects.Length > 0)
{
return true;
}
return false;
}