在一幅图像中自动检测直线并输出交点

本文介绍了如何使用计算机视觉技术检测图像中的直线,并通过Hough变换找到交点。首先进行图像预处理,然后应用Hough变换提取直线,最后计算两条最长线段的交点。Matlab代码详细展示了这一过程。
摘要由CSDN通过智能技术生成

在一幅图像中自动检测直线并输出交点

       特征提取是计算机视觉中的底层任务,在很多场合都有应用,如何检测图像中的直线呢,Hough变换很好用。

处理代码如下,包括3个主要步骤:

Step1. 图像预处理

Step2. Hough变换,提取峰值参数,绘出提取的直线

Step3. 求解两直线交点

 

Matlab代码如下:

% automatically detectthe intersection(cross) of two lines

% step 1. preprocessing:

% step 2. Hough transform

% step 3. computer thecross coordinate by two equations of the two lines

 

% Read the model images.

I1 = rgb2gray(imread('cutROI1.png'));

figure(1) imshow(I1);

 

% step1.  preprocessing the original image to binary image before doing Hough

% choose a proper edge operator, including 'sobel', 'prewitt', 'canny', 'roberts', it's problem-dependent

BW = edge(I1,'sobel');

 

% step 2. Basic Houghtransform

[H,T,R] = hough(BW);

figure(2)

imshow(H,[],'XData',T,'YData',R, 'InitialMagnification','fit');

xlabel('\theta')

ylabel('\rho')

axis on, axis normal, hold on;

 

% extract the peaks (rho,theta) of hough result

P = houghpeaks(H, 2, 'threshold',ceil(0.2*max(H(:))));

x = T(P(:,2))  %theta

y = R(P(:,1))  % rho

plot(x, y, 's', 'color', 'blue')

 

% extract the two lines in the searchedpeaks

% highlight the longestline segment overlapped in the input image

lines = houghlines(I1, T, R, P,'FillGap', 20, 'MinLength', 8);

figure(3)

imshow(I1), hold on

max_len = 0; count =0;

for k = 1:length(lines)

   xy &#

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值