OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Thu, 05 Nov 2015 14:44:24 -0600ellipse approximation of blob using contours moments : confusing orientation anglehttp://answers.opencv.org/question/75181/ellipse-approximation-of-blob-using-contours-moments-confusing-orientation-angle/ Dear all,
I want to draw the ellipse approximating an isolated blob (the largest contour found with findContours). Using the formulas of paper :http://goo.gl/yvcUO5 for the major and minor axes I obtain consistent axes lengths. However using the formula to compute the orientation angle from the same paper( and which I find almost everywhere) I obtain odd results. This is the formula : theta = 0.5*atan (2*mu11 / (mu20-mu02)) ;
As long as the blob (which represents a human silhouette) is not close to horizontal, the formula returns a consistent value of the orientation angle but as soon as the blob becomes almost horizontal the sign of the orientation angle is flipped suddenly. I know the reason of such a behavior. If we refer to the formula above : when the blob is not horizontal mu20 is smaller than mu02. This is true while the blob starts climbing (falling) counter clockwise until it reaches an orientation of about 45 degrees. When it reaches that value the pxels distribution of the blob becomes horizontal rather than vertical and mu20 becomes larger than mu02 which implies inversion of the angle's sign. I don't know if this formula is correct.
Thanks a lot for your help.Mon, 02 Nov 2015 11:07:20 -0600http://answers.opencv.org/question/75181/ellipse-approximation-of-blob-using-contours-moments-confusing-orientation-angle/Comment by LBerger for <p>Dear all,</p>
<p>I want to draw the ellipse approximating an isolated blob (the largest contour found with findContours). Using the formulas of paper :http://goo.gl/yvcUO5 for the major and minor axes I obtain consistent axes lengths. However using the formula to compute the orientation angle from the same paper( and which I find almost everywhere) I obtain odd results. This is the formula : theta = 0.5<em>atan (2</em>mu11 / (mu20-mu02)) ;</p>
<p>As long as the blob (which represents a human silhouette) is not close to horizontal, the formula returns a consistent value of the orientation angle but as soon as the blob becomes almost horizontal the sign of the orientation angle is flipped suddenly. I know the reason of such a behavior. If we refer to the formula above : when the blob is not horizontal mu20 is smaller than mu02. This is true while the blob starts climbing (falling) counter clockwise until it reaches an orientation of about 45 degrees. When it reaches that value the pxels distribution of the blob becomes horizontal rather than vertical and mu20 becomes larger than mu02 which implies inversion of the angle's sign. I don't know if this formula is correct.</p>
<p>Thanks a lot for your help.</p>
http://answers.opencv.org/question/75181/ellipse-approximation-of-blob-using-contours-moments-confusing-orientation-angle/?comment=75184#post-id-75184May be an [answer here](http://breckon.eu/toby/teaching/dip/opencv/SimpleImageAnalysisbyMoments.pdf)Mon, 02 Nov 2015 11:38:18 -0600http://answers.opencv.org/question/75181/ellipse-approximation-of-blob-using-contours-moments-confusing-orientation-angle/?comment=75184#post-id-75184Comment by lounice for <p>Dear all,</p>
<p>I want to draw the ellipse approximating an isolated blob (the largest contour found with findContours). Using the formulas of paper :http://goo.gl/yvcUO5 for the major and minor axes I obtain consistent axes lengths. However using the formula to compute the orientation angle from the same paper( and which I find almost everywhere) I obtain odd results. This is the formula : theta = 0.5<em>atan (2</em>mu11 / (mu20-mu02)) ;</p>
<p>As long as the blob (which represents a human silhouette) is not close to horizontal, the formula returns a consistent value of the orientation angle but as soon as the blob becomes almost horizontal the sign of the orientation angle is flipped suddenly. I know the reason of such a behavior. If we refer to the formula above : when the blob is not horizontal mu20 is smaller than mu02. This is true while the blob starts climbing (falling) counter clockwise until it reaches an orientation of about 45 degrees. When it reaches that value the pxels distribution of the blob becomes horizontal rather than vertical and mu20 becomes larger than mu02 which implies inversion of the angle's sign. I don't know if this formula is correct.</p>
<p>Thanks a lot for your help.</p>
http://answers.opencv.org/question/75181/ellipse-approximation-of-blob-using-contours-moments-confusing-orientation-angle/?comment=75475#post-id-75475@ L.Berger. Please check the poster's ID of the answer you are mentionning. You can see that it is not me. Anyways. I come to comment on my original question. After reading more carefuly drVit's document you have posted I managed to fetch consistent values or the orientation angle. Depending on the sign of the nominator and denominator in the ATAN expression.
Thanks.Thu, 05 Nov 2015 14:44:24 -0600http://answers.opencv.org/question/75181/ellipse-approximation-of-blob-using-contours-moments-confusing-orientation-angle/?comment=75475#post-id-75475Comment by LBerger for <p>Dear all,</p>
<p>I want to draw the ellipse approximating an isolated blob (the largest contour found with findContours). Using the formulas of paper :http://goo.gl/yvcUO5 for the major and minor axes I obtain consistent axes lengths. However using the formula to compute the orientation angle from the same paper( and which I find almost everywhere) I obtain odd results. This is the formula : theta = 0.5<em>atan (2</em>mu11 / (mu20-mu02)) ;</p>
<p>As long as the blob (which represents a human silhouette) is not close to horizontal, the formula returns a consistent value of the orientation angle but as soon as the blob becomes almost horizontal the sign of the orientation angle is flipped suddenly. I know the reason of such a behavior. If we refer to the formula above : when the blob is not horizontal mu20 is smaller than mu02. This is true while the blob starts climbing (falling) counter clockwise until it reaches an orientation of about 45 degrees. When it reaches that value the pxels distribution of the blob becomes horizontal rather than vertical and mu20 becomes larger than mu02 which implies inversion of the angle's sign. I don't know if this formula is correct.</p>
<p>Thanks a lot for your help.</p>
http://answers.opencv.org/question/75181/ellipse-approximation-of-blob-using-contours-moments-confusing-orientation-angle/?comment=75222#post-id-75222I think that's not a good way to use this forum. First when you have a question use Question and not Answer for a question. You shoud delete your "answer" and insert a new comment . Second if you have got a problem with fitellipse function forum user like to see some code or image with your problem to help you.Tue, 03 Nov 2015 01:20:48 -0600http://answers.opencv.org/question/75181/ellipse-approximation-of-blob-using-contours-moments-confusing-orientation-angle/?comment=75222#post-id-75222Comment by lounice for <p>Dear all,</p>
<p>I want to draw the ellipse approximating an isolated blob (the largest contour found with findContours). Using the formulas of paper :http://goo.gl/yvcUO5 for the major and minor axes I obtain consistent axes lengths. However using the formula to compute the orientation angle from the same paper( and which I find almost everywhere) I obtain odd results. This is the formula : theta = 0.5<em>atan (2</em>mu11 / (mu20-mu02)) ;</p>
<p>As long as the blob (which represents a human silhouette) is not close to horizontal, the formula returns a consistent value of the orientation angle but as soon as the blob becomes almost horizontal the sign of the orientation angle is flipped suddenly. I know the reason of such a behavior. If we refer to the formula above : when the blob is not horizontal mu20 is smaller than mu02. This is true while the blob starts climbing (falling) counter clockwise until it reaches an orientation of about 45 degrees. When it reaches that value the pxels distribution of the blob becomes horizontal rather than vertical and mu20 becomes larger than mu02 which implies inversion of the angle's sign. I don't know if this formula is correct.</p>
<p>Thanks a lot for your help.</p>
http://answers.opencv.org/question/75181/ellipse-approximation-of-blob-using-contours-moments-confusing-orientation-angle/?comment=75187#post-id-75187Another thing is confusing me... the coordinates system in openCV in linux... for the contours, moments and drawing function.Mon, 02 Nov 2015 11:44:52 -0600http://answers.opencv.org/question/75181/ellipse-approximation-of-blob-using-contours-moments-confusing-orientation-angle/?comment=75187#post-id-75187Comment by LBerger for <p>Dear all,</p>
<p>I want to draw the ellipse approximating an isolated blob (the largest contour found with findContours). Using the formulas of paper :http://goo.gl/yvcUO5 for the major and minor axes I obtain consistent axes lengths. However using the formula to compute the orientation angle from the same paper( and which I find almost everywhere) I obtain odd results. This is the formula : theta = 0.5<em>atan (2</em>mu11 / (mu20-mu02)) ;</p>
<p>As long as the blob (which represents a human silhouette) is not close to horizontal, the formula returns a consistent value of the orientation angle but as soon as the blob becomes almost horizontal the sign of the orientation angle is flipped suddenly. I know the reason of such a behavior. If we refer to the formula above : when the blob is not horizontal mu20 is smaller than mu02. This is true while the blob starts climbing (falling) counter clockwise until it reaches an orientation of about 45 degrees. When it reaches that value the pxels distribution of the blob becomes horizontal rather than vertical and mu20 becomes larger than mu02 which implies inversion of the angle's sign. I don't know if this formula is correct.</p>
<p>Thanks a lot for your help.</p>
http://answers.opencv.org/question/75181/ellipse-approximation-of-blob-using-contours-moments-confusing-orientation-angle/?comment=75197#post-id-75197What's exactly your problem? OpenCV use mathematical definition for all this things.Mon, 02 Nov 2015 15:08:45 -0600http://answers.opencv.org/question/75181/ellipse-approximation-of-blob-using-contours-moments-confusing-orientation-angle/?comment=75197#post-id-75197Comment by lounice for <p>Dear all,</p>
<p>I want to draw the ellipse approximating an isolated blob (the largest contour found with findContours). Using the formulas of paper :http://goo.gl/yvcUO5 for the major and minor axes I obtain consistent axes lengths. However using the formula to compute the orientation angle from the same paper( and which I find almost everywhere) I obtain odd results. This is the formula : theta = 0.5<em>atan (2</em>mu11 / (mu20-mu02)) ;</p>
<p>As long as the blob (which represents a human silhouette) is not close to horizontal, the formula returns a consistent value of the orientation angle but as soon as the blob becomes almost horizontal the sign of the orientation angle is flipped suddenly. I know the reason of such a behavior. If we refer to the formula above : when the blob is not horizontal mu20 is smaller than mu02. This is true while the blob starts climbing (falling) counter clockwise until it reaches an orientation of about 45 degrees. When it reaches that value the pxels distribution of the blob becomes horizontal rather than vertical and mu20 becomes larger than mu02 which implies inversion of the angle's sign. I don't know if this formula is correct.</p>
<p>Thanks a lot for your help.</p>
http://answers.opencv.org/question/75181/ellipse-approximation-of-blob-using-contours-moments-confusing-orientation-angle/?comment=75185#post-id-75185Hi L.Berger. I have already read it before posting my question. Actually it gives the same formula. Thank you anyways.Mon, 02 Nov 2015 11:41:16 -0600http://answers.opencv.org/question/75181/ellipse-approximation-of-blob-using-contours-moments-confusing-orientation-angle/?comment=75185#post-id-75185Answer by drVit for <p>Dear all,</p>
<p>I want to draw the ellipse approximating an isolated blob (the largest contour found with findContours). Using the formulas of paper :http://goo.gl/yvcUO5 for the major and minor axes I obtain consistent axes lengths. However using the formula to compute the orientation angle from the same paper( and which I find almost everywhere) I obtain odd results. This is the formula : theta = 0.5<em>atan (2</em>mu11 / (mu20-mu02)) ;</p>
<p>As long as the blob (which represents a human silhouette) is not close to horizontal, the formula returns a consistent value of the orientation angle but as soon as the blob becomes almost horizontal the sign of the orientation angle is flipped suddenly. I know the reason of such a behavior. If we refer to the formula above : when the blob is not horizontal mu20 is smaller than mu02. This is true while the blob starts climbing (falling) counter clockwise until it reaches an orientation of about 45 degrees. When it reaches that value the pxels distribution of the blob becomes horizontal rather than vertical and mu20 becomes larger than mu02 which implies inversion of the angle's sign. I don't know if this formula is correct.</p>
<p>Thanks a lot for your help.</p>
http://answers.opencv.org/question/75181/ellipse-approximation-of-blob-using-contours-moments-confusing-orientation-angle/?answer=75210#post-id-75210Try to use [fitellipse](http://docs.opencv.org/2.4/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#fitellipse) function.Mon, 02 Nov 2015 20:33:50 -0600http://answers.opencv.org/question/75181/ellipse-approximation-of-blob-using-contours-moments-confusing-orientation-angle/?answer=75210#post-id-75210