Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I raised this question because I wasn't able to figure out a solution (it is not only today that I was dealing with the matter hehe), but after all I was able to manage the problem! </p> <p>I had to change the way I calculated the convex hull, using the index array form. So now we have a vector&lt; int > instead a vector&lt; Point >.</p> <p>This is the code I used (it works I painted the points over an image):</p> <pre><code>void HandDetection::findConvexityDefects(vector&lt;Point&gt;&amp; contour, vector&lt;int&gt;&amp; hull, vector&lt;Point&gt;&amp; convexDefects){ if(hull.size() &gt; 0 &amp;&amp; contour.size() &gt; 0){ CvSeq* contourPoints; CvSeq* defects; CvMemStorage* storage; CvMemStorage* strDefects; CvMemStorage* contourStr; CvConvexityDefect *defectArray = 0; strDefects = cvCreateMemStorage(); defects = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq),sizeof(CvPoint), strDefects ); //We transform our vector&lt;Point&gt; into a CvSeq* object of CvPoint. contourStr = cvCreateMemStorage(); contourPoints = cvCreateSeq(CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), contourStr); for(int i=0; i&lt;(int)contour.size(); i++) { CvPoint cp = {contour[i].x, contour[i].y}; cvSeqPush(contourPoints, &amp;cp); } //Now, we do the same thing with the hull index int count = (int)hull.size(); //int hullK[count]; int* hullK = (int*)malloc(count*sizeof(int)); for(int i=0; i&lt;count; i++){hullK[i] = hull.at(i);} CvMat hullMat = cvMat(1, count, CV_32SC1, hullK); //We calculate convexity defects storage = cvCreateMemStorage(0); defects = cvConvexityDefects(contourPoints, &amp;hullMat, storage); defectArray = (CvConvexityDefect*)malloc(sizeof(CvConvexityDefect)*defects-&gt;total); cvCvtSeqToArray(defects, defectArray, CV_WHOLE_SEQ); //printf("DefectArray %i %i\n",defectArray-&gt;end-&gt;x, defectArray-&gt;end-&gt;y); //We store defects points in the convexDefects parameter. for(int i = 0; i&lt;defects-&gt;total; i++){ CvPoint ptf; ptf.x = defectArray[i].depth_point-&gt;x; ptf.y = defectArray[i].depth_point-&gt;y; convexDefects.push_back(ptf); } //We release memory cvReleaseMemStorage(contourStr); cvReleaseMemStorage(strDefects); cvReleaseMemStorage(storage); } } </code></pre> <p>This worked for me. If you see something wrong or another way to manage it, please tell me!</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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