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 › colorize text with live capture.
Page Index Toggle Pages: 1
colorize text with live capture. (Read 773 times)
colorize text with live capture.
Jun 9th, 2007, 3:28am
 
Hi! I try to display a text that is colorized by a live camera capture. I took part of some codes to make it work but there's a strange error message.

There's the code :


import processing.video.*;
int cellsize = 100;
int cols, rows;
Capture video;
PFont font;
String lines[];


void setup() {
 
 size(400, 400);
 frameRate(30);
 cols = width/cellsize;
 rows = height/cellsize;
 
 
 video = new Capture (this, 80, 60, 15);
 font = loadFont("Verdana.vlw");
 textFont(font,24);
 lines = loadStrings ("mytext.rtf");
}

void captureEvent (Capture camera){
 camera.read();
}


void draw() {
 
 
 background(0);
 
 textFont(font, 50);
 textAlign(CENTER);

 for ( int i = 0; i < cols;i++) {
   for ( int j = 0; j < rows;j++) {
     int x = i*cellsize;
     int y = j*cellsize;
     int loc = video.width + y*video.width;      
 float r = red(video.pixels[loc]);
 float g = green(video.pixels[loc]);
 float b = blue(video.pixels[loc]);
 color c = color(r,g,b,75);

fill(c);
   }
 }
for (int t=0; t<lines.length; t++){
 text(lines[t], width, (t*35));
 t++;
}
}


and there's the error message :

java.lang.ArrayIndexOutOfBoundsException: 8080
at Temporary_3094_4846.draw(Temporary_3094_4846.java:43)
at processing.core.PApplet.handleDisplay(PApplet.java:1355)
at processing.core.PGraphics.requestDisplay(PGraphics.java:564)
at processing.core.PApplet.run(PApplet.java:1450)
at java.lang.Thread.run(Thread.java:613)

java.lang.ArrayIndexOutOfBoundsException: 8080
at Temporary_3094_4846.draw(Temporary_3094_4846.java:43)
at processing.core.PApplet.handleDisplay(PApplet.java:1355)
at processing.core.PGraphics.requestDisplay(PGraphics.java:564)
at processing.core.PApplet.run(PApplet.java:1450)
at java.lang.Thread.run(Thread.java:613)

I'm not familiar with coding so there's a lot of mistake in my code (I think). Help me please to soluce this!
Re: colorize text with live capture.
Reply #1 - Jun 9th, 2007, 12:25pm
 
i think you're going outbound in the video pixel data.

y = j *cellsize;

after few iterations y goes too high, that might be the problem..

i dunno from where you want the pixel color, but try it differently..



// number of cols and rows
int cols = 10;
int rows = 10;


// how much to step to move to next col/row position
int xstep = video.width / rows;
int ystep = video.height / cols;

for( j=0 to j<cols )
{
 int y = j * ystep;
 for ( i=0 to i<rows )
 {
   int x = i * xstep;
   int loc = x + y * video.width;
   
   float r = red(video.pixels[loc])
   ...
   etc
 }
}

hope that helps
Re: colorize text with live capture.
Reply #2 - Jun 9th, 2007, 1:18pm
 
thanks ! I going to try this !
Re: colorize text with live capture.
Reply #3 - Jun 9th, 2007, 1:46pm
 
So, I made this :


import processing.video.*;
int cellsize = 100;
int cols, rows;
Capture video;
PFont font;
String lines[];


void setup() {
 
 size(400, 400);
 frameRate(30);
 int cols = 10;
 int rows = 10;
 int xstep = video.width / rows;
 int ystep = video.height / cols;
 
 video = new Capture (this, 80, 60, 15);
 font = loadFont("Verdana.vlw");
 textFont(font,24);
 lines = loadStrings ("mytext.rtf");
}

void captureEvent (Capture camera){
 camera.read();
}


void draw() {
 
 
 background(0);
 
 textFont(font, 50);
 textAlign(CENTER);

for (j=0 to j<cols)
{
 int y = j * ystep;
 for (i=0 to i<rows)
 {
   int x = i * xstep;
   int loc = x + y * video.width;
 
 float r = red(video.pixels[loc]);
 float g = green(video.pixels[loc]);
 float b = blue(video.pixels[loc]);
 color c = color(r,g,b,75);

fill(c);
   }
 }
for (int t=0; t<lines.length; t++){
 text(lines[t]+"\n", width, (t*35));
t++;
}
}

But there's a error message : "expecting SEMI, found 'to'"
I dont't know what to do...
Re: colorize text with live capture.
Reply #4 - Jun 9th, 2007, 2:07pm
 
It's quite simple, that means it was expecting a ";" but found "to".

It's this chunk:

for (j=0 to j<cols) //<---
{
 int y = j * ystep;
 for (i=0 to i<rows) //<---
Re: colorize text with live capture.
Reply #5 - Jun 9th, 2007, 2:16pm
 
Yes, but how can I resolve this problem ??? Sad
I'm quite embarassing, I don't understand the significance of there "semicolons"...
Re: colorize text with live capture.
Reply #6 - Jun 9th, 2007, 2:44pm
 
you should read/learn more about java/c language..

what i wrote was pseudo code..


the lang correct version is:

for( int j=0; j<cols; j++ )
{
 for( int i=0; i<rows; i++ )
 {


the error msgs usually are quite easy to understand..
it points the error line and like john pointed it was expecting a ; and it found 'to'.. easy to fix
i believe you need to go through some java book/tutorial before attempting to go any further.
Re: colorize text with live capture.
Reply #7 - Jun 9th, 2007, 2:46pm
 
Ok thanks ! I 'll going to learn more about java!
Re: colorize text with live capture.
Reply #8 - Jun 10th, 2007, 2:21pm
 
at a glance, i think the only thing that was actually wrong with your original code was that this line:
int loc = video.width + y*video.width;    
should have been:
int loc = x + y*video.width;    
(which is what you changed it to later) for what it's worth...
Re: colorize text with live capture.
Reply #9 - Jun 10th, 2007, 8:21pm
 
Madekan :

This is a little help, i think this is what you want to do.

Now it's up to you to tweak it and try to adapt it to your needs.

You can use the text("HELLO", loc2/10, loc/10); to substitute the LoadStrings

(If you use a text file, it must be in TXT UTF-8 format, not RTF)

Quote:
import processing.video.*;

Capture video;
PFont font;
String lines[];
 int cols = 64;
 int rows = 48;
 int xstep = 2;
 int ystep = 1;

void setup() {
 
 size(640, 480,P3D);
 frameRate(30);    
 video = new Capture(this, 320, 240, 30);
 font = loadFont("Verdana.vlw");
  textFont(font, 12);
 lines = loadStrings("mytext.txt");
}

void captureEvent (Capture camera){
 camera.read();
}


void draw() {  
 
 
 background(0);  
 

for (int j=0 ; j<cols; j++)
{
for (int i=0 ; i<rows; i++)
 {
for (int t=0; t<lines.length; t++){  
   int y = j * ystep;
   int x = i * xstep;
   int loc = x + y *(video.width);
   int loc2 =y + x *(video.height);
   float r = red(video.pixels[loc]);
   float g = green(video.pixels[loc]);
   float b = blue(video.pixels[loc]);
   color c = color(r,g,b,255);

   fill(c);
//  println(lines[t]);
   textAlign(CENTER);
   text(lines[t]+"\n", loc2/10, loc/10);
//   text("HELLO WORLD", loc2/10, loc/10);
t++;
 }  
}
}
}

Re: colorize text with live capture.
Reply #10 - Jun 12th, 2007, 10:12am
 
Yes I know that I must use "txt" files. It was just or the example. Now, my code works. But I have a last problem. My purpose is to use the live capture to "illumate" the text. For example, in a dark room with a infra-red camera, a man enter and his shape in the screen is create by letters of the text, like this :

                    yes                       gfg
fs               very j                    gfd
fdf              ok f                   gfg
ghjfkdlfdlfldffgfdgfdgfdsdf
       ,kfldkfldgkfdkgf
       jfkdjgkfdjgkfdjk
        fdsfdsfdsfdsfd
         fdfdsfdsfdsfd
          fdsfdsfdsfdf
           fdsf      fdsf
           fdsf      fdd

My drawing is beautiful!
So, with this code, I tried to interpet the luminosity and colour of the live capture as the colour of each character.

But now, with this code, the luminosity and the colour of the video is assigned (english?) to the whole text and not to each characters...

How can I do?

the code  :


import processing.video.*;
int cellsize = 100;
int cols = 10;
int rows = 10;
Capture video;
PFont font;
String lines[];


void setup() {
 
 size(400, 400);
 frameRate(30);
 video = new Capture (this, 80, 60, 15);
 font = loadFont("Verdana.vlw");
 textFont(font,5);
 lines = loadStrings ("mytext.txt");
}

void captureEvent (Capture camera){
 camera.read();
}


void draw() {
 
 
 background(0);
 
 textFont(font, 10);
 
 
 int xstep = video.width / rows;
 int ystep = video.height / cols;
 for (int j=0; j<cols; j++){
   int y = j * ystep;
   for (int i=0; i<cols; i++)
   {
     int x = i * xstep;
     int loc = x + y * video.width;
     
     float r = red(video.pixels[loc]);
     float g = green(video.pixels[loc]);
     float b = blue(video.pixels[loc]);
     color c = color(r,g,b,75);
     fill(c);
   }
 }
for (int t=0; t<lines.length; t++){
 text(lines[t]+"\n", width, (t*35));
t++;
}

for (int t=0; t<lines.length; t++){
 int g = 30;
 text(lines[t],g, 60);
t++;
for (int m = 1; m < video.width; m++) {
   translate(0,8/0.5);
}
}
}

Page Index Toggle Pages: 1