Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For those who don't read the comments or didn't see it the solution is to use: </p> <p><code>vector&lt;cv::vector&lt;int&gt; &gt;hull;</code> </p> <p>to create the hull instead of:</p> <p><code>vector&lt;cv::vector&lt;Point&gt; &gt;hull;</code></p> <p>as convexityDefects only works on hulls stored as a series of indices rather than a series of Points.</p> <p>Sadly this gives another problem as drawContours only draws contours stored as a series of Points and not as a series of indices! So if you want to draw your hulls at a later stage you may want to create 2 stores when you are finding the hulls, one for drawing and one for finding defects from. Something along the lines of the following works:</p> <pre><code> // create storage space vector&lt;vector&lt;int&gt; &gt; hullsI(contours.size()); vector&lt;vector&lt;Point&gt; &gt; hullsP(contours.size()); vector&lt;vector&lt;Vec4i&gt; &gt; defects(contours.size()); for(int i = 0; i &lt;contours.size(); ++i){ //find the hulls convexHull(contours[i], hullsI[i], true); convexHull(contours[i], hullsP[i], true); //find the defects convexityDefects(contours[i], hullsI[i], defects[i]); } </code></pre> <p>It may be more efficient to just use a different method to draw the hulls rather than calculating them twice but this was the most elegant way I saw of doing it.</p> <p>Also I'm still getting the hang of C/C++ myself (Java guy) but I believe if you add <code>using namespace cv</code> to the top of the code you can save having to have cv:: throughout your code.</p> <p>Hope I haven't stepped on toes Innuendo, not my intention at all if I have.</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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