# Trying to combine two files - peasy cam issue

**URL:** https://discourse.processing.org/t/trying-to-combine-two-files-peasy-cam-issue/7146
**Category:** Libraries
**Created:** [January 3, 2019, 10:41pm UTC](https://discourse.processing.org/t/trying-to-combine-two-files-peasy-cam-issue/7146 "2019-01-03T22:41:34Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![kritid](https://avatars.discourse-cdn.com/v4/letter/k/ea5d25/32.png) [@kritid](https://discourse.processing.org/u/kritid)
#### Post date: [January 3, 2019, 10:41pm UTC](https://discourse.processing.org/t/trying-to-combine-two-files-peasy-cam-issue/7146/1 "2019-01-03T22:41:34Z")

</div>

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.

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

```

with

```auto
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

[Tree&Trigger](https://www.dropbox.com/sh/387typvbmsll10h/AAANUS-OKB7o0oJHGP7xD93ta?dl=0)

---

<div class="post-metadata">

### Author: ![figraham](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/figraham/32/4161_2.png) [@figraham](https://discourse.processing.org/u/figraham)
#### Post date: [January 3, 2019, 11:10pm UTC](https://discourse.processing.org/t/trying-to-combine-two-files-peasy-cam-issue/7146/2 "2019-01-03T23:10:48Z")

</div>

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](https://processing.org/reference/libraries/video/Capture.html) 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.

---

<div class="post-metadata">

### Author: ![kritid](https://avatars.discourse-cdn.com/v4/letter/k/ea5d25/32.png) [@kritid](https://discourse.processing.org/u/kritid)
#### Post date: [January 3, 2019, 11:53pm UTC](https://discourse.processing.org/t/trying-to-combine-two-files-peasy-cam-issue/7146/3 "2019-01-03T23:53:34Z")

</div>

> [@kritid](#):
>
> video = new Capture(this, “name=Integrated Webcam,size=320x240,fps=30”);

Hi, I’ve uploaded the combined processing file,  
and  
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.

Link  
[Tree&Trigger](https://www.dropbox.com/sh/387typvbmsll10h/AAANUS-OKB7o0oJHGP7xD93ta?dl=0)

---

<div class="post-metadata">

### Author: ![figraham](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/figraham/32/4161_2.png) [@figraham](https://discourse.processing.org/u/figraham)
#### Post date: [January 4, 2019, 12:31am UTC](https://discourse.processing.org/t/trying-to-combine-two-files-peasy-cam-issue/7146/4 "2019-01-04T00:31:53Z")

</div>

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:

```auto
// 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:

```auto
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.

---

<div class="post-metadata">

### Author: ![kritid](https://avatars.discourse-cdn.com/v4/letter/k/ea5d25/32.png) [@kritid](https://discourse.processing.org/u/kritid)
#### Post date: [January 4, 2019, 2:58am UTC](https://discourse.processing.org/t/trying-to-combine-two-files-peasy-cam-issue/7146/5 "2019-01-04T02:58:46Z")

</div>

Hey,  
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](https://www.dropbox.com/sh/18htw0mrghl9m79/AACmEfr_jfFhFx2Ve28ITuu7a?dl=0)

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

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [January 4, 2019, 10:49am UTC](https://discourse.processing.org/t/trying-to-combine-two-files-peasy-cam-issue/7146/6 "2019-01-04T10:49:43Z")

</div>

- [Forum.Processing.org/two/discussion/16435/how-to-make-the-webcam-capture-window-go-away-or-put-images-over-it#Item\_1](http://Forum.Processing.org/two/discussion/16435/how-to-make-the-webcam-capture-window-go-away-or-put-images-over-it#Item_1)
