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.
Page Index Toggle Pages: 1
JMyron & Triggering Text? (MAC) (Read 1037 times)
JMyron & Triggering Text? (MAC)
Apr 5th, 2010, 6:27pm
 
Hi there!

I'm pretty new at processing, have been playing quite a bit with example patches and have now included the JMyron (for MAC) external library. I am trying to create a video tracking patch that will trigger the presence of text on screen. I've tried very very many different approaches at this point (including NextText), to no avail.

The following patch is an attempt to hack together a differencing (JMyron) patch, a simple particle class ('cause it would hypothetically animate the text in an interesting way), and to loadStrings(from ext text file) from within the class. I haven't a clue if it would work, as I keep getting an error on the String var equation. Can anyone provide insight on why the error? Or should I simply go about the whole thing differently? And if so, links et al to any code examples would be oh-so gratefully helpful!

Here is the class patch (main patch to follow):

Code:


// A simple Particle class
class Particle5 {////////////////////////////OPEN

int i;
float x;
float y;
float xspeed;
float yspeed;

String loadFile;
public String[] words;

public Particle5(float x, float y) {
this.x = x;
this.y = y;
xspeed = random(-1,1);
yspeed = random(-2,0);

words= loadStrings("trial");
}

public void run() {
x = x + xspeed;
y = y + yspeed;
}

public void gravity() {
yspeed += 0.1;
}

public void display() {
stroke(0);
fill(255,75);
//ellipse(x,y,30,30);
for(i = 1; i < words.length; i++){
words[i=i+i];
}

}

}////////////////////////////CLOSED





Re: JMyron & Triggering Text? (MAC)
Reply #1 - Apr 5th, 2010, 6:30pm
 
here is the main patch:

Code:


// ----------------------------------------------------------------------
// GLOBAL VARIABLES & IMPORTS
// ----------------------------------------------------------------------

import JMyron.*;
//init external library with var
JMyron m;

float x;//shared by bubbles function & particles3 class
float y;//shared by bubbles function & particles3 class
ArrayList particles;//init arrayList
//Particle4 p;//init class object

//variables for findCentre() custom function
float objx = 160;//animation object in prior frame, x pos
float objy = 120;//animation object in prior frame, y pos
float objNextX = 160;//animation object in current frame, x pos
float objNextY = 120;//animation object in current frame, y pos

PFont fonts[];

// ----------------------------------------------------------------------
// SET-UP & MAIN LOOP
// ----------------------------------------------------------------------

void setup(){//setup OPEN

size(320,240);//or
//size(screen.width, screen.height);
//size(1024, 768); //USE FOR PRESENTATION
//frameRate(24);//good for sony miniDV but works w/o also
frame.setLocation(0,0);//for display purposes USE FOR PRESENTATION
m = new JMyron();//make a new instance of the ext-library object
m.start(width,height);//start capturing at screen size(320x240)
// for trackColor(red,green,blue,tolerance) tolerance = "sensitivity" of the color matching
//m.trackColor(0,0,0,100-100);//track black
m.trackColor(255,255,255,256*3-100);//track white
//ext library : perpetually update video pixels
m.update();
/*adaptivity(float val) sets the speed at which the retina image adapts
the retina is where the past frames are stored- waiting for comparison with the
cameraImage in order to calculate the difference */
m.adaptivity(10);//was 10
//tells the retinaImage to immediately adapt, completely, to the camera image
m.adapt();// immediately take a snapshot of the background for differencing
println("Myron " + m.version());
rectMode(CENTER);
noStroke();
//create arrayList
particles = new ArrayList();

//font selection
String[] fontFiles =
{
"Crass-48.vlw",
"Cambria-Bold-48.vlw",
"Felt_Regular-48.vlw",
"CODE3X-48.vlw"
};

fonts = new PFont[fontFiles.length];
for (int i = 0; i < fontFiles.length; i++)
{
fonts[i] = loadFont(fontFiles[i]);
}

}//setup CLOSE


void draw(){//draw OPEN

m.update();//ext library function : perpetually update processed camera frames
drawCamera();//custom function drawing camera pov
findCentre();//custom function locating centre x,y's of movement & draws animation

}//draw CLOSE

/*W/WEBCAM IT CRASHES!
void mousePressed(){
m.settings();//click the window to get the settings
} */

// ----------------------------------------------------------------------
// CUSTOM FUNCTIONS
// ----------------------------------------------------------------------

void drawCamera(){//drawC OPEN


//init array for recording difference image (btwn prior & current frames)
int[] img = m.differenceImage(); //ext lib function : returns the difference image
//get the normal image of the camera
loadPixels();
/*"pixels{} is an array containing the values for all the pixels in the display window.
These values are of the color datatype, array is the size of the display window.*/
//cycle through all the pixels and add the frame's pixels to screen
for(int i = 0; i < width*height; i++){ //for open
pixels[i] = img[i];
}//for closed

//processing command that updates the display window with the data in the pixels[] array).

updatePixels();

}//drawC CLOSE

////////////////////////// calculations that find average centre of motion's x,y positions
void findCentre() {//findC OPEN

/*globCenters() returns a list of center points for each glob.
this is a list of points [point,point,point] */
//init array (for recording all the centre points of glob in 2d array)
int[][] centers = m.globCenters();//get the center points
//draw all the dots while calculating the average.
//vars for counting the num of average x,y values
float avX=0;
float avY=0;
//cycle thru array and count the num of average x,y pos
for(int i = 0; i < centers.length; i++){//if1 open
fill(80);//80
rect(centers[i][0],centers[i][1],5,5);
avX += centers[i][0];
avY += centers[i][1];
}//if1 closed
//restrict average x,y data to 1 less than array length
if(centers.length-1 > 0){//if2 open
avX/=centers.length-1;
avY/=centers.length-1;
}//if2 closed

//draw the average of all the points in red.
fill(255,0,0);
rect(avX,avY,5,5);
println("avX= " + avX);
println("avY= " + avY);

//update the location of the object on the screen.
if(!(avX==0&&avY==0)&&centers.length>0){
objNextX = avX;
objNextY = avY;
}
objx += (objNextX-objx)/10.0f;
objy += (objNextY-objy)/10.0f;
fill(30,100,0,0);
ellipseMode(CENTER);
ellipse(objx,objy,30,30);

bubbles(objx,objy);

}//findC CLOSE


void bubbles(float x, float y) {//bubbles OPEN

// A new Particle object is added to the ArrayList every cycle through draw().
particles.add( new Particle5(x,y) );
// Iterate through our ArrayList and get each Particle
// The ArrayList keeps track of the total number of particles.
for (int i = 0; i < particles.size(); i++ ) {//for open
Particle5 p = (Particle5) particles.get(i);
//p.textSetUp();
p.run();
p.gravity();
p.display();

}//for closed

// If the ArrayList has more than 100 elements in it, we delete the first element, using remove().
if (particles.size() > 50) {//if open
particles.remove(0);
}//if closed

}//bubbles CLOSE

////////////////////////// needed for control over external library init
public void stop(){//stop OPEN
m.stop();//stop the object
super.stop();
}//stop CLOSE

Re: JMyron & Triggering Text? (MAC)
Reply #2 - Apr 7th, 2010, 8:43am
 
no need to reply - got it!
Re: JMyron & Triggering Text? (MAC)
Reply #3 - Apr 19th, 2010, 7:49am
 
Hello Pd

Glad that you made it work. I just checked your code and it is working here as well.
What caught my attention is that you mentioned the frame rate appropriate for Song miniDV. please please could you explain how can I connect Sony to a mac machine and get input from it? I am also a newbie in Processing. I have a video installation where I have prepared all the video analysis code and tested it with my web cam. I am still trying to get a Sony camera to test it on my code but some tips could help. I don't know if it is gonna be difficult or easy. I didn't really find resources talking about it.
So please if you can just give me some directions, then it would be really really great!!


Thanks
Cheers
RUSA
Page Index Toggle Pages: 1