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
slit-scanning in 3d using two webcams (Read 1710 times)
slit-scanning in 3d using two webcams
May 19th, 2010, 2:19pm
 
Hi, I am really new to this, but I have been trying to combine a found slit-scanning code and a found Anaglyph code. Below you can see what i have been trying. It does run, but not in the way i need it to. Could you give me any points as to where i am going wrong?


import processing.video.*;
Capture rightCamera;
Capture leftCamera;
PImage redImage;
PImage blueImage;
Boolean _isSetup;
int mode = 0;
int n;
int varZero;
int prevN;
int prevZero;
int rightnumPixels;
int leftnumPixels;
int rightprevPixels;
int[] rightprevLines;
int leftprevPixels;
int[] leftprevLines;


void setup(){
 size(640, 480);
 frameRate = 30;
 
 //instantiate capture source for right stereo image
rightCamera = new Capture(this, width, height, 30);        
//select webcam from quicktime dialog
rightCamera.settings();                            


 //instantiate capture source for left image
leftCamera = new Capture(this, width, height, 30);
//select webcam from quicktime dialog      
leftCamera.settings();
 
 
 
 
 rightnumPixels = rightCamera.width * rightCamera.height;
 //Sets the number of pixels to be stored using
 //an algebric progression formula related
 //to the number of lines to be stored.
 rightprevPixels = ((rightnumPixels*(height+1))/2);
 //Sets the array to store these pixels.
 rightprevLines = new int[rightprevPixels];


  leftnumPixels = leftCamera.width * leftCamera.height;
 //Sets the number of pixels to be stored using
 //an algebric progression formula related
 //to the number of lines to be stored.
 leftprevPixels = ((leftnumPixels*(height+1))/2);
 //Sets the array to store these pixels.
 leftprevLines = new int[leftprevPixels];
 
  redImage = new PImage(width, height);
blueImage = new PImage(width, height);

_isSetup = true;

 loadPixels();
 noStroke();
}





void updateMode(){

if(key == '1'){
 mode = 1;
}else if(key == '2'){
  mode = 2;
}else{
  mode = 0;
}

}






void draw(){
 if (rightCamera.available()){
   rightCamera.read();
   rightCamera.loadPixels();
   //For each line of the image:
   for (int y=1; y<height; y++){
     //Declares the value of 'n', which will be used to index
     //to which of the "lines" stored for line 'y' shall the software
     //access to store current frame's line 'y'.
     n=(frameCount%y);
     //Indexes to the begining of the "line" in which to store
     //the current frame's line 'y' using an algebric progression
     //formula based on 'y' var and the indexing gave by 'n' var.
     varZero= round((n*width)+(((sq(y)+y)*width)/2));
     //Declares the value of 'prevN'. This var will
     //index to stored "line" the software shall
     //read to display at current frame's line 'y'.
     prevN=((frameCount-(y-1))%y);
     //Indexes to the begining of the "line" that the software
     //shall read to display currently at line 'y'. Uses the
     //same process of varZero expression, but with other vars.
     prevZero=round((prevN*width) +(((sq(y)+y)*width)/2));
     //For each pixel in line 'y':
     for (int i=1; i<width; i++){
       //Declares a 'ind' var based on 'y' and 'i'
       //to index the displayed pixels.
       int ind=((y*width)+i);
       //Stores each pixel of line 'y' of current frame
       //captured from real-time video.
       rightprevLines[varZero+i]= rightCamera.pixels[ind];
       //Reads and displays the proper line of pixels from
       //the data stored.
       pixels[ind]=rightprevLines[prevZero+i];
     }
   }
   updatePixels();
    }
   
    if (leftCamera.available()){
   leftCamera.read();
   leftCamera.loadPixels();
   //For each line of the image:
   for (int y=1; y<height; y++){
     n=(frameCount%y);
     varZero= round((n*width)+(((sq(y)+y)*width)/2));
     prevN=((frameCount-(y-1))%y);.
     prevZero=round((prevN*width) +(((sq(y)+y)*width)/2));
     for (int i=1; i<width; i++){
       int ind=((y*width)+i);
       leftprevLines[varZero+i]= leftCamera.pixels[ind];
       pixels[ind]=leftprevLines[prevZero+i];
     }
   }
   updatePixels();
    }
   
    if(_isSetup){
 
 switch(mode) {
    case 1:
      showRight();
      break;
    case 2:
      showLeft();
      break;
    case 0:
      showAnaglyph();
      break;
   }
   
}
}



void showRight(){

if(rightCamera.available()){
  rightCamera.read();
  image(rightCamera, 0, 0);
}

}

void showLeft(){

if(leftCamera.available()){
  leftCamera.read();
  image(leftCamera, 0, 0);
}

}

/*
* create colorized images for both cameras
* and display a merged image
*/
void showAnaglyph(){
createRightImage();
createLeftImage();
mergeImages();
}

/*
* Remove blue from right
* camera feed and store in PImage
*/
void createRightImage(){
if(rightCamera.available()){
  //right = red;
  rightCamera.read();
  rightCamera.loadPixels();
   
  redImage.copy(rightCamera, 0, 0, width,  height, 0, 0, width, height);
 
  for(int i=0;i<redImage.pixels.length;i++)
  {
    float r = red(redImage.pixels[i]);
   // float g = green(redImage.pixels[i]);
    redImage.pixels[i] = color(r,0,0);
  }
}
}

void createLeftImage(){
if(leftCamera.available()){
  //left = blue;
  leftCamera.read();
  leftCamera.loadPixels();
 
  blueImage.copy(leftCamera, 0, 0, width,  height, 0, 0, width, height);
  for(int i=0;i<blueImage.pixels.length;i++)
  {
    float b = blue(blueImage.pixels[i]);
    float g = green(blueImage.pixels[i]);
    blueImage.pixels[i] = color(0,g,b);
  }
}
}

void mergeImages(){
if(leftCamera.available() && rightCamera.available()){
  image(blueImage, 0, 0);
  blend(redImage, 0, 0, width, height, 0, 0, width, height, SCREEN);
  image(blueImage, 0, height);
  image(redImage, width, height);
}
}
     
Re: slit-scanning in 3d using two webcams
Reply #1 - May 19th, 2010, 2:27pm
 
the question is, how do you need it ? hard to guess
Re: slit-scanning in 3d using two webcams
Reply #2 - May 19th, 2010, 2:54pm
 
Sorry, i should have specified but ran out of characters! Basically I need it to slit scan from both cameras and then apply a red filter to one camera and cyan to the other. Which in my mind, seems simple, but in practice it doesn't seem to work. I'm not sure if it is due to the fact that it is too heavy on my RAM (I only have 2GB) and/or GPU (which is intergrated rather than being a standalone card. Or if it is due to the code being poorly written. Any ideas?

Cheers
Re: slit-scanning in 3d using two webcams
Reply #3 - May 19th, 2010, 5:26pm
 
basically i think the colour extraction needs to be more efficient. There must be a way of colourising the slit scanned video without it being so heavy?
Re: slit-scanning in 3d using two webcams
Reply #4 - May 20th, 2010, 12:09am
 
maybe you can just tint them

try http://processing.org/reference/tint_.html
Page Index Toggle Pages: 1