我一直在使用OpenCV、ConvexHull和ConvexityDefects方法开发一个基本的手/手指跟踪代码。
基本上我可以创建一个手的轮廓。现在我需要能够计算手指的数量。我知道凸面船体的起点和终点是指尖,但我不确定如何计算它们,以及如何通过在它们上画圆圈或其他什么来突出它们。
我想让我的代码执行类似this的操作。
这是到目前为止我的代码的一个示例部分:
cvFindContours( hsv_mask, storage, &contours, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
CvSeq* contours2 = NULL;
CvRect rect = cvBoundingRect( contours2, 0 );
cvRectangle( bitImage, cvPoint(rect.x, rect.y + rect.height), cvPoint(rect.x + rect.width, rect.y), CV_RGB(200, 0, 200), 1, 8, 0 );
CvSeq* hull = cvConvexHull2( contours2, 0, CV_CLOCKWISE, 0 );
CvSeq* defect = cvConvexityDefects( contours2, hull, dftStorage );
CvBox2D box = cvMinAreaRect2( contours2, minStorage );
cvDrawContours( bg, contours2, CV_RGB( 0, 200, 0), CV_RGB( 0, 100, 0), 1, 1, 8, cvPoint(0,0));我已经尝试过了,现在可以使用下面的代码绘制指尖的点。
for(;defect;defect = defect->h_next)
{
int nomdef = defect->total;
if(nomdef == 0)
continue;
defectArray = (CvConvexityDefect*)malloc(sizeof(CvConvexityDefect)*nomdef);
cvCvtSeqToArray (defect, defectArray, CV_WHOLE_SEQ);
for(i=0; i<nomdef;>
{
cvCircle( bg, *(defectArray[i].end), 5, CV_RGB(255,0,0), -1, 8,0);
cvCircle( bg, *(defectArray[i].start), 5, CV_RGB(0,0,255), -1, 8,0);
cvCircle( bg, *(defectArray[i].depth_point), 5, CV_RGB(0,255,255), -1, 8,0);
}
j++;
free(defectArray);
}然而,我仍然得到了许多假阳性。此外,如果有人能提出任何方法来计算手指的数量,那就太好了。
发布于 2011-11-29 17:02:24
您拥有的一种可能性是计算缺陷的数量。如果你做得对,缺陷应该位于两个手指之间的底部。http://img27.imageshack.us/img27/6532/herpz.jpg
为了确保您不会得到任何“不想要的”缺陷,您可以使用CvConvexityDefect();函数中的'depth‘参数来过滤长度较短的缺陷。"depth“参数的更好描述可以在这里找到:opencv.itseez.com defect description
https://stackoverflow.com/questions/8239651
复制相似问题