原标题:OpenCV标准霍夫直线检测详解
OpenCV学堂
星标或者置顶【OpenCV学堂】
精华文章与干货第一时间送达
霍夫直线检测
对于图像来说可以从笛卡尔坐标系统转换到霍夫空间,对于一条直线来说
在笛卡尔坐标系统中表示一条直线有两个参数斜率k与截距b
在霍夫空间中表示一条直线也有两个参数到原点的距离d与角度theta
对于给定任意theta值,都有一个r与之对应,对于点x0=8, y0=6,在霍夫空间有如下的曲线:
当有很多点在霍夫空间的曲线相交于一点时候
就说明这些点具有相同的theta与r,即它们都属于同一条直线,而参数theta与r就是该直线在霍夫空间的直线参数方程。
OpenCV中标准霍夫直线检测源码部分:
// stage 1. fill accumulator
for( i = 0; i < height; i++ )
for( j = 0; j < width; j++ )
{
if( image[i * step + j] != 0)
for( intn = 0; n < numangle; n++ )
{
intr = cvRound( j * tabCos[n] + i * tabSin[n] );
r += (numrho - 1) / 2;
accum[(n+ 1) * (numrho+ 2) + r+ 1]++;
}
}
// stage 2. find local maximums
findLocalMaximums( numrho, numangle, threshold, accum, _sort_buf );
<