Setting Pixels of a Webcam Capture

Hello @dswayne92,

Modified your code:

// Modified code from here:
// https://discourse.processing.org/t/setting-pixels-of-a-webcam-capture/43976

import processing.video.*;

Capture video;
Movie clip;

color trackColor;
float threshold = 50;

void setup() 
  {
  size(640, 480);
  //frameRate(25);
  String[] cameras = Capture.list();
  printArray(cameras);
  video = new Capture(this, 640, 480);
  println(RGB);           // GLV added! 
  println(video.format);  // GLV added! 
  println(ARGB);          // GLV added! 
  video.format = ARGB;    // GLV added! 
  println(video.format);  // GLV added! 
  video.start();

  trackColor = color(255, 0, 0);
  noLoop();  // GLV added!
  }

void draw() 
  {
  background(255, 255, 0);
  video.format = 0;  // GLV added!          
  image(video, 0, 0);
  }

void captureEvent(Capture video) 
  {
  video.read();
  video.loadPixels();

  //iterate through pixel array
  for (int x = 0; x < video.width; x++) {
    for (int y = 0; y < video.height; y++)
    {
      //location of individual pixels
      int loc = x + y * video.width;

      //what  is current color
      color currentColor = video.pixels[loc];

      //get color values
      int r1 = (currentColor >> 16) & 0xFF;  // Faster way of getting red(argb)
      int g1 = (currentColor >> 8) & 0xFF;   // Faster way of getting green(argb)
      int b1 = currentColor & 0xFF;//fast blue

      int r2 = (trackColor >> 16) & 0xFF;  // Faster way of getting red(argb)
      int g2 = (trackColor >> 8) & 0xFF;   // Faster way of getting green(argb)
      int b2 = trackColor & 0xFF; // Faster way of getting blue(argb)

      //compare similarity of current color to track color
      //using 3d distance function
      float d = distSq(r1, g1, b1, r2, g2, b2);

      //if distance is below threshold squared
      if ( d < threshold * threshold) 
        {
        video.pixels[loc] = color(0, 0, 0, 0);
        }
      }
    }
  redraw(); // GLV added!
  }

//3d distance for color compariso
float distSq(float x1, float y1, float z1, float x2, float y2, float z2) {
  float d = (x2-x1) * (x2-x1) + (y2 - y1 ) * (y2- y1) + (z2-z1) * (z2-z1);
  return d;
}

void mousePressed() {
  //save a color where the mouse is clicked in trackColor
  //number of pixels is pixelWidth * pixelHeight;
  // 1200 * 800 = 960,000
  int loc = mouseX + mouseY * video.width;
  trackColor = video.pixels[loc];
}

Related discussions:

Scrutinize the changes and look up the references where needed.

:)