William Renwick
YaBB Newbies
Offline
Posts: 5
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); } }