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 & HelpPrograms › Need Help with video Streamin Boxes above text
Page Index Toggle Pages: 1
Need Help with video Streamin Boxes above text (Read 1009 times)
Need Help with video Streamin Boxes above text
Apr 12th, 2010, 3:24am
 
Hey guys ,

I am working on a program for an exhibition  . The main idea is to combine text mosaic and above that to have some boxes of the real video (with a small offset)


this is what i got :


1st tab:
"
import processing.video.*;
Capture video;
Box[] boxArray = new Box[25];
int f=0;

//create class Mosaic
Mosaic myMosaic;

void setup()
{
   size(640,480);
   video = new Capture(this,640,480,15);
   
   //define class Mosaic
   myMosaic = new Mosaic();
   for(int i = 0; i<boxArray.length; i++)
   { boxArray[i] = new Box();
   }
   frameRate(30);

}


void draw()
{
 //create an if/else form to animate the boxes depenting on the frame count
 if (video.available())
 { video.read();
 }
 
 //call class Mosaic
 myMosaic.display();
 //image(video,0,0);
 //image(video,0,0);
 
 
 int moveCounter = int(random(0, boxArray.length));
 
 boxArray[moveCounter].move();
 
 for(int i = 0; i<boxArray.length; i++)
 {
 
   
   //if(frameCount == 1+f)
   if(frameCount%25==0)
   {   //f = f+24;
     
      //if(i%2 == 0) boxArray[i].move();
      //else if(i%2 == 1) boxArray[i].move();
   }
   else
   {
       
      // boxArray[i].display();
     
   
   }
   
   //boxArray[i].move();
   boxArray[i].display();
 }


}


"


2nd tab (class for the video boxes):
"
class Box
{
 int Xpos;
 int Ypos;
 int BoxW;
 int BoxH;
 int cols;
 int rows;
 int visibleCounter;
 //this is freek jans code for the PImage
 
 public final static int visibleWindow = 5;
 public final static int lifeTime = 200;
 
 int birth;
 int speed = 4;
 PImage img;
 boolean visible;
 
 Box()
 {
   Xpos = int(random(100,540));
   Ypos = int(random(100,380));
   BoxW = int(random (50,100));
   BoxH = int(random (50,100));
   cols = int(Xpos/10);
   rows = int(Ypos/10);
   visible = true;
   birth = millis();

   img = createImage(BoxW, BoxH, ARGB);
   
 }
 
 //try to animate the box by making a method for a different position
 void move()
 {   Xpos = int(random(10,540));
      Ypos = int(random(100,380));
     //int(Xpos+random(0,200));
     //Ypos = int(Xpos+random(0,150));
 }

 void display()
 {
   int i;
   int j;
   int originalLoc;
   int offsetLoc;
   color c;
   
   noStroke();
   
   video.loadPixels();
   
   for (i = 0; i<BoxW; i++)
   {
     for(j = 0; j<BoxH; j++)
     {
       int pixLocation;
       c = video.pixels[(Xpos + i -10) + (j + Ypos) * video.width];
       img.pixels[i + j*BoxW] = color(red(c),0,0);
     }
   }
   

   img.updatePixels();
   
 
   
   if(alive() || true)
   { image(img, Xpos, Ypos, BoxW, BoxH);
   }
 
 
 }
 
 public boolean alive()
 {
   return (millis() - birth / 1000) < lifeTime;
 }
}
"



3rd tab (Class for the text Mosaic):

"
class Mosaic
{
 import processing.video.*;

// Size of each cell in the grid, ratio of window size to video size
int videoScale = 10;
// Number of columns and rows in our system
int cols, rows;
// Variable to hold onto capture object
Capture video;

// The source text used in the mosaic pattern. A longer String might produce more interesting results.
String chars = "Kirou-Furs" ;

PFont f;
 
 
 Mosaic()
 {
   size(640,480);
 // Set up columns and rows
 cols = width/videoScale;
 rows = height/videoScale;
 video = new Capture(this,cols,rows,15);

 // Load the font
 // Using a fixed-width font. In most fonts, individual characters have different widths.
 // In a fixed-width font, all characters have the same width.
 // This is useful here since we intend to display the letters one at a time spaced out evenly.
 // See Section 17.7 for how to display text character by character with a nonfixed width font.
 f = createFont("ArialHebrew-Bold",8,true);
 textFont(f);
   
 }
 
 void display()
 {
   background(0);

   // Read image from the camera
   if (video.available()) {
   video.read();
   }
   video.loadPixels();

   // Use a variable to count through chars in String
   int charcount = 0;
   // Begin loop for rows
   for (int j = 0; j < rows; j ++ )
   {
     // Begin loop for columns
     for (int i = 0; i < cols; i ++ )
     {

     // Where are we, pixel-wise?
     int x = i*videoScale;
     int y = j*videoScale;
     
      // Looking up the appropriate color in the pixel array
     color c = video.pixels[i + j*video.width];
     // Displaying an individual character from the String instead of a rectangle
     textFont(f);
     fill(c);

     // Map the brightness of a pixel to the size of a font
     float b = brightness(video.pixels[i + j*video.width]);
     float fontSize = 20 * (b / 255);
     textSize(fontSize);

     
     // One character from the source text is displayed colored accordingly to the pixel location.
     // A counter variable -- charcount -- is used to walk through the source String one character at a time.
     text(chars.charAt(charcount),x,y);

     // Go on to the next character
     charcount = (charcount + 1) % chars.length();
     }
   }
 
 
 }



}




"





The problem is that i constantly get an error in the 3rd tab and i don't get it: "The constructor Capture(kirou_furs_3tabs.Mosaic,int,int,int)" is undefined "

the video offset boxes and the mosaic work perfect separate

can you help (im a bit new in porcessing)
Re: Need Help with video Streamin Boxes above text
Reply #1 - Apr 12th, 2010, 4:02am
 
Within Mosaic class "this" refers to the instance of the Mosaic object, not a PApplet, you need to pass the main PApplet into the Mosaic object so it can then pass it to the Capture one, e.g.

Code:

class Mosaic
{
Capture video;
Mosaic(PApplet parent)
{
video=new Capture(parent,cols,rows,15);
}
}
Re: Need Help with video Streamin Boxes above text
Reply #2 - Apr 12th, 2010, 6:34am
 
Thanks this solves the problem there but now i got an error on my void setup

Quote:
void setup()
{
   size(640,480);
   video = new Capture(this,640,480,15);
   
   //define class Mosaic
   myMosaic = new Mosaic();
   for(int i = 0; i<boxArray.length; i++)
   { boxArray[i] = new Box();
   }
   frameRate(30);

}


The Constructor is undefined
Re: Need Help with video Streamin Boxes above text
Reply #3 - Apr 12th, 2010, 7:30am
 
myMosaic = new Mosaic(this);
Re: Need Help with video Streamin Boxes above text
Reply #4 - Apr 13th, 2010, 10:45am
 
Thanks for the help . Again guys . The program is working now but is really slow and the brightness detection is not working correctly , Is there any way to optimize it ?
Re: Need Help with video Streamin Boxes above text
Reply #5 - Apr 16th, 2010, 6:41am
 
The program is working now but is really slow . Below i will paste the code i got now . Can anyone help me optimize it so it run smoothly ?


Quote:
1st Tab:


import processing.video.*;
Capture video;
Box[] boxArray = new Box[25];
int f=0;

//create class Mosaic
Mosaic myMosaic;

void setup()
{
   size(640,480);
   video = new Capture(this,640,480,15);
   
   //define class Mosaic
    myMosaic = new Mosaic(this);
   for(int i = 0; i<boxArray.length; i++)
   { boxArray[i] = new Box();
   }
   frameRate(30);

}


void draw()
{
 //create an if/else form to animate the boxes depenting on the frame count
 if (video.available())
 { video.read();
 }
 
 //call class Mosaic
 myMosaic.display();
 //image(video,0,0);
 //image(video,0,0);
 
 
 int moveCounter = int(random(0, boxArray.length));
 
 boxArray[moveCounter].move();
 
 for(int i = 0; i<boxArray.length; i++)
 {
 
   
   //if(frameCount == 1+f)
   if(frameCount%25==0)
   {   //f = f+24;
     
      //if(i%2 == 0) boxArray[i].move();
      //else if(i%2 == 1) boxArray[i].move();
   }
   else
   {
       
      // boxArray[i].display();
     
   
   }
   
   //boxArray[i].move();
   boxArray[i].display();
 }


}






