i actually made it.. took me less than half an hour, so it wasn't as hard as i thought.. :)
This is for webcam though.. but you can load an image into i.e. img, and change myCapture.pixels to img.pixels or something.
ask and thou shalt recieve help.
http://wliia.org/projects/video/textCam/textimg-322984.jpg
http://wliia.org/projects/video/textCam/textimg-3647328.jpg
http://wliia.org/projects/video/textCam/bwTextCam.pde
this is basicly what you need: color [] src are the same as img.pixels
Code:
usage:
drawLetters(myCapture.pixels,5);
drawLetters(checkInput(myCapture.pixels).pixels,5); // for dramatic effect
----
void drawLetters(color [] src, int spacing)
{
for(int j = 0; j < vheight; j+=spacing)
{
for(int i = 0; i < vwidth; i+=spacing)
{
fill(0);
//fill(src[j*vwidth+i]); // uncomment this if you want colored fonts
textFont(dFont,determineFontSize(getAreaBrightness(src,i,j,spacing)));
text(BaseTable[(int)random(0,BaseTable.length)],i*2,j*2); // let it pick randomly.. lots a bit messy, but it works.
}
}
}
int determineFontSize(int b)
{
if(b < 30)
return fSz+25;
if(b < 60)
return fSz+23;
if(b < 90)
return fSz+21;
if(b < 120)
return fSz+19;
if(b < 150)
return fSz+17;
if(b < 180)
return fSz+15;
if(b < 210)
return fSz+13;
if(b < 240)
return fSz+11;
if(b < 255)
return fSz+10;
return fSz;
}
int getAreaBrightness(color [] src, int x, int y, int sz)
{
int bval = 0, count = 1;
int xw = x+(sz*(vwidth/vheight)), yh = y+sz;
for(int i = x; i < xw; i++)
{
for(int j = y; j < yh; j++)
{
bval += brightness(src[j*vwidth+i]);
count++;
}
}
return (int)(bval/count);
}
PGraphics3 checkInput(color [] video){
PGraphics3 tmp = new PGraphics3(vwidth,vheight,null);
int black = color(0,0,0); // Declare some constants for colors.
int white = color(255,255,255);
int threshold = 127;
int pix_val; // Declare variables to store a pixel's color.
float pix_bri;
// Split the image into dark and light areas:
for (int i=0; i<video.length; i++){ // For each pixel in the video frame,
pix_val = video[i]; // fetch the current color in that location,
pix_bri = brightness (pix_val); // and compute the brightness of that pixel.
if (pix_bri > threshold){ // Now "binarize" the video into black-and-white,
tmp.pixels[i] = white; // depending on whether each pixel is brighter
} else { // or darker than a threshold value.
tmp.pixels[i] = black;
}
}
return tmp;
}
hope this helps you out
sincerly
seltar