Q: Calculate distance to hand in real time in opencv? I am new to openCV. Is there any way to calculate distance to hand in real time in open cv. My basic idea is to track the hand and identify gestures. Its really hard to do it using skin color recognition. So I though, calculate distance to hand and isolate hand area and do the gesture recognition. Please help me with this...

A: Here are some of the techniques u can use...


*

*if your background is still and only the hand is moving then you can use frame differentiation to segment the moving hand...I(x,y)diff = absoulute[ I(x,y,n) - I(x,y,n-1) ]....where I(x,y,n) is the intensity of point x,y of the current frame...and I(x,y,n-1) is the same for the previous frame..then threshold I(x,y)diff to get the only moving hand....

*Use goodfeturestotrack function of OpenCV to identify a set of points that are good to track and calcOpticalFlow function to find the position of that set of points in each frame...this method is irrespective of the background...goodfeaturestotrack will identify a set of points on your hand as well as at the background ....but since your hand is moving considerably compared to your background so in each frame you will get different positions of the initially identified set of points that are good for tracking...so the points on and close to your hand will have maximum displacement compared to the other points in the frame...so on the basis of the magnitude of displacement of the points between 2 consecutive frames one can segment out the hand...this process is called optical flow calculation...

*once you segment out the hand then you can do a polygon fit to the segmented area. this way you can relate between the gesture and the shape of the polygon...

