参考网址:
霍夫线变换原理_哔哩哔哩_bilibili
mars_mapping/occ_line_detector.cpp at master · Forrest-Z/mars_mapping (github.com)
(164条消息) 霍夫变换直线检测(Line Detection)原理及示例_leonardohaig的博客-CSDN博客_霍夫变换直线检测原理
原理
1 2
| 通过霍夫变换,得到霍夫空间下的(p, theta),对不同角度进行累加,若得到相近的p,则认为处于同一直线 ==> 霍夫变换: p = x*cos(theta) + y*sin(theta), 细分theta与p(这里一般指地图分辨率)
|
代码实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #pragma omp parallel for for(int i = 0;i < height;i++) { for(int j = 0;j < width;j++) { int index = j + i * width; if(i == 0 && j == 0) continue;
if(map_->data[index] >= 60) { double x_ = (double)j + 0.5; double y_ = (double)i + 0.5;
double phi = atan2(y_,x_); double R = sqrt(pow(x_,2) + pow(y_,2)) * resolution;
for(int k = 0;k < angle_size; k++) { double angle = (double)k * angle_resolution; double r = R*cos( angle/180.0*M_PI - phi); int theta_index = k; int r_index = (r-origin_r)/r_resolution; int hough_index = r_index*angle_size + theta_index; hough_map[hough_index]++; } } } }
|