# A question about my code (video)

**URL:** <https://discourse.processing.org/t/a-question-about-my-code-video/24329>\
**Category:** Libraries\
**Created:** [October 4, 2020, 9:10am UTC](https://discourse.processing.org/t/a-question-about-my-code-video/24329 "2020-10-04T09:10:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![8SU](https://avatars.discourse-cdn.com/v4/letter/8/b4bc9f/32.png) [@8SU](https://discourse.processing.org/u/8SU)\
**Post date:** [October 4, 2020, 9:10am UTC](https://discourse.processing.org/t/a-question-about-my-code-video/24329/1 "2020-10-04T09:10:53Z")

</div>

So I’m new to Processing 3, and i can’t understand this issue

import processing.video.\*;

Capture cam;  
Capture G;  
Capture B;  
Capture R;

int capW = 320;  
int capH = 240;

int nDelayFrames = 20; // about 3 seconds (3seconds:10)  
int nDelayFramesB = 41;  
int nDelayFramesR = 61;  
int nDelayFramesG = 81;

int currentFrame = nDelayFrames-1;  
int currentFrameB = nDelayFramesB-1;  
int currentFrameR = nDelayFramesR-1;  
int currentFrameG = nDelayFramesG-1;

PImage frames[];  
PImage framesB[];  
PImage framesR[];  
PImage framesG[];

void setup() {  
size(640, 480);

```
String[] cameras = Capture.list();
  cam = new Capture(this, width, height, cameras[0]);
  B = new Capture(this, width, height, cameras[0]);
  R = new Capture(this, width, height, cameras[0]);
  G = new Capture(this, width, height, cameras[0]);

```

cam.start();

frames = new PImage[nDelayFrames];  
for (int i=0; i\<nDelayFrames; i++) {  
frames[i] = createImage(width, height, ARGB);  
}

```
framesB = new PImage[nDelayFramesB];

```

for (int i=0; i\<nDelayFramesB; i++) {  
framesB[i] = createImage(width, height, ARGB);  
}

framesR = new PImage[nDelayFramesR];  
for (int i=0; i\<nDelayFramesR; i++) {  
framesR[i] = createImage(width, height, ARGB);  
}

```
framesG = new PImage[nDelayFramesG];

```

for (int i=0; i\<nDelayFramesG; i++) {  
framesG[i] = createImage(width, height, ARGB);  
}

}

void draw() {  
if (cam.available()) {  
cam.read();  
B.read();  
R.read();  
G.read();

```
for (int d = 0; d < width; d++) 

```

{  
for (int j = 0; j \<height; j++)  
{  
int loc = d + j\*width;  
int pixelColour = cam.pixels[loc];

```
  //float g = (pixelColour >> 24) & 0xff;
  float r = (pixelColour >> 16) & 0xff;
  float g = (pixelColour >> 8) & 0xff;
  float b = pixelColour & 0xff;
  
  r = (r*1.0);
  g = (g*1.0);
  b = (b*1.0);
  
    cam.pixels[loc] = color(r, g, b); 
    R.pixels[loc] = color(r*2, 0, 0); <---- this point ! ( NullPointerException )
    G.pixels[loc] = color(0, g*2, 0); 
    B.pixels[loc] = color(0, 0, b*2); //img=cam;
   
  R.updatePixels();
  G.updatePixels();
  B.updatePixels();
  cam.updatePixels();
}

```

}

```
frames[currentFrame].loadPixels();
arrayCopy (cam.pixels, frames[currentFrame].pixels);
frames[currentFrame].updatePixels();
currentFrame = (currentFrame-1 + (nDelayFrames)) % nDelayFrames;

framesG[currentFrameG].loadPixels();
arrayCopy (G.pixels, framesG[currentFrameG].pixels);
framesG[currentFrameG].updatePixels();
currentFrameG = (currentFrameG-1 + (nDelayFramesG)) % nDelayFramesG;

framesR[currentFrameR].loadPixels();
arrayCopy (R.pixels, framesR[currentFrameR].pixels);
framesR[currentFrameR].updatePixels();
currentFrameR = (currentFrameR-1 + nDelayFramesR) % nDelayFramesR;  

framesB[currentFrameB].loadPixels();
arrayCopy (B.pixels, framesB[currentFrameB].pixels);
framesB[currentFrameB].updatePixels();
currentFrameB = (currentFrameB-1 + nDelayFramesB) % nDelayFramesB;

```

}

// tint(0,255,0,160);  
image (framesG[currentFrameG], 0, 0, width, height);  
//updatePixels();  
//tint(0,0,255,140);  
image (framesB[currentFrameB], 0, 0, width, height);  
image (framesR[currentFrameR], 0, 0, width, height);  
tint(255, 30);  
image(cam,0,0,width, height);

}

can help me please

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [October 4, 2020, 9:37am UTC](https://discourse.processing.org/t/a-question-about-my-code-video/24329/2 "2020-10-04T09:37:57Z")

</div>

Hello,

Welcome.

> [@8SU](#):
>
> So I’m new to Processing 3, and i can’t understand this issue

What issue?

Asking Questions:  
[https://discourse.processing.org/t/guidelines-asking-questions/2147](https://discourse.processing.org/t/guidelines-asking-questions/2147)

Please format your code:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

Your code runs here without an error once I comment your comment.

`:)`

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [October 5, 2020, 9:55am UTC](https://discourse.processing.org/t/a-question-about-my-code-video/24329/3 "2020-10-05T09:55:24Z")

</div>

I’m somewhat surprised @glv gets it to run. Opening the same camera from multiple streams is likely to be problematic. Also, you only seem to start `cam` or check that it has any data. Just work this around a single `Capture`.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [October 5, 2020, 10:05am UTC](https://discourse.processing.org/t/a-question-about-my-code-video/24329/4 "2020-10-05T10:05:19Z")

</div>

> [@neilcsmith](#):
>
> I’m somewhat surprised @glv gets it to run.

It runs as is (only commented his comment) on W10 and a old Logitech Pro 9000.

I did not explore beyond that or scrutinize his unformatted code for other issues.

`:)`

---

<div class="post-metadata">

**Author:** ![8SU](https://avatars.discourse-cdn.com/v4/letter/8/b4bc9f/32.png) [@8SU](https://discourse.processing.org/u/8SU)\
**Post date:** [October 7, 2020, 6:19am UTC](https://discourse.processing.org/t/a-question-about-my-code-video/24329/5 "2020-10-07T06:19:57Z")

</div>

hi nice meet you i am used maxbookpro 2019.  
and i can use maxbook camera and i don’t know why can’t play my code  
//float g = (pixelColour \>\> 24) & 0xff;  
float r = (pixelColour \>\> 16) & 0xff;  
float g = (pixelColour \>\> 8) & 0xff;  
float b = pixelColour & 0xff;

r = (r_1.0);  
g = (g_1.0);  
b = (b\*1.0);

```
cam.pixels[loc] = color(r, g, b); 
R.pixels[loc] = color(r*2, 0, 0); <---- this point ! ( NullPointerException )
G.pixels[loc] = color(0, g*2, 0); 
B.pixels[loc] = color(0, 0, b*2); //img=cam;

```

R.updatePixels();  
G.updatePixels();  
B.updatePixels();  
cam.updatePixels();  
}

issue is this part  
R.pixels[loc] = color(r\*2, 0, 0) ← NullPointerException

i don’t know what happened this issue

> [@8SU](#):
>
> ` R.pixels[loc] = color(r*2, 0, 0);`
