[英]Slope of a line using houghline transformation c# Aforge.Net
我使用了aforge.net库中的代码
HoughLineTransformation lineTransform = new HoughLineTransformation( );
// apply Hough line transofrm
lineTransform.ProcessImage( sourceImage );
Bitmap houghLineImage = lineTransform.ToBitmap( );
// get lines using relative intensity
HoughLine[] lines = lineTransform.GetLinesByRelativeIntensity( 0.5 );
foreach ( HoughLine line in lines )
{
// get line's radius and theta values
int r = line.Radius;
double t = line.Theta;
// check if line is in lower part of the image
if ( r < 0 )
{
t += 180;
r = -r;
}
// convert degrees to radians
t = ( t / 180 ) * Math.PI;
Console.WriteLine("{0},{1}",t,r)
// get image centers (all coordinate are measured relative
// to center)
int w2 = image.Width /2;
int h2 = image.Height / 2;
double x0 = 0, x1 = 0, y0 = 0, y1 = 0;
if ( line.Theta != 0 )
{
// none-vertical line
x0 = -w2; // most left point
x1 = w2; // most right point
// calculate corresponding y values
y0 = ( -Math.Cos( t ) * x0 + r ) / Math.Sin( t );
y1 = ( -Math.Cos( t ) * x1 + r ) / Math.Sin( t );
}
else
{
// vertical line
x0 = line.Radius;
x1 = line.Radius;
y0 = h2;
y1 = -h2;
}
// draw line on the image
Drawing.Line( sourceData,
new IntPoint( (int) x0 + w2, h2 - (int) y0 ),
new IntPoint( (int) x1 + w2, h2 - (int) y1 ),
Color.Red );
}
我为代码添加了Console.WriteLine(“ {0},{1}”,t,r),以显示线的斜率和半径。
在输出中,尽管图像具有不同的线斜率,但图像中所有线的斜率值为45或135度。 可能是什么原因? 请帮忙...
代码中没有编译错误。
我认为您忘记像Sobel一样应用边缘检测滤镜。 霍夫霍夫线使用每个非黑色像素来计算一条线。 如果您有较大的彩色区域,则将有许多斜度分别为45和135的线。
希望我理解你的问题是什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.