필터 지우기
필터 지우기

Perform angle recognition on the objects in the following images

조회 수: 1 (최근 30일)
tao wang
tao wang 2022년 3월 17일
댓글: tao wang 2022년 3월 17일
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
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:
tao wang
tao wang 2022년 3월 17일
Thank you very much. I will study hard

댓글을 달려면 로그인하십시오.

채택된 답변

Simon Chan
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
Simon Chan
Simon Chan 2022년 3월 17일
You may extend the line manually from the result in variable 'lines'.
tao wang
tao wang 2022년 3월 17일
Thank you. I used the parameter equation of two points to calculate the intersection with the picture, but it's more troublesome if the denominator is equal to 0. Thank you. I'll try again

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2022년 3월 17일
편집: Matt J 2022년 3월 17일
Perhaps as follows,
load Image
BW = edge(im2gray(A));
for i=1:5
E=bwmorph(BW,'endpoints');
BW=BW&~E;
end
BW=bwareaopen(BW,6);
imshow(BW)
T=regionprops('table',BW,'Orientation');
angle=mean(T.Orientation)
angle = -24.0316
histogram(T.Orientation)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by