Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenCV CvConvexityDefects can't work and can't detect fingers!
    primarykey
    data
    text
    <p>I'm using OpenCv to detect fingertips, but now I meet with some obstacles! The findContours &amp; convexHull &amp; convexityDefects method doesn't work with my project. It's my first time to ask a question. Thanks everybody!</p> <p>My code is below:</p> <pre><code>int main() { CvScalar white = cvRealScalar(255); CvScalar black = cvRealScalar(0); CvSeq* contours = 0; CvMemStorage* storage = cvCreateMemStorage(0); IplImage* img = cvLoadImage("h.jpg"); IplImage* imgGray = cvCreateImage(cvGetSize(img), img-&gt;depth, 1); IplImage* contoursImg = cvCreateImage(cvGetSize(img), img-&gt;depth, 1); cvZero(contoursImg); int nWidth = contoursImg-&gt;width; int nHeight = contoursImg-&gt;height; int nChannels = contoursImg-&gt;nChannels; int nStep = contoursImg-&gt;widthStep; for (int i=0; i&lt;nHeight; i++) for(int j=0; j&lt;nWidth; j++) contoursImg-&gt;imageData[i*nStep + j*nChannels] = 255 - contoursImg-&gt;imageData[i*nStep + j*nChannels]; cvCvtColor(img, imgGray, CV_BGR2GRAY); cvThreshold(imgGray, imgGray, 230, 255, CV_THRESH_BINARY); cvSmooth(imgGray, imgGray); cvFindContours(imgGray, storage, &amp;contours, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0)); contours = cvApproxPoly(contours, sizeof(CvContour), storage, CV_POLY_APPROX_DP, 35, 1); cvDrawContours(contoursImg, contours, CV_RGB(0, 0, 0), CV_RGB(0, 0, 0), 1, 1, 8, cvPoint(0, 0)); CvSeq* hull = cvConvexHull2(contours, 0, CV_CLOCKWISE, 0); CvSeq* defect = cvConvexityDefects(contours, hull, NULL); for(; defect; defect = defect-&gt;h_next) { int nomdef = defect-&gt;total; if(!nomdef) continue; CvConvexityDefect* defectArray = (CvConvexityDefect*)malloc(sizeof(CvConvexityDefect)*nomdef); cvCvtSeqToArray(defect, defectArray, CV_WHOLE_SEQ); for(int i = 0; i &lt; nomdef; i++) { cvCircle(contoursImg, *(defectArray[i].end), 5, CV_RGB(255, 0, 0), -1, 8, 0); cvCircle(contoursImg, *(defectArray[i].start), 5, CV_RGB(0, 255, 0), -1, 8, 0); cvCircle(contoursImg, *(defectArray[i].depth_point), 5, CV_RGB(0, 0, 255), -1, 8, 0); } free(defectArray); } cvNamedWindow("image", 1); cvShowImage("image", contoursImg); cvWaitKey(0); cvReleaseMemStorage(&amp;storage); cvReleaseImage(&amp;img); cvReleaseImage(&amp;imgGray); cvReleaseImage(&amp;contoursImg); cvDestroyWindow("image"); return 0; } </code></pre> <p>This is my hand picture:</p> <p><a href="http://www.billwang.net/bbs/oldattach/2006/12/29/billwang_5315954-038-embed.jpg" rel="nofollow">http://www.billwang.net/bbs/oldattach/2006/12/29/billwang_5315954-038-embed.jpg</a></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.
 

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