Hi, forgive me in advance if this is a dumb question to be asking, but i'm pretty new to the world of coding and i'm pretty much teaching myself from scratch.
Anyway, i have been playing around with Golan Levin's Frame Differencing sketch, and have altered it so that it displays the difference image on to a jpg, png ect. I have been trying to move this is on a bit by making the difference image transparent, so instead of displaying altered colour those difference area's would simply be transparent pixels. Unfortunately i have exhausted my limited abilities in trying to figure out why the alpha transparency doesn't change even though the colour does:
[code]
import codeanticode.gsvideo.*;
int numPixels;
int[] previousFrame;
// passondiff is where the video capture difference image is being saved
int[] passondiff;
// is the revised version of the difference image that should have black pixels that are transparent
int[] passondiffnoblack;
int movementSum = 0;
int noblackA = 0;
GSCapture video;
PImage img;
void setup() {
size(640, 480);
background(0, 0, 255);
img = loadImage("knightsmall.png");
img.format = ARGB;
video = new GSCapture(this, width, height);
video.start();
numPixels = img.width * img.height;
previousFrame = new int[numPixels];
passondiff = new int[numPixels];
passondiffnoblack = new int[numPixels];
loadPixels();
}
void draw() {
if (video.available()) {
video.read();
video.loadPixels();
int movementSum = 0;
for (int i = 0; i < numPixels; i++) {
color currColor = video.pixels[i];
color prevColor = previousFrame[i];
int currR = (currColor >> 16) & 0xFF;
int currG = (currColor >> 8) & 0xFF;
int currB = currColor & 0xFF;
int prevR = (prevColor >> 16) & 0xFF;
int prevG = (prevColor >> 8) & 0xFF;
int prevB = prevColor & 0xFF;
int diffR = abs(currR - prevR);
int diffG = abs(currG - prevG);
int diffB = abs(currB - prevB);
movementSum += diffR + diffG + diffB;
passondiff[i] = color(diffR, diffG, diffB);
previousFrame[i] = currColor;
}
for (int x = 0; x < img.width; x++) {
for (int y = 0; y < img.height; y++) {
int dif = x + y*img.width;
// extract the colours from the difference image
color noblack = passondiff[dif];
int noblackR = (noblack >> 16) & 0xFF;
int noblackG = (noblack >> 8) & 0xFF;
int noblackB = noblack & 0xFF;
// if the pixels colour is black then sent the alpha channel
passondiffnoblack[dif] = color (noblackR, noblackG, noblackB, noblackA);
}
}
for (int x = 0; x < img.width; x++) {
for (int y = 0; y < img.height; y++) {
int loc = x + y*img.width;
color imgColor = img.pixels[loc];
color thediff = passondiffnoblack[loc];
// extract the colour values of the jpg
int imgR = (imgColor >> 16) & 0xFF;
int imgG = (imgColor >> 8) & 0xFF;
int imgB = imgColor & 0xFF;
int imgA = (imgColor >> 24) & 0xFF;
//extract the updated colours of the difference image
int diffR = (thediff >> 16) & 0xFF;
int diffG = (thediff >> 8) & 0xFF;
int diffB = thediff & 0xFF;
int diffA = (thediff >> 24) & 0xFF;
// subtract the difference image from the jpg to get aa new difference image
int imgdiffR = abs(imgR - diffR);
int imgdiffG = abs(imgG - diffG);
int imgdiffB = abs(imgB - diffB);
int imgdiffA = abs(imgA - diffA);
pixels[loc] = color(imgR, imgG, imgB, imgdiffA);
}
}
if (movementSum > 0) {
updatePixels();
println(movementSum);
}
}
}
[/code]
I thought subtracting the non- transparent pixels (255) of the difference image from the non-transparent pixels of the png (255) would leave me with a transparent section where there meeting but obviously this not working and i cant think for the life of me why exactly it's not, so any input on this would much appreciated.
I am a university student and my current brief is to make a manifesto based around the idea of collaboration. What i'm trying to find out at the moment is, how collabrative communitys such as yourselves operate and some first hand views on what collaboration means to people who are actively involved in these communitys is.
Any views you could share with me would be much appreciated,
Look forward to reading your replies.