0

My program deals with multitouch. I am supposed to differentiate between my right hand and my left hand.

To save the x,y touch points in an array i have

public boolean onTouchEvent(MotionEvent event) 
{
int pointerCount = event.getPointerCount();


if (pointerCount > MAX_TOUCHPOINTS)
{
    pointerCount = MAX_TOUCHPOINTS;
}


xval = new int[pointerCount];
yval = new int[pointerCount];



for (int i = 0; i < pointerCount; i++)
{
    xval[i]= (int) event.getX(i);
    yval[i]= (int) event.getY(i);
}

Canvas c = getHolder().lockCanvas();
.....
.....

}

To determine left and right hand I have

private String DetermineTouch()
{
String message="" ;
int xcount1=0,ycount=0,xcount2=0;
int ylargest=yval[0];
int xlargest=xval[0];
int xlowest=xval[0];

// The thumb has the highest y
for(int i=0;i<yval.length;i++)
{
 if(yval[i]> ylargest)
 {
     ylargest=yval[i];
     ycount=i;
 }

 // if the thumb is of my left hand x is the largest among the points
 for(int j=0;j<xval.length;j++)
 {
     if(xval[j]> xlargest)
     {
         xlargest=xval[j];
         xcount1=j;
     }
 }

// X is the smallest if the thumb is of my right hand

 for(int k=0;k<xval.length;k++)
 {
     if(xval[k]< xlowest)
     {
         xlowest=xval[k];
         xcount2=k;
     }
 }

 //determining left or right hand

 if(xval[ycount]==xval[xcount1]){
     message="left";
 }
 else if (xval[ycount]==xval[xcount2]){
     message="right";
 }
}

return message;
} 

This works if I were to place my hand normally on the screen (All five fingers). But if I try to place my hand at any angle the program fails. ( Example inclining my hand more towards right or more towards left) Is there a better approach to detect between left and right hand?

Any help is appreciated

gfernandes
  • 1,156
  • 3
  • 12
  • 29
  • I think this totally depends on what kind of touch it has to detect, and how accurate you want to detect it. By reading the question the only thing that is clear to me is you want to detect whether the right or left hand is touching the screen. But when? Two fingers? Whole hand? During use of the app? Or does the user place his hand on screen just for detection. This makes the difference of detecting both the pinky and thumb, or confusing the pinky for the thumb. – NickL Jan 09 '13 at 13:23
  • You indeed would have to calculate something to detect rotation of the hand. Your use case: left hand = thumb biggest Y, biggest X; right hand = thumb biggest Y, smallest X; only works when the hand is flat on the screen. If you rotate your left hand slightly to the right, now isntead of the thumb, the index finger will have the biggest X. I'm sure there is some kind of a clever formula for this, maybe you can ask it at the Math Q&A with a drawing of android screen axis + hand & rotation – NickL Jan 09 '13 at 13:40

1 Answers1

0

I didn't really get where you would use that snippet but I would simply get X1,Y1 and X2,Y2 and check whether X1 > X2 or not; then act accordingly.

Just remember that Android doesn't use the normal Cartesian axis with the 0,0 in the center of the screen.

EDIT: Check the size of the fingers? Android: Measure/detect covered area by a finger touch on screen (NOT only touch coordinates)

I don't know what your application is supposed to do but what I would is to ask the user to 'save' his hand configuration for both left and right hand and save the size of each finger somewhere; then, whenever he touches the screen you can easily tell (by the size and order) what hand and what finger is which.

Community
  • 1
  • 1
N3sh
  • 881
  • 8
  • 37
  • I did the same, compared between the x,y of all possible touch points. But this code does not detect accurately if the thumb is at the right side (indicating left hand) of left side (indicating right hand) of the screen. It confuses with the pinky – gfernandes Jan 09 '13 at 13:35
  • all five fingers of the hand – gfernandes Jan 09 '13 at 13:39
  • Oh, ok. So, you have only 5 fingers and you want to recognize whether it is a left or right hand? – N3sh Jan 09 '13 at 13:40
  • Yes exactly :) U have any solution? – gfernandes Jan 09 '13 at 13:42
  • Thank you! But i had tried event.getSize() and also event.getPressure(). These funCtions do not accurately determine between each fingers. I am using samsung galaxy tablet 2 10.1 and the size of the touch is 0. I think the problem is more mathematical – gfernandes Jan 09 '13 at 14:10
  • Well, my friend, if you cannot find a way to get the size of each finger, I am afraid Maths won't help you much. Another way would be to add assumptions and just go with it. If you assume a certain specific position of the hands, then you can just identify the thumb from the pinky by its Y position and then identify the left or right hand. – N3sh Jan 09 '13 at 14:14
  • I'm sure there is some kind of mathematical solution for this.. There will always be a relation between the distance of the finger touch points. Like distance between the tip of the fingers, will 'always'(if you don't bend a finger) be about the same. – NickL Jan 09 '13 at 14:18
  • Might help if you just look at the output of different hand positions and output of different calculations or ratios between finger touch points. Before you start doing the full calculation + result, because this will only tell you if you did it right or wrong, not HOW you should do it. – NickL Jan 09 '13 at 14:39