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 & HelpVideo Capture,  Movie Playback,  Vision Libraries › drawing on a video like on a upper layer
Page Index Toggle Pages: 1
drawing on a video like on a upper layer (Read 897 times)
drawing on a video like on a upper layer
Aug 12th, 2009, 8:24am
 
hi all,

working on an installation that process some signals that arrive from another application, I've a little problem... the drawing on the video is not clear and the result is bad.

My goal is drawing on a video background, cause I'm a newbie of programming I've tried with the help of my father to draw a wave and a little rectangle (like examples): these are just few things in order to arrive to my final goal (drawing on the video the wave -in real time- and corresponding to the frequency of the signal, one "superimposed" frame white (perhaps not at 100% opacity but less).

Is possible to draw on a video, like the drawing ad the white frame are on different, upper, layers? I've tried to look to other video libraries (like openCV) but I didn' find nothing useful, but I also think is possible to do the thing I want...

thanks in advice (in next post, I put the code of the sketch that process the signal and draw on the video layer) I hope to be clear...


stefanino

Re: drawing on a video like on a upper layer
Reply #1 - Aug 12th, 2009, 8:25am
 
/**
*
* prototipo 0.5
* visualizza 1 video
* scrive il valore bpm ricevuto (1)
* sovrappone un rettangolo (2) con un effetto "bump"
* disegna grafico (in bianco) tipo polar
* invia ad arduino comando per ON striscia di led
*
*/


import processing.net.*;
import processing.video.*;
import processing.serial.*;

// Network connection
Client c;

// movie player
Movie myMovie;

// The serial port:
Serial myPort;



String input;
int data[];

int area=3;
float x[] = new float[area];
float y[] = new float[area];
float w[] = new float[area];
float h[] = new float[area];

float x00=0.;    
float y00=200;
float xx=0.;    
float yy=0.;
float x0=0.;    
float y0=0.;
float incY=1.;  
float facY=1.5;
float orgX=0.;  
float orgY=-60.;

boolean sent = false;
boolean flip = false;
int   bpm  = 0;
float mill = 0;
float bump = 0;
float btime= 0;
float bleng= 0;

int sizeX = 320 +  5 +  5; // 450;
int sizeY = 240 + 10 + 10; // 255;
//int sizeX=160;
//int sizeY=120;

void setup()
{
 size(sizeX, sizeY, P2D);
 background(204);

 //
 //myMovie = new Movie(this, "station.mov");
 myMovie = new Movie(this, "sfondo_cuore.mov");
 myMovie.loop();
 float hex=255;
 float alpha=128;
 tint(hex, alpha);
 //
 // non posso usare background con un movie //background(myMovie);
 //
 stroke(0);
 frameRate(16); // Slow it down a little
 // Connect to the server's IP address and port
 c = new Client(this, "127.0.0.1", 12345); // Replace with your server's IP and port

 // List all the available serial ports:
 println(Serial.list());
 /*  nx133 (windows: marco)
  [0] "COM1"
  [1] "COM4"
  [2] "COM7"
  */
 int nP = 2;
 int speed=9600;
 myPort = new Serial(this, Serial.list()[nP], speed);


 PFont  font;
 //String Tpath = "C:/a/processing-1.0.5/examples/Basics/Typography/Letters/data";
 String Tfont = "CourierNew36.vlw";
 font = loadFont(Tfont);
 textFont(font);

 x[0]=05;  
 y[0]=40;  
 w[0]=160;  
 h[0]= -35;  // bpm=
 x[1]=05;  
 y[1]=100;  
 w[1]=160;  
 h[1]= -35;  // bump color
 x[2]=50;  
 y[2]=100;  
 w[2]=110;  
 h[2]= -35;  // bump color

 if(false)
 {
   image(myMovie, 05, 10);
 }

}

void movieEvent(Movie myMovie) {
 myMovie.read();
}

void draw()
{
 mill = millis();  
 //
 if(false)
 { // sposta
   image(myMovie, mouseX-myMovie.width/2, mouseY-myMovie.height/2);
 }

 if(true)
 {
   image(myMovie, 05, 10);
 }

 //
 if ( (mill - bump) <= btime )
 {
   sent = false;
 }
 if ( (mill - bump) > btime )
 {
   // a new bump here
   bump = mill; // memo this time-instant

   if( flip) {
     fill(128);
   }
   else {
     stroke(255);
     fill(64);
   }
   rect(x[1],y[1],w[1],h[1]);
   flip = !flip;
   if( flip) {
     fill(128+64);
   }
   else {
     fill(256+64);
   }
   fill(0);

   if (true) if(!sent)
   {
     sent = true;
     // Send a capital A out the serial port:
     myPort.write(65);
   }

 }
 if (false) if ( (mill - bump) > bleng )
 {
   // a new bump here
   //bump = mill; // memo this time-instant
   if( flip) {
     fill(128+64);
   }
   else {
     stroke(255);
     fill(32);
   }
   rect(x[2],y[2],w[2],h[2]);
   if( flip) {
     fill(128+64);
   }
   else {
     fill(256+64);
   }
   fill(0);
 }


 if (mousePressed == true)
 {
   // Draw our line
   stroke(255);
   line(pmouseX, pmouseY, mouseX, mouseY);
   // Send mouse coords to other person
   c.write(pmouseX + " " + pmouseY + " " + mouseX + " " + mouseY + "\n");
 }

 // Receive data from server
 if (c.available() > 0)
 {
   input = c.readString();
   int nl = input.indexOf("\n");
   if(nl>=0)
   {
     input = input.substring(0, nl); // Only up to the newline
     data = int(split(input, ' ')); // Split values into an array
     bpm   = data[0];
     btime = (60./bpm)*1000.;  // bump-time = time-length of a hearth bump
     bleng = btime/5.;          // bump length

     if(true)
     {
       // Draw line using received coords
       stroke(255);
       // line(data[0], data[1], data[2], data[3]);
       xx = x00 + (xx     +orgX) + incY;
       yy = y00 - (data[0]+orgY) * facY;
       if(xx > x0) line(x0,y0, xx,yy);
       x0=xx;
       y0=yy;  
       if(x0 >sizeX)
       {
         background(204);
         stroke(0);
         x0=0;
         xx=0;
       }  
     }

     if(true)
     {
       stroke(192);
       rect(x[0],y[0]+6,w[0],h[0]);
       fill(128);
       text("bpm="+bpm, x[0],y[0],0);
       fill(255);
     }

     if (true)
     { // display bpm
       rect(x[0],y[0]+6,w[0],h[0]);
       fill(128);
       text("bpm="+bpm, x[0],y[0],0);
       fill(255);
     }


   } // if(nl>=0)
 } //  if (c.available() > 0)

}
Page Index Toggle Pages: 1