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.
IndexProgramming Questions & HelpSyntax Questions › Multiple Cameras
Page Index Toggle Pages: 1
Multiple Cameras (Read 599 times)
Multiple Cameras
Sep 12th, 2008, 5:32pm
 
Hey, trying to go through the Capture() documentation, and the example code for the captureEvent() related function is incorrect.

<code>
import processing.video.*;
Capture myCapture;
String[] caps;

void setup()
{
 size(200, 200);
 caps = Capture.list()
 myCapture = new Capture(this, caps[0], width, height, 30);
 myCapture = new Capture(this, caps[1], width, height, 30);
}

void captureEvent(Capture c) {
 if(c == caps[0]) {
   myCapture.read();
 } else if (c == caps[1]) {
   myCapture.read();
 }
}

void draw() {
 image(myCapture, 0, 0);
}

</code>

Forgetting the missing semi-colon, the if statement throws an error concerning comparing Capture to a string.

(can be found here: http://processing.org/reference/libraries/video/captureEvent_.html )

I am working on CV piece and I need to be able to track motion from 3 cameras at once. First step I need to accomplish is to pull in three different feeds... any help on the proper way to do this?
Re: Multiple Cameras
Reply #1 - Sep 12th, 2008, 11:01pm
 
Was able to answer my own question...

import processing.video.*;
Capture myCapture;
Capture myCapture2;
String[] captureDevices;

void setup()
{
 size(200, 200);
 println (Capture.list());
 captureDevices = Capture.list();
 myCapture = new Capture(this, width, height, 30);
 myCapture.settings();
 myCapture2 = new Capture(this, width, height, 30);
 myCapture2.settings();
}

void draw() {
 if (myCapture.available()) {
   myCapture.read();
   image(myCapture, 0, 0, width/2, height);
 }
 if (myCapture2.available()) {
   myCapture2.read();
   image(myCapture2, width/2, 0, width/2, height);
 }
}

there is my code, for those whom are interested.

Now my question is, is this the most efficient and correct way to do this? I ask because the reference code was incorrect, and I am confused about the captureEvent() usage. I have seen conflicting information. Can anyone clarify the usage?

ps, how do I do quote or code style stuff on the board?

Re: Multiple Cameras
Reply #2 - Feb 13th, 2009, 1:04am
 
Hi!

Not sure it is necessarily a better solution but i did some investigation in the processing svn source code for the Capture class.

What your initial code is trying to do is to compare an object of class Capture with a String, which is why it returns an error.

The Capture class has a "name" attribute but it is not exposed and i couldn't seem to access the name of its public "channel" attribute of class <a href="http://developer.apple.com/Java/Reference/1.4/Java14API_QTJ/quicktime/std/sg/SGVideoChannel.html">SGVideoChannel</a>.

The following code is essentially derived from your first version and identifies within the captureEvent callback which Capture object called it (by comparison between the calling object and either of the Capture object initialized in the setup()) and prints it on the console.

Quote:
import processing.video.*;
import quicktime.std.sg.*;
Capture myCapture1;
Capture myCapture2;
String[] captureDevices;

void setup()  
{
  size(200, 200);

  myCapture1 = new Capture(this, width, height, "DVCPRO HD (720p60)",30);
  myCapture2 = new Capture(this, width, height, 30);
}

void captureEvent(Capture c) {
  if(c == myCapture1) {
    myCapture1.read();
    println("First camera");
  } 
  else if (c == myCapture2) {
    myCapture2.read();
    println("Second camera");
  }
}

void draw() {
  background(0,128);
  if (frameCount%2 == 0)
    image(myCapture1, 0, 0);
  else
    image(myCapture2, 0, 0);





Hope this helps.

Pierre
Re: Multiple Cameras
Reply #3 - Feb 13th, 2009, 1:18am
 
psykel wrote on Sep 12th, 2008, 11:01pm:
ps, how do I do quote or code style stuff on the board


I forgot to add that "Copy for Discourse" in the "Edit" menu takes care of that for you.
Page Index Toggle Pages: 1