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
how do I choose another video source (Read 1290 times)
how do I choose another video source
May 30th, 2009, 3:07am
 
I'm new on processing; wanted to find out how can I choose a different video source (firewire 800) opposed to the built in camera on laptop.
would greatly appreciate it.

Regards

code;

import processing.video.*;
MovieMaker movie;

boolean rec;
int n;
int varZero;
int prevN;
int prevZero;
int numPixels;
int prevPixels;
int[] prevLines;
Capture video;

void setup(){
 size(320, 240);
 frameRate = 30;
 video = new Capture(this, width, height, 72);
 numPixels = video.width * video.height;
 //Sets the number of pixels to be stored using
 //an algebric progression formula related
 //to the number of lines to be stored.
 prevPixels = ((numPixels*(height+1))/2);
 //Sets the array to store these pixels.
 prevLines = new int[prevPixels];
 movie = new MovieMaker(this, width, height, "rybczynski.mov",
 72, MovieMaker.ANIMATION, MovieMaker.LOSSLESS);
 //Sets the movie recording function off by default.
 rec=false;
 loadPixels();
 noStroke();
}


void draw(){
 if (video.available()){
   video.read();
   video.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.
       prevLines[varZero+i]= video.pixels[ind];
       //Reads and displays the proper line of pixels from
       //the data stored.
       pixels[ind]=prevLines[prevZero+i];
     }
   }
   updatePixels();
   if (rec==true){
     movie.addFrame();
   }
 }
}

void keyPressed (){
 //If SPACE key is pressed and recording is off, turn it on.
 if (key==' ' && rec==false){
   rec=true;
   println("REC");
 }
 //If SPACE key is pressed and recording is on, turn it off.
 else if (key==' ' && rec==true){
   rec=false;
   println("PAUSE");
 }
 //If ESCAPE key is pressed, finish movie.
 else if (key==ESC){
   movie.finish();
   println("STOP");
 }
}
Re: how do I choose another video source
Reply #1 - May 30th, 2009, 7:19am
 
Try adding:

Code:

void keyPressed(){
 if(key == 's'){
   video.settings();
 }
}


at the end of your code. Then start the program and click "s". You can change camera in the settings window that appear.

I hope I could do this with JMyron or OpenCV libraries...
Re: how do I choose another video source
Reply #2 - May 30th, 2009, 8:00am
 
Or you add this code in setup(), taken from the video library examples:

Code:

Capture cam;
void setup() {
String[] devices = Capture.list();
println(devices);  
// Change devices[0] to the proper index for your camera.
cam = new Capture(this, width, height, devices[0]);
}


(There was errors in my codes. It's now fixed)
Re: how do I choose another video source
Reply #3 - Jun 1st, 2009, 3:52am
 
Hi - If I try adding the former i get an unexpected token: void.
and if i try the latter code in void setup it says 'Cannot not find anything named "cam"

What am I doing wrong here?

Thanks for your help.
Re: how do I choose another video source
Reply #4 - Jun 1st, 2009, 4:19am
 
Okay I added   if(key == 's'){
   video.settings();
I hit 's' when its running and i select source, DV is greyed out and cannot be selected - only built in camera is available?

why is this. I closed processing turned the camera back on and opened the project up again, but still no luck

what do i do next?
Re: how do I choose another video source
Reply #5 - Jun 15th, 2009, 2:27am
 
I had the same problem and I solved it by unplugging the (firewire cable of the) camera and plugged it in again while Processing was running and suddenly it was detected. It's ugly, but it worked.

* Dr. Strangecode
Page Index Toggle Pages: 1