/*
function: detects a straight line by using the Hough transform
parameter description: imgbinaryin, indicating a binary image
width, indicates the image width
height, indicating the image height
houghbuf, indicating the buffer pointer required by the Hough Transformation
houghwidth,
houghheight indicates the width of the buffer required by the transformation.
radiusresolution indicates the height of the buffer required by the transformation.
angleresolution indicates the detection resolution of the polar radius of the transformation.
angleresolution, indicates the angle resolution of the Hough transformation.
radius indicates that the polar radius of the longest straight line detected by the Hough transformation is returned.
angle, returns the angle of the longest straight line detected by the Hough transformation.
*/
void imagealgorithm: houghtransform (unsigned char * imgbinaryin, int width, int height, int * houghbuf, int houghwidth, int houghheight, float radiusresolution, float angleresolution, float * radius, float * angle)
{< br> int I, J;
for (I = 0; I {< br> for (j = 0; j {< br> * (houghbuf + I * houghwidth + J) = 0;
}< BR >}
int R, A;
float tempr, Tempa;
// traverse image data
for (I = 0; I {< br> for (j = 0; j {< br> If (* (imgbinaryin + I * width + J) = 1)
{< br> // A indicates the circular variable of the angle,
for (a = 0; A {< br> // obtain the angle based on the resolution of the given angle of conversion
Tempa = (a-houghheight/2) * angleresolution;
// calculate the corresponding polar coordinate based on the angle of the current traversal and the X and Y values.
tempr = (J-width/2) * Cos (Tempa * 2 * PI/360) + (I-height/2) * sin (Tempa * 2 * PI/360);
r = tempr/radiusresolution;
// accumulate array
* (houghbuf + A * houghwidth + R + houghwidth/2) + = 1;
}< BR >}
// Calculate the maximum value of the accumulated array and record the array coordinates at this time
Int Max, maxr, maxa;
Max = * (houghbuf + 0 * houghwidth + 0 );
Maxr = 0;
Maxa = 0;
For (A = 0; A {
For (r = 0; r {
If (max <= * (houghbuf + A * houghwidth + r ))
{
Max = * (houghbuf + A * houghwidth + r );
Maxr = R;
Maxa =;
}
}
}
// Convert the maximum position to the polar radius and angle, and return the result through the Parameter
* Radius = (maxr-houghwidth/2) * radiusresolution;
* Angle = (maxa-houghheight/2) * angleresolution;
}