Note that there are some explanatory texts on larger screens.

plurals
  1. PODetect closed contours
    primarykey
    data
    text
    <p>This is example image:</p> <p><img src="https://i.imgur.com/ue0s2wL.png" alt="screenshot"></p> <p>and I use opencv to detect contours:</p> <pre><code>&gt;&gt;&gt; fc = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) &gt;&gt;&gt; contours = fc[0] </code></pre> <p>For detecting closed contour I thought to check start and end points in each contour returned by opencv, while I noticed that regardless the shape of object opencv seem to outline each object, so I get this result:</p> <pre><code>&gt;&gt;&gt; for contour in contours: &gt;&gt;&gt; print(contour[0,:,:], contour[-1,:,:]) [[246 38]] [[247 38]] [[92 33]] [[93 33]] </code></pre> <p>or each found contour has closed path.</p> <p>I searched for additional constants to available methods in <code>findContour()</code> function, but it seems all return closed paths.</p> <p>So is there some general way of detecting if found contour is closed?</p> <hr> <p>I googled before asking and didn't got results, but I see good candidate in similar questions at the right side: <a href="https://stackoverflow.com/questions/15135128/how-can-i-know-if-a-contour-is-open-or-closed-in-opencv">How can i know if a contour is open or closed in opencv?</a> where it is suggested I use <code>cv2.isContourConvex(contour)</code>, but:</p> <pre><code>&gt;&gt;&gt; for contour in contours: &gt;&gt;&gt; print(cv2.isContourConvex(contour)) False False </code></pre> <hr> <p>yet another update: <a href="http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#contourarea" rel="nofollow noreferrer">contourArea</a> looks like it may provide answer (at least for simple contours) but I didn't tested on anything else then above example image:</p> <pre><code>&gt;&gt;&gt; for contour in contours: &gt;&gt;&gt; print(cv2.contourArea(contour)) 0.0 12437.5 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload