We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Faking gesture/pattern recognition
Pages: 1 2 
Faking gesture/pattern recognition (Read 3743 times)
Re: Faking gesture/pattern recognition
Reply #15 - Feb 23rd, 2007, 5:54pm
 
At the moment I can't give my code out because it's my final year project but....

http://www.processing.org/reference/dist_.html << that tells you how to measure the distance bewteen X,Y and Z.

Then use the angles and do some experimenting using println statements to work out the average numbers for making shapes then do some if and else statements.

Sorry I can't be of much help.
Re: Faking gesture/pattern recognition
Reply #16 - Feb 23rd, 2007, 6:47pm
 
I used a neural net to do this sort of thing. My gesture was made with a class called Tracer:
Code:

//Line drawing class
class Tracer{
Vec2 [] vectors;
Tracer(){
}
Tracer(int len){
vectors = new Vec2[len];
}
void initVectors(Vec2 [] input){
//if the path is too short, double its length and interpolate vectors
while(input.length < vectors.length){
Vec2 [] temp = copyVec2(input);
input = new Vec2[(temp.length*2)-1];
for(int i = 0; i < temp.length-1; i++){
input[i*2] = temp[i];
input[i*2+1] = temp[i].midPoint(temp[i+1]);
}
input[input.length-1] = temp[temp.length-1];
}
//take points along the input as our path
if (input.length > vectors.length){
float step = (float)input.length/vectors.length;
float j = 0.0;
for(int i = 0; i < vectors.length; i++){
vectors[i] = input[(int)j];
j += step;
}
}
}
void draw(){
if(tracer.vectors[0] != null){
beginShape(LINE_STRIP);
for(int i = 0; i < vectors.length; i++)
vertex(vectors[i].x,vectors[i].y);
endShape();
}
}
}

I just took a line of points and then calculated the angle at each point. Then I compared that list of angles to the one I had stored. Thus, big square or small square, the angles in the points that go into making it are roughly the same as the square I drew in memory.

The neural net basically allows you to identify sloppy answers, but I'm sure you could bypass it (don't learn neural nets unless you really have to) by just taking the nearest rough answer (look up fuzzy logic).

The neural net gesture recognition is here.
Re: Faking gesture/pattern recognition
Reply #17 - Feb 24th, 2007, 2:25pm
 
Thats some cool code!

How do you plot different vertex point along a line?
Re: Faking gesture/pattern recognition
Reply #18 - Feb 24th, 2007, 3:26pm
 
The line was always taken as one long snap shot. I let the user drag the mouse to generate the line and on mouse release I capture. If it's too short then I walk along the points filling in enough points to make the length. Too long then I jump along the path missing surplus points. But that's all there in the code above anyway.

How do you mean a different point? Since the line is an array of a class called Vec2 (x, y), I guess you would just pick a member out from the array and change it's x,y value.
Re: Faking gesture/pattern recognition
Reply #19 - Feb 24th, 2007, 4:29pm
 
Thanks!!

One last (slightly stupid) question not so much related to this topic...

how would I go about storing about 4 different angles into an array?

Re: Faking gesture/pattern recognition
Reply #20 - Feb 24th, 2007, 4:38pm
 
That's more confusing than stupid. I assume you mean from points.

Code:

// Function from Vec2 class in Gesture sketch
float arcTan2(Vec2 other){
float dx = other.x - this.x;
float dy = other.y - this.y;
return atan2(dy,dx);
}

// Method for getting an array of angles from an array of Vec2s in gesture sketch
float [] atan2Vec2(Vec2 [] vectors){
float [] atan2Return = new float[vectors.length-1];
for(int i = 1; i < vectors.length; i++)
atan2Return[i-1] = vectors[i-1].arcTan2(vectors[i]);
return atan2Return;
}


or

Code:

float [] myAngles = {TWO_PI, HALF_PI, 3.6, 0.1};
Re: Faking gesture/pattern recognition
Reply #21 - Feb 25th, 2007, 9:12pm
 
Cheers!!
Pages: 1 2