我想要檢測圖像中的彎曲傳送帶。我用下面的代碼中使用Hough變換來檢測其邊緣如何檢測matlab中的光滑曲線
%# 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
)。任何其他解決方案也是可喜的。
你能否給我們提供原始圖片? – Tapio
@Tapio我在帖子中添加了圖片。 – Ahmad
我不明白你想要檢測圖像中的曲線。您可以手動繪製圖像並突出顯示您想要查找的曲線嗎? – Shai