Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Closing a contour curve in OpenCV

I'm using OpenCV (Canny + findCountours) to find external contours of objects. The curve drawn is typically almost, but not entirely, closed. I'd like to close it - to find the region it bounds.

How do I do this?

Things considered:

  • Dilation - the examples I've seen show this after Canny, although it would seem to me it makes more sense to do this after findContours
  • Convex hull - might work, though I'm really trying to complete a curve
  • Shape simplification - related, but not exactly what I want
like image 906
SRobertJames Avatar asked Jan 30 '14 23:01

SRobertJames


1 Answers

Using PolyLine method to draw contours

cv2.PolyLine(img, points, is_closed=True, 255, thickness=1, lineType=8, shift=0)

Read the docs for further details: http://docs.opencv.org/2.4/modules/core/doc/drawing_functions.html

Mark answered if it resolved your problem. If not then let me know.

like image 189
Muhammad Abdullah Avatar answered Oct 03 '22 01:10

Muhammad Abdullah