How can i draw a slanted rectangle in a frame?

조회 수: 3 (최근 30일)
Maayan
Maayan 2013년 9월 12일
I have a code that takes a video,split it into frames and then asks me how many rectangles would i like to draw on the frame (the first one). In those rectangles the mean intensity in each frame is calculated.I would like to be able to draw a slanted rectangles too.Is there any command that can help me?Here is the part of my code that is responsible for making the rectangles:
if k==1
result=input('How many rectangles would you like to draw? ');
pos=zeros(result,4);
for i=1:result
handle=imrect;
pos(i,:)=handle.getPosition;
end
end

채택된 답변

Image Analyst
Image Analyst 2013년 9월 12일
You could call the line() command 4 times to draw the sides of your slanted rectangle in the graphical overlay above the image. Alternatively, if the user needs to adjust the vertices, you can call impoly().
  댓글 수: 4
Maayan
Maayan 2013년 9월 15일
Yes i know that's the way to draw a rectangle,but i'm doing it by hand with the impoly() command. How can i know for sure? Is there any way to restrict the impoly() command?On the other hand,Is there any way to draw a rectangle with the imrect() command and to rotate it?
Image Analyst
Image Analyst 2013년 9월 15일
편집: Image Analyst 2013년 9월 15일
Sure. You know the rotation matrix, I'm sure. In case you don't, it's [cos(theta), sin(theta); -sin(theta), cos(theta)]. Just multiply your 4 by 2 array of (x,y) coordinates by that. Be sure to offset the coordinates by the center of the rectangle if you want to rotate it about the center of the rectangle rather than the origin!!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by