【发布时间】:2015-11-10 16:58:58
【问题描述】:
我试图找到消失线的消失点来估计 2D 图像的深度图。
首先,我使用霍夫变换检测了 2D 图像的消失线。这是我在 Matlab 中的代码:
Img =imread('landscape.bmp'); %read the 2D image
%Convert the image to Grayscale
I=rgb2gray(Img);
%Edge Detection
Ie=edge(I,'sobel');
%Hough Transform
[H,theta,rho] = hough(Ie);
% Finding the Hough peaks (number of peaks is set to 5)
P = houghpeaks(H,5,'threshold',ceil(0.2*max(H(:))));
x = theta(P(:,2));
y = rho(P(:,1));
%Vanishing lines
lines = houghlines(I,theta,rho,P,'FillGap',170,'MinLength',350);
[rows, columns] = size(Ie);
figure, imshow(~Ie)
hold on
xy_1 = zeros([2,2]);
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
% Get the equation of the line
x1 = xy(1,1);
y1 = xy(1,2);
x2 = xy(2,1);
y2 = xy(2,2);
slope = (y2-y1)/(x2-x1);
xLeft = 1; % x is on the left edge
yLeft = slope * (xLeft - x1) + y1;
xRight = columns; % x is on the reight edge.
yRight = slope * (xRight - x1) + y1;
plot([xLeft, xRight], [yLeft, yRight], 'LineWidth',1,'Color','blue');
%intersection of two lines (the current line and the previous one)
slopee = @(line) (line(2,2) - line(1,2))/(line(2,1) - line(1,1));
m1 = slopee(xy_1);
m2 = slopee(xy);
intercept = @(line,m) line(1,2) - m*line(1,1);
b1 = intercept(xy_1,m1);
b2 = intercept(xy,m2);
xintersect = (b2-b1)/(m1-m2);
yintersect = m1*xintersect + b1;
plot(xintersect,yintersect,'m*','markersize',8, 'Color', 'red')
xy_1 = xy;
% Plot original points on the lines .
plot(xy(1,1),xy(1,2),'x','markersize',8,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','markersize',8,'Color','green');
end
现在我需要找到消失点才能估计深度图。 消失点被选为在其周围具有最多交叉点的交叉点。
换句话说,我的问题是如何在 Matlab 中找到多条线(消失线)的交点?我想一种方法是找到与所有线的距离平方和最小的点,但不确定如何在 Matlab 中做到这一点?
任何帮助将不胜感激。
编辑:我试图找到线的交点,但我只能找到每条线和它后面的线的交点。我不知道如何找到所有线的交点?
这是我正在使用的图片示例: https://www.dropbox.com/s/mbdt6v60ug1nymb/landscape.bmp?dl=0
我发布链接是因为我没有足够的声誉来发布图片。
【问题讨论】:
-
我也会尝试使用霍夫变换。根据图像的大小,使用 x 和 y 参数空间形成霍夫。您需要遍历每条线并找到它与另一条线相交的位置。然后增加离该位置最近的 bin。最后只找到票数最高的垃圾箱。如果您找到最小二乘点,它可能不像假设所有线都必须正确指向消失点那样稳健,我认为可能不会出现这种情况,因为可能存在一些不正确的线。
-
我试图找到线的交点,但我只能找到每条线和它之后的线的交点 我刚刚在问题中编辑了我的代码以显示我是怎么做的它。我不知道如何找到所有线的交点。你知道我该怎么做吗?
-
你可以添加你正在使用的图像吗?
标签: matlab image-processing vanishing-point