我正在尝试检测图像中的弯曲传送带。我使用以下代码使用霍夫变换来检测其边缘
%# load image, and process it
I = imread('ggp\2.jpg');
g = rgb2gray(I);
bw = edge(g,'Canny');
[H,T,R] = hough(bw);
P = houghpeaks(H,500,'threshold',ceil(0.4*max(H(:))));
% I apply houghlines on the grayscale picture, otherwise it doesn't detect
% the straight lines shown in the picture
lines = houghlines(g,T,R,P,'FillGap',5,'MinLength',50);
figure, imshow(g), hold on
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
deltaY = xy(2,2) - xy(1,2);
deltaX = xy(2,1) - xy(1,1);
angle = atan2(deltaY, deltaX) * 180 / pi;
if (angle == 0)
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
end
end
如图所示,两条直线成功检测到传送带的顶部和底部边缘,但我不知道如何检测它是否弯曲(在图中它是弯曲的)以及如何计算弯曲的程度。
下图(红色)大致是手动绘制的曲线:
我在 matlab 中没有找到用于检测此类平滑曲线的霍夫变换的代码或函数(例如,二次多项式:y= a*x^2
)。也欢迎任何其他解决方案。
It's the original image: