Saving a blended image as a PImage
in
Core Library Questions
•
1 year ago
Hey,
I'm a little new to this processing thing and I'm currently working on a project where I am trying to take a frame, add it to the next frame but have the two frames merge and create a new image based on the blended image of the first 2 frames. Then continue this process indefinitely. (Sorry if that is a bit complicated -> check code for more clarification)
I have tried using a blend() function continually on the image but it seems that you can't save a blend() into a PImage to be used later.
I have currently written a quick little blend function that returns a blended image but it doesn't seem to be doing the trick.
Ultimately I hope to have only the brightest pixels make their way to the front of the "accu" PImage.
Here is my current code:
- import processing.video.*;
- Capture cam;
- boolean testPic = false;
- PImage addi = createImage(320, 240, ARGB);
- PImage accu = createImage(320, 240, ARGB);
- PImage temp = createImage(320, 240, ARGB);
- int threshold = 20;
- float vidPixBrite;
- void setup() {
- size(670, 500);
- String[] cameras = Capture.list();
- cam = new Capture(this, 320, 240, cameras[0]);
- cam.start();
- frameRate(24);
- }
- void draw() {
- if (cam.available() == true) {
- cam.read();
- image(cam, 0, 0);
- image(addi, 340, 0);
- cam.loadPixels();
- addi.loadPixels();
- accu.loadPixels();
- for (int i = 0; i < cam.pixels.length; i++) {
- colorMode(HSB);
- color temp;
- temp = color((hue(cam.pixels[i])),(saturation(cam.pixels[i])), (brightness((cam.pixels[i]))-70));
- if(brightness(addi.pixels[i]) >= (brightness(accu.pixels[i]))){
- addi.pixels[i] = temp;
- }
- }
- addi.updatePixels();
- /* for(int i=0; i<cam.pixels.length; i++){
- // if(brightness(addi.pixels[i]) > (brightness(accu.pixels[i]))){
- accu.pixels[i] = addi.pixels[i];
- // }
- }*/
- temp = lightBlend(addi, accu);
- accu = temp;
- accu.updatePixels();
- image(cam, 0, 250);
- image(accu, 0, 250);
- accu.blend(cam, 0, 0, 340, 240, 0 , 250, 320, 240, LIGHTEST);
- }}
- //}
- void keyPressed(){
- switch(key){
- case 's': accu = clearPixels(accu); break;
- }
- }
- PImage clearPixels(PImage p){
- PImage temp = createImage(320, 240, ARGB);
- return temp;
- }
- PImage lightBlend(PImage light, PImage bg){
- PImage temp = createImage(light.width, light.height, ARGB);
- temp.loadPixels();
- light.loadPixels();
- bg.loadPixels();
- for(int i=0; i<temp.pixels.length; i++){
- if((brightness(light.pixels[i])) > (brightness(bg.pixels[i]))){
- temp.pixels[i] = light.pixels[i];
- }else if((brightness(light.pixels[i])) <= (brightness(bg.pixels[i]))){
- temp.pixels[i] = bg.pixels[i];
- }
- }
- return temp;
- }
Any help would be greatly appreciated - or if you have any other criticisms of the code I could use anything at all. Thanks you for your help in advance!
1