video transparency over a still image
in
Core Library Questions
•
11 months ago
Hi I'm working on writing a code that displays a still image that is disrupted by live video feed when someone gets within a certain distance of the af range finder. As the person gets within maximum closeness of the range finder the still image should be complete replaced with live video.
For some reason now the image and video play simultaneously, eventually the image is complete replaced by the live video.
processing code:
PImage img;
float offset = 0;
float easing = 0.05; //using sensor value distance to change its position. this program overlays one image over another by modifying the alpha value of the image with the tint() function.
import processing.video.*;
import processing.serial.*;
Capture video;
//int rangeAnalogPin= 0; //rangefinder
boolean showLiveVideo=false;
Serial serialPort;
int rangeVal;
void setup() {
size (displayWidth, displayHeight, P3D);
img = loadImage("art1.jpg"); //load image into program
// Setup VIDEO Capture
String[] cameras = Capture.list();
if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
}
else {
println("Available cameras:");
for (int i = 0; i < cameras.length; i++) {
println(i+" "+cameras[i]);
}
}
//video = new Capture(this, 640, 480);
video = new Capture(this, cameras[9]);
video.start();
// Setup SERIAL PORT
println(Serial.list());
String portName = Serial.list()[0];
serialPort = new Serial(this, portName, 9600);
}
void draw() {
// check for new range finder data
while ( serialPort.available() > 0) { // If data is available,
rangeVal = serialPort.read(); // read it and store it in val
//println(rangeVal);
}
// draw image
image(img, 0, 0, displayWidth, displayHeight);
// draw video image
tint(255, rangeVal); // display at half opacity
image(video, offset, 0, displayWidth, displayHeight);
}
void captureEvent(Capture c) {
c.read();
}
arduino code:
/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor.
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
*/
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
// Serial.println(map(sensorValue, 0, 545, 0, 255));
Serial.write(map(sensorValue, 0,255, 50, 450));
// send sensor value as number between 0 - 255
//Serial.write(sensorValue/4);
delay(100); // delay in between reads for stability
}
For some reason now the image and video play simultaneously, eventually the image is complete replaced by the live video.
processing code:
PImage img;
float offset = 0;
float easing = 0.05; //using sensor value distance to change its position. this program overlays one image over another by modifying the alpha value of the image with the tint() function.
import processing.video.*;
import processing.serial.*;
Capture video;
//int rangeAnalogPin= 0; //rangefinder
boolean showLiveVideo=false;
Serial serialPort;
int rangeVal;
void setup() {
size (displayWidth, displayHeight, P3D);
img = loadImage("art1.jpg"); //load image into program
// Setup VIDEO Capture
String[] cameras = Capture.list();
if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
}
else {
println("Available cameras:");
for (int i = 0; i < cameras.length; i++) {
println(i+" "+cameras[i]);
}
}
//video = new Capture(this, 640, 480);
video = new Capture(this, cameras[9]);
video.start();
// Setup SERIAL PORT
println(Serial.list());
String portName = Serial.list()[0];
serialPort = new Serial(this, portName, 9600);
}
void draw() {
// check for new range finder data
while ( serialPort.available() > 0) { // If data is available,
rangeVal = serialPort.read(); // read it and store it in val
//println(rangeVal);
}
// draw image
image(img, 0, 0, displayWidth, displayHeight);
// draw video image
tint(255, rangeVal); // display at half opacity
image(video, offset, 0, displayWidth, displayHeight);
}
void captureEvent(Capture c) {
c.read();
}
arduino code:
/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor.
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
*/
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
// Serial.println(map(sensorValue, 0, 545, 0, 255));
Serial.write(map(sensorValue, 0,255, 50, 450));
// send sensor value as number between 0 - 255
//Serial.write(sensorValue/4);
delay(100); // delay in between reads for stability
}
1