Problem with P2D

I’m doing Shiffman’s algorithm of motion detection, but I want to use P2D.
I noticed that there are “noise” in my video only when I use P2D, with the normal renderer there isn’t any problem.
even when I just read pixels from the video and write them again without touching anything there are color noises in the video sometimes.

here is the code for it:

import processing.video.*;

Capture video;
PImage prev;
void setup() {
  size (640, 480,P2D);
  video = new Capture (this, 640, 480);
  prev=createImage(640, 480, RGB);
  video.start();
}

void captureEvent (Capture video) {
  prev.copy(video, 0, 0, video.width, video.height, 0, 0, prev.width, prev.height);
  prev.updatePixels();
  video.read();
}

void draw() {
  loadPixels();
  prev.loadPixels();
  video.loadPixels();  

  for (int x = 0; x < prev.width; x++) {    
    for (int y = 0; y < prev.height; y++) {      
      int loc = x + y * prev.width;
      color current= video.pixels[loc];
       pixels[loc]=color(current);
    }
  }
  updatePixels();
}

what can be the problem?
thanks :slight_smile: