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
using text in a video capture (Read 798 times)
using text in a video capture
Jun 5th, 2007, 12:41am
 
Hello everyone! I'm new on processing and I try to use the shape of a person captured by a firewire cam and to re-interpret this live-video as sentences or words.

I started by modified the exemple ascii-video in the library-video folder of the exemples. But I'm new on processing (YES!) and my experiments didn't work.

So, have you another solution easier or a solution to modify the ascii-video exemple?

Thanks !
Re: using text in a video capture
Reply #1 - Jun 5th, 2007, 1:39am
 
Hi,

can you please avoid to create many topics related to the same thing, it is the 3rd now.

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1180832697;start=1#1

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1180884188;start=0#0

If you really want to receive help from people here you should post the whole code you have modified in the same topic you've created first, if you create many topics it will be confusing and wouldn't be easier to find a solution to your problem.

Thx Smiley
Re: using text in a video capture
Reply #2 - Jun 5th, 2007, 2:16am
 
I'm sorry but I thought I was not in the good part of the forum and my english is bad...

the code :


import processing.opengl.*;
import processing.video.*;

Capture video;
int count;
boolean cheatScreen;

// all ascii characters, sorted according to their visual density
static final String vals =
 "HELLO" +
 "I'M FINE";

// how quickly to update each pixel (see below)
static final float STEP = 0.01;

// starting font size
float asciiFontSize = 1.5f;

float dgR[], dgG[], dgB[];

char values[];
float bright[];
char chars[];

PFont font;


public void setup() {
 // run at the default size
 size(640, 480, P3D);
 // or run full screen, more fun!
 //size(screen.width, screen.height, OPENGL);

 video = new Capture(this, 80, 60, 15);
 count = video.width * video.height;

 font = loadFont("UniversLTStd-Light-48.vlw");

 // for the 256 levels of brightness, distribute the letters across
 // the an array of 256 elements to use for the lookup
 values = new char[256];
 float multiplier = 256.0 / (float) vals.length();
 for (int i = 0; i < 256; i++) {
   int which = values[i] = vals.charAt((int) (i / multiplier));
 }

 // current characters for each position in the video
 chars = new char[count];



}


public void captureEvent(Capture c) {
 c.read();
}


void draw() {
 background(0);

 pushMatrix();

 float hgap = (float) width / (float) video.width;
 float vgap = (float) height / (float) video.height;

 scale(max(hgap, vgap) * asciiFontSize);
 textFont(font, asciiFontSize);

 int index = 0;
 for (int y = 1; y < video.height; y++) {

   // move down for next line
   translate(0,  1.0 / asciiFontSize);

   pushMatrix();
   for (int x = 0; x < video.width; x++) {
     int pixelColor = video.pixels[index];
     int r = (pixelColor >> 16) & 0xff;
     int g = (pixelColor >> 8 ) & 0xff;
     int b = pixelColor & 0xff;

     // another option would be to properly calculate brightness as luminance:
     // luminance = 0.3*red + 0.59*green + 0.11*blue
     // or you could instead red + green + blue, and make the the values[] array
     // 256*3 elements long instead of just 256.
     int brightness = max(r, g, b);

     // the STEP variable is used to damp the changes so that letters flicker less
     bright[index] =
       (bright[index] * (1.0 - STEP) + (float)brightness * STEP);

     fill(pixelColor);
     text((char) values[(int) bright[index]], 0, 0);
     index++;

     // move over for next character
     translate(1.0 / asciiFontSize, 0);
   }
   popMatrix();
 }
 popMatrix();

 if (cheatScreen) {
   image(video, 0, height - video.height);
 }
}


/**
* Handle key presses:
* 'c' toggles the cheat sccimage in the corner
* 'g' grabs an image and saves the frame to a tiff image
* 'f' and 'F' iffncrease and decrease the font size
*/
public void keyPressed() {
 switch (key) {
   case 'g': saveFrame(); break;
   case 'c': cheatScreen = !cheatScreen; break;
   case 'f': asciiFontSize *= 1.1f; break;
   case 'F': asciiFontSize *= 0.9f; break;
 }
}
Page Index Toggle Pages: 1