Perform angle recognition on the objects in the following images
6 ビュー (過去 30 日間)
古いコメントを表示
clc
clear
A = imread('shipai.jpg');
A = rgb2gray(A);
BW = A<128;
% find angle of dominant line
[H,T,R] = hough(BW);
P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
x = T(P(:,2)); y = R(P(:,1));
plot(x,y,'s','color','white');
lines = houghlines(BW,T,R,P,'FillGap',5,'MinLength',7);
imshow(A), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
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');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end
n = length(lines);
for i=1:n-1
k=(lines(i).theta-lines(i+1).theta);
if abs(k>=15)
jiaodu=k
return
end
end
That's the code I used originally. It has a good effect on the following image recognition


Then you can get that the angle of two of the lines is 90
But for the following pictures, we can't recognize straight lines very well

I can't recognize the boundary straight line very well. The main reason is that my camera is not very good and the fabric is a little reflective. Is there any better way to deal with it? Thank you
4 件のコメント
Image Analyst
2022 年 3 月 17 日
I've spent about a third or half my working career over the past 30 years working on fabric image analysis. There are many papers published on it. See this link:
採用された回答
Simon Chan
2022 年 3 月 17 日
編集済み: Simon Chan
2022 年 3 月 17 日
Do some filtering before searching for lines.
Need to increase the number of peaks to 20 for function houghpeaks otherwise it is not possible to detect the diagonal line.
clear; clc;
rawdata = imread('fabric.png');
A = rgb2gray(rawdata);
se = strel('square',3);
BW1 = imbothat(A,se); % Filtering
BW2 = bwareaopen(BW1>2,5); % Remove small objects
% find angle of dominant line
[H,T,R] = hough(BW2);
P = houghpeaks(H,20,'threshold',ceil(0.3*max(H(:)))); % Increase number of peaks = 20
x = T(P(:,2)); y = R(P(:,1));
plot(x,y,'s','color','white');
lines = houghlines(BW2,T,R,P,'FillGap',5,'MinLength',7);
imshow(A), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
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');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end
n = length(lines);
for i=1:n-1
k=(lines(i).theta-lines(i+1).theta);
if abs(k>=15)
jiaodu=k
return
end
end

4 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



