使用openCv凸度缺陷进行手指跟踪/计数 [英] Finger tracking / counting using openCv convexity defects

查看:161
本文介绍了使用openCv凸度缺陷进行手指跟踪/计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,只是一个简单的问题.我一直在使用OpenCv和ConvexHull和ConvexityDefects方法来研究基本的手/手指跟踪代码.基本上,我能够创建手的轮廓.我现在需要能够计算手指的数量.我不知道凸包的起点和终点只是指尖,但我不确定如何计算它们,以及如何通过绘制圆或它们或其他东西来突出显示它们.我有点用我的代码来执行类似 http://www.youtube.com/watch?v=mGpTE1RkEvQ [< ^ ]

到目前为止,这是我的代码的一部分:

Hi all, Just a quick question. I have been working on a basic hand/ finger tracking code using OpenCv and the ConvexHull and ConvexityDefects method. Basically i am able to create a contour of the hand. I now need to be able to count the number of fingers. I no that the start and the end points of the Convex Hull are the finger tips but i am unsure how to count them and also how to highlight them by drawing circles or them or something. I kinda what my code to preform something like this http://www.youtube.com/watch?v=mGpTE1RkEvQ[^]

This is a sample part of my code so far:

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));


我已经玩过它了,现在可以使用此代码绘制指尖


I have played around with it and I can now draw the fingertip points using this code

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);
	}



但是,我仍然收到很多误报.另外,如果有人可以建议任何方法来数手指,那将是非常棒的

任何帮助将不胜感激
谢谢



However i am still getting a lot of false positives. Also if any one could suggest any methods to now count the fingers that would be wonderful

Any help would be very much appreciated
Thanks

推荐答案

要计数或使用结果,请尝试类似

< pre>
CvSeq *壳= cvConvexHull2(Contours2,0,CV_CLOCKWISE,0);

int i;
for(i = 0; i total; i ++)
{
float * p =(float *)cvGetSeqElem(hull,i);
//在这里做些事,尽管float *可能不适合您的数据
}
</pre>
To count them or use the results, try something like

<pre>
CvSeq* hull = cvConvexHull2( contours2, 0, CV_CLOCKWISE, 0 );

int i;
for(i=0; i < hull->total; i++)
{
float* p = (float*)cvGetSeqElem(hull, i);
// do something here, though float* may not be right for your data
}
</pre>


关于误报,您是否在调用凸包算法尝试消除图像误报的某些原因之前尝试对图像进行处理?
Regarding false positives have you tried working on the image before calling the convex hull algorithm to try and remove some of the reasons for those false positives?


这篇关于使用openCv凸度缺陷进行手指跟踪/计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