Reputation: 363
Given:
findContours()
in openCV python(y=mx + c)
.If the line intersects the contour, split/divide the original contour into two contours such that one contour falls on one side of the line and second contour on the other side.
How can I do this?
Example: NB: Line isn't necessarily horizontal.
Upvotes: 2
Views: 782
Reputation:
The expression y - (mx + c) is positive on a side of the line and negative on the other. Compute the sign for every vertex in sequence, keep the positive ones and the intersections. An intersection occurs on sides that exhibit a change of sign; you find the point by interpolation between the endpoints.
This gives you the positive polygon. Repeat with the negative signs to get the negative polygon.
Upvotes: 2