Quote:
2nd Tab:

class Box
{
 int Xpos;
 int Ypos;
 int BoxW;
 int BoxH;
 int cols;
 int rows;
 int visibleCounter;
 //this is freek jans code for the PImage
 
 public final static int visibleWindow = 5;
 public final static int lifeTime = 200;
 
 int birth;
 int speed = 4;
 PImage img;
 boolean visible;
 
 Box()
 {
   Xpos = int(random(100,540));
   Ypos = int(random(100,380));
   BoxW = int(random (50,100));
   BoxH = int(random (50,100));
   cols = int(Xpos/10);
   rows = int(Ypos/10);
   visible = true;
   birth = millis();

   img = createImage(BoxW, BoxH, ARGB);
   
 }
 
 //try to animate the box by making a method for a different position
 void move()
 {   Xpos = int(random(10,540));
      Ypos = int(random(100,380));
     //int(Xpos+random(0,200));
     //Ypos = int(Xpos+random(0,150));
 }

 void display()
 {
   int i;
   int j;
   int originalLoc;
   int offsetLoc;
   color c;
   
   noStroke();
   
   //video.loadPixels();
   
   for (i = 0; i<BoxW; i++)
   {
     for(j = 0; j<BoxH; j++)
     {
       int pixLocation;
       c = video.pixels[(Xpos + i -10) + (j + Ypos) * video.width];
       img.pixels[i + j*BoxW] = color(red(c),0,0);
     }
   }
   

   img.updatePixels();
   
 
   
   if(alive() || true)
   { image(img, Xpos, Ypos, BoxW, BoxH);
   }
 
 
 }
 
 public boolean alive()
 {
   return (millis() - birth / 1000) < lifeTime;
 }
}




Quote:
3rd Tab:
class Mosaic
{
//import processing.video.*;
// Size of each cell in the grid, ratio of window size to video size
int videoScale = 10;
// Number of columns and rows in our system
int cols, rows;
// Variable to hold onto capture object
//Capture video;


PImage img;
// The source text used in the mosaic pattern. A longer String might produce more interesting results.
String chars = "Kirou-Furs" ;

PFont f;
 
 //PApplet parent was shown to me by a question to the fo
 Mosaic(PApplet parent)
 {
   size(640,480);
 // Set up columns and rows
 cols = width/videoScale;
 rows = height/videoScale;
// video = new Capture(parent,cols,rows,15);

 // Load the font
 // Using a fixed-width font. In most fonts, individual characters have different widths.
 // In a fixed-width font, all characters have the same width.
 // This is useful here since we intend to display the letters one at a time spaced out evenly.
 // See Section 17.7 for how to display text character by character with a nonfixed width font.
 f = createFont("ArialHebrew-Bold",8,true);
 textFont(f);
 
  img = createImage(cols, rows, ARGB);
   
 }
 
 void display()
 {
   background(0);

   // Read image from the camera
   if (video.available()) {
   video.read();
   }
   video.loadPixels();

   // Use a variable to count through chars in String
   int charcount = 0;
   // Begin loop for rows
   for (int j = 0; j < rows; j ++ )
   {
     // Begin loop for columns
     for (int i = 0; i < cols; i ++ )
     {

     // Where are we, pixel-wise?
     int x = i*videoScale;
     int y = j*videoScale;
     
      // Looking up the appropriate color in the pixel array
     color c = video.pixels[i + j*video.width];
     // Displaying an individual character from the String instead of a rectangle
     textFont(f);
     fill(c);

     // Map the brightness of a pixel to the size of a font
     float b = brightness(video.pixels[i + j*video.width]);
     float fontSize = 20 * (b / 255);
     textSize(fontSize);

     
     // One character from the source text is displayed colored accordingly to the pixel location.
     // A counter variable -- charcount -- is used to walk through the source String one character at a time.
     text(chars.charAt(charcount),x,y);

     // Go on to the next character
     charcount = (charcount + 1) % chars.length();
     }
      img.updatePixels();
   
 
   
 
 

   }
 
 
 }



}
Re: Need Help with video Streamin Boxes above text
Reply #6 - Apr 16th, 2010, 7:49am
 
Actually i as I see again the Video boxes work Good but the mosaic is really bad . Any ideas?
Page Index Toggle Pages: 1