Trying to combine two files - peasy cam issue

I have two files

  1. A tree that grows. (branches grow organically from the root) This example is based on the 3D Fractal Tree Example by The Coding Train aka Daniel Shiffman.
  2. A movement trigger. That activates i++ each time someone moves in front of the screen.

I’m trying to combine the two files so the movement trigger is what grows a new branch each time someone moves in front of the webcam. But the camera ‘this’ and the peasy cam ‘this’ i think are getting mixed up in the code.

I tried replacing the camera ‘this’ with the name of my webcam. but the platform just got super confused. see below.

video = new Capture(this, width, height, 30);


video = new Capture(this, "name=Integrated Webcam,size=320x240,fps=30");

Not quite sure what to do here. Can anyone help? This is a link to the two files


1 Like

The keyword in this can certainly be confusing. In this context in referring to the PApplet (your current Processing application). Looking at the code you posted both the Capture and PeasyCam constructors are called from setup so chances are the this keyword isn’t your problem.

From what you said about the name of the webcam not working it might be that the Video library can’t find a webcam. Does the example on the Capture documentation page work?

Could you also post a screenshot of your error? I don’t have a webcam on this computer so I can’t run your sketch.

1 Like

Hi, I’ve uploaded the combined processing file,
screenshots for each file.

  1. The original tree
  2. The trigger ( an ellipse comes up when someone moves)
  3. The combined file when I use the generic ‘this’ for both peasy and the webcam.- file provides a black output.
  4. The combined file where I use the specific name for the webcam. - file shows an error - Array Index Out of Bounds Exception:0

You’re right, it may not be ‘this’ causing the issue. I’m not quite sure what else the issue could be.


1 Like

Looks like you might create prevFrame image before the Webcam finishes initializing so your video.width and video.height are set to 0. Not sure why this would suddenly show up with the same code as the trigger sketch, but I’ve run into this problem a couple times. Could try adding:

// Below, video.start(); (line 36)
println("videowidth: " + video.width + " videoheight: " + video.height);

You’ll have to scroll up above the error to see the println in the console. If it reads out as videowidth: 0 videoheight: 0. Then try changing line 38 to:

prevFrame = createImage(width, height, RGB);
// This might not be the best practice, but since you are using the sketch 
// size to define the Capture size it probably will work.

If you get something other than zero then it’s a different problem and I can look into it more I get home in an hour or two.

1 Like

I was trying to figure out the same issue. you were right. For some reason the first frame suddenly does NOT read, which is why the error shows up.

But with
println("videowidth: " + video.width + " videoheight: " + video.height);
it does not show 0. Not sure whats going on.

Anyway, I’ve got it working at 320.240. I just put in an if statement.

See here

Now need to figure out how to work with it at higher resolutions. Haven’t quite solved that issue yet :smiley:
Thank you for your help with this. Atleast I’ve got it started.

1 Like