A question about my code (video)

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

Hello,

Welcome.

What issue?

Asking Questions:
https://discourse.processing.org/t/guidelines-asking-questions/2147

Please format your code:
https://discourse.processing.org/faq#format-your-code

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

:)

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.

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.

:)

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 = (r1.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