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
3D pixels from realtime video! (Read 5868 times)
3D pixels from realtime video!
May 8th, 2006, 2:03am
 
Hey, so I took the 2d pixelator program I wrote yesterday and threw in the 3rd dimension. I picked brightness for the box height... click on the link below to see a screen capture movie of what I was able to produce.  This was running on a 17" powerbook g4 with an external iSight camera.

http://www.youtube.com/v/SjvuyzBkLcc

Code is below... change the camera name to yours, and that should do it.  If you're using an external old school iSight, you might be able to just leave it alone:

Quote:


/*  webcam 3d pixelator!!
// steve cooley
// http://somejunkwelike.com/wordpress
// http://stevecooley.etsy.com
// 2006-05-07
*/

import processing.video.*;

Capture myCapture;  

// split the screen by:
int gridsizex = 40;
int gridsizey = 40;

// space between boxes
int spacer = 0;

void setup()  
{  
 background(0);

 framerate(20);
 size(640, 480, P3D);  
 println(Capture.list()); // to output which cam is connected, then copy that text into the string below

 // "IIDC FireWire Video" is what my external iSight is called.
 String s = "IIDC FireWire Video";  

 myCapture = new Capture(this, s, width, height, 10);
 noStroke();
 rectMode(CORNER);

}

void captureEvent(Capture myCapture) {
 myCapture.read();

}

//
// get the size of the window
// divide the window by x across and y down
// for every time in the x and y divisions, get the pixel color at that location
// draw a box (or ellipse) on that spot with that color
//


void draw() {
 lights();
 background(204);
 float cameraY = height/8.0;
 float fov = 1.5;
 float cameraZ = cameraY / tan(fov / 2.0);
 float aspect = float(width)/float(height);
 perspective(fov, aspect, cameraZ/10.0, cameraZ*10.0);
 float mousex = mouseX;
 float mousey = mouseY;
 camera(width/2, mouseY, mouseX,width/2,height/2,0,0.0,1.0,1.0); // help... this camera control is hard to understand

 if(myCapture.available()) {
   // Reads the new frame
   myCapture.read();
 }

 for(int y = 0; y<height; y=y+(height/gridsizey))
 {
   // println(y);
   for(int x = 0; x<width; x=x+(width/gridsizex))
   {
     // this took me a while to understand.
     // it was trying to get() the canvas at first, but then I learned about
     // myCapture.get();
     // I learned so much doing this program!
     color cp = myCapture.get(x, y);
     fill(cp);
     pushMatrix(); // OH, that's what that does. COOL.
     translate(x, y,0);
     box(width/gridsizex-spacer, height/gridsizey-spacer, int(brightness(cp)));
     popMatrix();
   }
 }
}



Re: 3D pixels from realtime video!
Reply #1 - May 8th, 2006, 2:34am
 
I'm guessing you could speed things up by simply setting your capture size to smaller (rather than 640x480), then accessing every pixel rather than the extra work of jumping by a particular number of pixels.  It will also probably do antialiasing for you, so the mosaic will be more accurate (I was going to post this on your other thread, it'd be much easier, and run a lot faster to simply use a stretched image call than a for loop of rect calls).

Looks interesting though, would be even cooler to see some real 3d using 2 cameras...

Marcello
Re: 3D pixels from realtime video!
Reply #2 - May 8th, 2006, 8:54pm
 
These 2 lines won't make a massive difference, but avoiding get can be useful, as I believe it's rather expensive:

Code:

//color cp = myCapture.get(x, y);
int cp = myCapture.pixels[y*myCapture.width+x];


and...

Code:

box(width/gridsizex-spacer, height/gridsizey-spacer, (cp & 0xff));


not much, but then what the hell!
Re: 3D pixels from realtime video!
Reply #3 - May 16th, 2006, 3:45am
 
Ok, I've incorporated some of the fine suggestions, and much better camera control with the OCD library.  Thank you all for your suggestions!

Quote:


import damkjer.ocd.*;
import processing.opengl.*;

/*  webcam 3d pixelator!! Version 3
// steve cooley
// http://somejunkwelike.com/wordpress
// http://stevecooley.etsy.com
// 2006-05-15
*/

import processing.video.*;

Capture myCapture;  
Camera camera1;

// split the screen by:
int gridsizex = 3*16;
int gridsizey = 4*16;
// Thank you Cello
int divide_capture_by = 10;
int capture_height = 640 / divide_capture_by;
int capture_width = 480 / divide_capture_by;

void setup()  
{  
 background(0);
 framerate(30);
 //  size(1024, 768, OPENGL);  
 size(640, 480, OPENGL);  
 //   size(500, 500, OPENGL);  
 println(Capture.list()); // to output which cam is connected, then copy that text into the string below

 camera1 = new Camera(this, width/2,height/2,500,width/2-100,height/2,0);

 // "IIDC FireWire Video" is what my external iSight is called.
 String s = "IIDC FireWire Video";  
 myCapture = new Capture(this, s, capture_width, capture_height, 30);
 noStroke();
 rectMode(CORNER);
}

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

void draw() {
 lights();
 background(204);
 float mousex = mouseX;
 float mousey = mouseY;
 camera1.feed();

 if(myCapture.available()) {
   // Reads the new frame
   myCapture.read();
 }

 for(int y = 0; y<capture_width; y=y+(capture_height/gridsizey))
 {
   // println(y);
   for(int x = 0; x<capture_width; x=x+(capture_width/gridsizex))
   {
     // thank you mark_h!
     int cp = myCapture.pixels[y*myCapture.width+x];
     fill(cp);
     pushMatrix(); // OH, that's what that does. COOL.
     translate(x*divide_capture_by, y*divide_capture_by,0);
     // thank you again mark_h
     box((capture_width*divide_capture_by)/gridsizex, (capture_height*divide_capture_by)/gridsizey, (cp & 0xff));
     popMatrix();
   }
 }
}

void mouseDragged() {
// thank you, surelyyoujest, I inverted your controls, and it works awesomely for me
 int divideby=2;
 if (mouseButton == LEFT) {
   camera1.tumble(radians((mouseX/divideby - pmouseX/divideby)*-1), radians((mouseY/divideby - pmouseY/divideby)*-1));
 }  
 else if (mouseButton == RIGHT) {
   camera1.track((mouseX/divideby - pmouseX/divideby)*-1, (mouseY/divideby - pmouseY/divideby)*-1);
 }  
 else if (mouseButton == CENTER) {
   camera1.dolly(mouseY/divideby - pmouseY/divideby);
 }
}


Re: 3D pixels from realtime video!
Reply #4 - Jan 15th, 2007, 6:59pm
 
hello i very interst in this code. . but how I can find the damkjer library, post in de code "import damkjer.ocd.*;"...
Re: 3D pixels from realtime video!
Reply #5 - Jan 16th, 2007, 12:11am
 
http://www.cise.ufl.edu/%7Ekdamkjer/processing/libraries/ocd/
Page Index Toggle Pages: 1