Adjusting tint value (or possibly blend mode) to layer images
in
Contributed Library Questions
•
2 years ago
Hello
I'm very new to processing so apologies if this is covered else where.
I'm working on a image capture processing sketch, the idea is that the image is captured from a webcam and then layered with the previous layer, it also sends out a trigger to a PureData audio patch that records and layers the sound.
The problem is that tint() is applying everytime the sketch reloads the composite with a new image. Meaning that the previous images are becoming too faint too fast. What we want to happen is to retain more of the older images and add the new changes (a person in shot) to them. I have tried various blending modes and pixel changes to get the effect but i was wondering if anyone has a better idea of how to do it. One idea is to detect a pixel change within the image a turn these to black but i have no idea how to implement this once we have detected the pixel change. I don't know if i have explained this very well but here is the code. Some of the variables are now redundant.
Any help or ideas of how to get a better image would be amazing.
Thanks
//Assimilating Presence.
// Libraries
import processing.video.*;//openCV
import oscP5.*;
import netP5.*;
import hypermedia.net.*;
// Variables
int counter = 0;
int displaycounter = 0;
int framerate = 25;
PImage jpgimg;
Capture myCapture;//somehow setting up camera
int saveCount = 0;
int imgcounter = 0;
// Image manipulation variables
int num_images_to_use = 20;
PImage[] img_array = new PImage[num_images_to_use];
int start_img = 0;
long time_of_last_shot = -5L;
long time_lapse = 500; // millis
String latest_filename = null;
//--------------------------Server stuff
import hypermedia.video.*;
import oscP5.*;
import netP5.*;
public static final int port = 11000;
public static final String client_host = "127.0.0.1";
OpenCV opencv;
OscP5 oscP5;
private NetAddress client_destination = new NetAddress(client_host,port);
//----------------------------------------------------------
void setup(){
myCapture = new Capture(this, 800, 600);
size(myCapture.width,myCapture.height);
frameRate(framerate);
createOutput("imgs/tmp.txt");
{
size(800, 500);// to open camera settings and add cameras
// myCapture = new Capture(this, 800, 600);
//myCapture.settings();
// Initialise oscP5 variable
initOSCP5();
}
}
void initOSCP5() {
/* create a new osc properties object */
OscProperties properties = new OscProperties();
/* set a default NetAddress. sending osc messages with no NetAddress parameter
* in oscP5.send() will be sent to the default NetAddress.
*/
properties.setRemoteAddress("127.0.0.1",11000);
/* the port number you are listening for incoming osc packets. */
properties.setListeningPort(11000);
/* Send Receive Same Port is an option where the sending and receiving port are the same.
* this is sometimes necessary for example when sending osc packets to supercolider server.
* while both port numbers are the same, the receiver can simply send an osc packet back to
* the host and port the message came from.
*/
properties.setSRSP(OscProperties.ON);
/* set the datagram byte buffer size. this can be useful when you send/receive
* huge amounts of data, but keep in mind, that UDP is limited to 64k
*/
properties.setDatagramSize(1024);
/* initialize oscP5 with our osc properties */
oscP5 = new OscP5(this,properties);
/* print your osc properties */
println(properties.toString());
}
//----------------------------------------------------------
void draw() {
// If no images have been captured, then show what is in view of the camera...
if(imgcounter == 0 && myCapture.available()) {
myCapture.read();
image(myCapture, 0,0);
}
else
drawImage();
if(imgcounter != 0 && System.currentTimeMillis()-time_of_last_shot>time_lapse) {
// captureAndProcess();
}
}
void drawImage() {
if(myCapture.available()) {
myCapture.read();
image(myCapture, 0,0);
tint(255, 210);//tint video
}
if(latest_filename!=null) {
PImage tmp_img = loadImage(latest_filename);
image(tmp_img, 0, 0);
}
}
void keyPressed() {
// If the space key (' ') was pressed, then capture the image and increment the counter
// Also, process the image using the 'process_image' function
if(key == ' ') {
captureAndProcess();
}
}
void captureAndProcess() {
if(myCapture.available()) {
println("capture " + imgcounter + "OscMessage myMessage");
myCapture.read();
image(myCapture, 0, 0);
tint(255, 100);// this is the alpha that is applied to the composite
String filename = "imgs/frame_" + imgcounter + ".jpg";
saveFrame(filename);
imgcounter++;
// Trigger audio capture in Pure Data
OscMessage myMessage = new OscMessage("/trigger");
myMessage.add("/trigger");
oscP5.send(myMessage, client_destination);
process_image();
time_of_last_shot = System.currentTimeMillis();
}
}
void process_image() {
println("Processing new image...");
// Set the image to start with..
start_img = imgcounter - num_images_to_use;
if(start_img<0) start_img = 0;
// Load images into memory
println("Loading "+imgcounter+"images...");
size(800, 600);
for (int i = 0; i < num_images_to_use && i < imgcounter; i = i+1)
img_array[i] = loadImage("imgs/frame_"+(i+start_img)+".jpg"); // Load an image into the array
println("Loading images...DONE");
// Draw images
println("Drawing "+imgcounter+" images...");
for (int i = 0; i < num_images_to_use && i < imgcounter; i = i+1) {
image(img_array[i], 0, 0);
}
println("Drawing images...DONE");
// Save the composite
latest_filename = "composites/tomisawesome_" + imgcounter + ".jpg";
saveFrame(latest_filename);
println("Processing new image...DONE");
}
I'm very new to processing so apologies if this is covered else where.
I'm working on a image capture processing sketch, the idea is that the image is captured from a webcam and then layered with the previous layer, it also sends out a trigger to a PureData audio patch that records and layers the sound.
The problem is that tint() is applying everytime the sketch reloads the composite with a new image. Meaning that the previous images are becoming too faint too fast. What we want to happen is to retain more of the older images and add the new changes (a person in shot) to them. I have tried various blending modes and pixel changes to get the effect but i was wondering if anyone has a better idea of how to do it. One idea is to detect a pixel change within the image a turn these to black but i have no idea how to implement this once we have detected the pixel change. I don't know if i have explained this very well but here is the code. Some of the variables are now redundant.
Any help or ideas of how to get a better image would be amazing.
Thanks
//Assimilating Presence.
// Libraries
import processing.video.*;//openCV
import oscP5.*;
import netP5.*;
import hypermedia.net.*;
// Variables
int counter = 0;
int displaycounter = 0;
int framerate = 25;
PImage jpgimg;
Capture myCapture;//somehow setting up camera
int saveCount = 0;
int imgcounter = 0;
// Image manipulation variables
int num_images_to_use = 20;
PImage[] img_array = new PImage[num_images_to_use];
int start_img = 0;
long time_of_last_shot = -5L;
long time_lapse = 500; // millis
String latest_filename = null;
//--------------------------Server stuff
import hypermedia.video.*;
import oscP5.*;
import netP5.*;
public static final int port = 11000;
public static final String client_host = "127.0.0.1";
OpenCV opencv;
OscP5 oscP5;
private NetAddress client_destination = new NetAddress(client_host,port);
//----------------------------------------------------------
void setup(){
myCapture = new Capture(this, 800, 600);
size(myCapture.width,myCapture.height);
frameRate(framerate);
createOutput("imgs/tmp.txt");
{
size(800, 500);// to open camera settings and add cameras
// myCapture = new Capture(this, 800, 600);
//myCapture.settings();
// Initialise oscP5 variable
initOSCP5();
}
}
void initOSCP5() {
/* create a new osc properties object */
OscProperties properties = new OscProperties();
/* set a default NetAddress. sending osc messages with no NetAddress parameter
* in oscP5.send() will be sent to the default NetAddress.
*/
properties.setRemoteAddress("127.0.0.1",11000);
/* the port number you are listening for incoming osc packets. */
properties.setListeningPort(11000);
/* Send Receive Same Port is an option where the sending and receiving port are the same.
* this is sometimes necessary for example when sending osc packets to supercolider server.
* while both port numbers are the same, the receiver can simply send an osc packet back to
* the host and port the message came from.
*/
properties.setSRSP(OscProperties.ON);
/* set the datagram byte buffer size. this can be useful when you send/receive
* huge amounts of data, but keep in mind, that UDP is limited to 64k
*/
properties.setDatagramSize(1024);
/* initialize oscP5 with our osc properties */
oscP5 = new OscP5(this,properties);
/* print your osc properties */
println(properties.toString());
}
//----------------------------------------------------------
void draw() {
// If no images have been captured, then show what is in view of the camera...
if(imgcounter == 0 && myCapture.available()) {
myCapture.read();
image(myCapture, 0,0);
}
else
drawImage();
if(imgcounter != 0 && System.currentTimeMillis()-time_of_last_shot>time_lapse) {
// captureAndProcess();
}
}
void drawImage() {
if(myCapture.available()) {
myCapture.read();
image(myCapture, 0,0);
tint(255, 210);//tint video
}
if(latest_filename!=null) {
PImage tmp_img = loadImage(latest_filename);
image(tmp_img, 0, 0);
}
}
void keyPressed() {
// If the space key (' ') was pressed, then capture the image and increment the counter
// Also, process the image using the 'process_image' function
if(key == ' ') {
captureAndProcess();
}
}
void captureAndProcess() {
if(myCapture.available()) {
println("capture " + imgcounter + "OscMessage myMessage");
myCapture.read();
image(myCapture, 0, 0);
tint(255, 100);// this is the alpha that is applied to the composite
String filename = "imgs/frame_" + imgcounter + ".jpg";
saveFrame(filename);
imgcounter++;
// Trigger audio capture in Pure Data
OscMessage myMessage = new OscMessage("/trigger");
myMessage.add("/trigger");
oscP5.send(myMessage, client_destination);
process_image();
time_of_last_shot = System.currentTimeMillis();
}
}
void process_image() {
println("Processing new image...");
// Set the image to start with..
start_img = imgcounter - num_images_to_use;
if(start_img<0) start_img = 0;
// Load images into memory
println("Loading "+imgcounter+"images...");
size(800, 600);
for (int i = 0; i < num_images_to_use && i < imgcounter; i = i+1)
img_array[i] = loadImage("imgs/frame_"+(i+start_img)+".jpg"); // Load an image into the array
println("Loading images...DONE");
// Draw images
println("Drawing "+imgcounter+" images...");
for (int i = 0; i < num_images_to_use && i < imgcounter; i = i+1) {
image(img_array[i], 0, 0);
}
println("Drawing images...DONE");
// Save the composite
latest_filename = "composites/tomisawesome_" + imgcounter + ".jpg";
saveFrame(latest_filename);
println("Processing new image...DONE");
}
1