Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Draw lines from centroid of contour at given angle till edge of contour

I have a contour named 'cnt' obtained from the image bellow:

image description

for which I am able to find the centroid like this:

M = cv2.moments(cnt)
centroid_x = int(M['m10']/M['m00'])
centroid_y = int(M['m01']/M['m00'])

I now want to draw N number of lines, each 360/N degrees apart, starting from the centroid and passing through all possible points of intersection with the contour. The cv2.line() function requires start point and end point but I don't have the end point.

If I had drawn a line passing through centroid with a slope of Tan(360/N) I would have found the intersection of the line with the contour using bitwise_and but I'm not able to figure out a way to draw that line.

Any help would be much appreciated.

click to hide/show revision 2
No.2 Revision

updated 2015-02-26 04:57:44 -0600

berak gravatar image

Draw lines from centroid of contour at given angle till edge of contour

I have a contour named 'cnt' obtained from the image bellow:below:

image description image description

for which I am able to find the centroid like this:

M = cv2.moments(cnt)
centroid_x = int(M['m10']/M['m00'])
centroid_y = int(M['m01']/M['m00'])

I now want to draw N number of lines, each 360/N degrees apart, starting from the centroid and passing through all possible points of intersection with the contour. The cv2.line() function requires start point and end point but I don't have the end point.

If I had drawn a line passing through centroid with a slope of Tan(360/N) I would have found the intersection of the line with the contour using bitwise_and but I'm not able to figure out a way to draw that line.

Any help would be much appreciated.

Draw lines from centroid of contour at given angle till edge of contour

I have a contour named 'cnt' obtained from the image below:

image description

for which I am able to find the centroid like this:

M = cv2.moments(cnt)
centroid_x = int(M['m10']/M['m00'])
centroid_y = int(M['m01']/M['m00'])

I now want to draw N number of lines, each 360/N degrees apart, starting from the centroid and passing through all possible points of intersection with the contour. The cv2.line() function requires start point and end point but I don't have the end point.

If I had drawn a line passing through centroid with a slope of Tan(360/N) I would have found the intersection of the line with the contour using bitwise_and but I'm not able to figure out a way to draw that line.

Any help would be much appreciated.