Copy pixel[] and overlay

edited February 5 in Library Questions

Screen Shot 2018-02-05 at 1.16.36 PM

I'm trying to create an effect like the image above which I have done by crudely exporting a frame then loading it and blending it - which isn't very memory/processor efficient. I'm wanting to know what the best way producing this effect would be with the pixel array. ie - how to store the pixels[] of a single frame.

thanks.

import processing.video.*;


PImage test, test2;
float FPS;
int count;
int mod;
int rand;


Capture video;

void setup() {
  size(640, 420, P2D);
  video = new Capture(this, 640, 360, 30);
  video.start();

}

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

void draw() {
  FPS = frameRate;
  count = ceil(millis()/1000);
  mod = count % 5;

  background(245, 238, 96);

  image(video, 0, 0, 640, 420);

  loadPixels();
  for (int i = 0; i < pixels.length; i++) {

    float b = brightness(pixels[i]);
    if (b > 97) {
      pixels[i] = color (255);
    } else {
      pixels[i] = color (245, 238, 96);
    }
  }

  updatePixels();
  textSize(16);
  fill(0);
  text(FPS, 50, 50);
  text(count, 50, 75);
  text(mod, 50, 100);
  text(mouseX, 50, 125);


}

Answers

  • //IN SETUP:
    ArrayList<PImage> container = new ArrayList<PImage>();
    
    //ADD any frames in your array list (Yes, 
    //  make sure you limit the size, otherwise laggish)
    //Use this in draw() when you get a new image for instance
    container.add(cam.get());
    
    //ONE example accessing those images
    //Here is where you can process them, merge them, filter them, etc.
    //I am displaying all the images on top of each other (Useless but good for demo)
    for(PImage p:container){
      image(p,0,0);
      p.loadPixels();
      println("Image dimensions => ",p.width,p.height);
    }
    

    Kf

  • Thanks for that - much appreciated - I have part of it working. I might need a few days. Cheers

Sign In or Register to comment.