Matlab实现霍夫变换_优化版

在上一篇博客中发现经过霍夫变换检测出的直线有可能因为车辆挡住路沿等原因断开,形成线段,这样就不好了,因为检测道路是要找直线焦点。

Thus it is necessary to combine 相同斜率的直线 and connect them.

本代码提供了matlab下求取经过霍夫变换的直线斜率,并将其联合,代码见下方,实验结果见文末。


% 入口图像为 BW,出口图像为f
%optimize from main_optimize, merely select 2 lines, one has positive
%slope,the other has negative slope
clear all,close all
BW=imread('D:\Images\NEW\img4b9faef664e03.jpg');
figure,imshow(BW);

BW=rgb2gray(BW);
%thresh=[0.01,0.17];
thresh=[0.01,0.10];
sigma=2;%定义高斯参数
f = edge(double(BW),'canny',thresh,sigma);
figure,subplot(121);
imshow(f,[]);
title('canny Edge Detect Result');

[H, theta, rho]= hough(f, 0.1);%cos(theta)*x+sin(theta)*y=rho
%imshow(theta,rho,H,[],'notruesize'),axis on,axis normal
%xlabel('\theta'),ylabel('rho');

[r,c]=houghpeaks(H,10);
hold on


lines=houghlines(
  • 13
    点赞
  • 46
    收藏
    觉得还不错? 一键收藏
  • 37
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 37
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值