How to calculate the inclination angle of whole box which their 4 vertices are stored in cell array with respect to the horizontal x-axis?

조회 수: 4 (최근 30일)
How to calculate the inclination angle of whole box which their 4 vertices are stored in cell array with respect to the horizontal x-axis?
There is cell with size 1*23 , In each part of cell there are four (x,y) coordinates stored (23 Bounding boxes coordinates )as the following:
c = {{[x1 , y1], [x2, y2], [x3 , y3 ], [x4 , y4 ]}, {[x1 , y1], [x2, y2], [x3 , y3 ], [x4 , y4 ]}, ........... }
The attached file is xy coordinates of the vertices of the boxes.
The coordinates are in the order:
(left-bottom), (right-bottom), (left-top), (right-top).where each coordinate is an (x, y) pair.. i.e([x1 , y1], [x2, y2], [x3 , y3 ], [x4 , y4 ])
  댓글 수: 2
Image Analyst
Image Analyst 2022년 5월 12일
Not sure all those brackets make sense. Can you attach your c in a .mat file?
If they came from regionprops why didn't you just do this:
props = regionprops(mask, 'BoundingBox');
allBB = vertcat(regionprops.BoundingBox); % Put into an N-by-4 matrix.

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

채택된 답변

Matt J
Matt J 2022년 5월 12일
편집: Matt J 2022년 5월 12일
boxes = cellfun(@(z) cell2mat(z(:)) ,c ,'UniformOutput' ,false)
boxes=cat(3,boxes{:});
rays=normalize( boxes(4,:,:)-boxes(3,:,:) ,2 ,'n');
angles= squeeze( acosd( rays(:,1,:) ) );
  댓글 수: 11
Matt J
Matt J 2022년 5월 13일
편집: Matt J 2022년 5월 13일
That's what the wiki page explains. The first element of the ray is the cosine of the angle with the x-axis.

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by