HoughLineTransformation lineTransform = new HoughLineTransformation();
lineTransform.ProcessImage(sourceImage);
Bitmap houghLineImage = lineTransform.ToBitmap();
HoughLine[] lines = lineTransform.GetLinesByRelativeIntensity(0.5);
foreach (HoughLine line in lines)
{
int r = line.Radius;
double t = line.Theta;
if (r < 0)
{
t += 180;
r = -r;
}
t = (t / 180) * Math.PI;
int w2 = image.Width / 2;
int h2 = image.Height / 2;
double x0 = 0, x1 = 0, y0 = 0, y1 = 0;
if (line.Theta != 0)
{
x0 = -w2;
x1 = w2;
y0 = (-Math.Cos(t) * x0 + r) / Math.Sin(t);
y1 = (-Math.Cos(t) * x1 + r) / Math.Sin(t);
}
else
{
x0 = line.Radius;
x1 = line.Radius;
y0 = h2;
y1 = -h2;
}
Drawing.Line(sourceData,
new IntPoint((int)x0 + w2, h2 - (int)y0),
new IntPoint((int)x1 + w2, h2 - (int)y1),
Color.Red);
}
Detected radius and theta values (color in corresponding colors):
답글삭제Theta = 90, R = 125, I = 249;
Theta = 0, R = -170, I = 187 (converts to Theta = 180, R = 170);
Theta = 90, R = -58, I = 163 (converts to Theta = 270, R = 58);
Theta = 101, R = -101, I = 130 (converts to Theta = 281, R = 101);
Theta = 0, R = 43, I = 112;
Theta = 45, R = 127, I = 82.