Hello everyone, I'm still getting confidence with processing and I had some tryouts about pixel processing. I'm on this sketch, my camera is cameras[3], yours could be different:
import processing.video.*;
int i=1;
Capture cam;
PImage img;
int camX;
int camY;
void setup ()
{
size(800, 600, P3D);
frameRate(25);
img = createImage(width, height, RGB);
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(cameras[i]);
}
// The camera can be initialized directly using an
// element from the array returned by list():
cam = new Capture(this, 640, 480,cameras[3]);
cam.start();
}
}
void draw()
{
background(0,10);
if (cam.available() == true){
img.copy(cam, 0, 0, cam.width, cam.height, 0, 0, cam.width, cam.height);
img.updatePixels();
cam.read();
}
loadPixels();
cam.loadPixels();
img.loadPixels();
//pix process start
for (int index=0;index<width*height; index++)
{
int myPixel = pixels[index];
int r = myPixel >>24 & 0xFF;
int g = myPixel >>8 & 0xFF;
int b = myPixel >>4 & 0xFF;
int av = (r*2);
if (av>128){
r=av<<16;
g=av<<8;
b=av;
pixels[index]= r|g|b;
}
}
for (int y = 0; y<height; y+=1 ) {
for (int x = 0; x<width; x+=1) {
int loc = x + y*img.width;
float r = red (img.pixels[loc]);
float g = green (img.pixels[loc]);
float b = blue (img.pixels[loc]);
float av = ((r+g)/2.0);
pushMatrix();
translate(x,y);
if (b >10 && b < 15) {
stroke(0,g/random(.3),b/random(.6,.7),random(15,80));
line(0,0, random(-100,100), 0, 0, random(-100,100));
}
if (g >80 && g < 90) {
stroke(r/random(.5,.6),g/random(.3),b/random(.6,.7),random(200,255));
point(random(width/2)*.25,random(height/2)*.25, random(-10,10));
}
if (r >80 && r < 85) {
strokeWeight(random(.25,.95));
stroke(r/random(-.5,.5),g*(random(1.9)),b/random(b, 0),random(200,250));
point(random(width/2)*.25,random(height/2)*.25, random(-70,70));
stroke(r/random(5),g,b/random(.6));
noFill();
point(random(width/2)*.25,random(height/2)*.25, random(-10,10));
}
popMatrix();
//filter(BLUR,1);
}
}}
which gives out this framing:

What I want to do is to have something like this (mock up), so duplicate and mirror on 4 corners the single framing

I had different tryouts, I tried to work by objects and classes but it hasn't worked.
I tried to transform img.copy on line 38, but it can't mirror it.
import processing.video.*;
int i=1;
Capture cam;
PImage img;
int camX;
int camY;
void setup ()
{
frameRate(25);
size(800, 600, P3D);
img = createImage(width, height, RGB);
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(cameras[i]);
}
// The camera can be initialized directly using an
// element from the array returned by list():
cam = new Capture(this, 352, 288, cameras[3]);
cam.start();
}
}
void draw()
{
background(2);
if (cam.available() == true){
img.copy(cam, 0, 0, cam.width, cam.height, 0, 0, 400, 300);
img.copy(cam, 0, 0, cam.width, cam.height, 400, 0, 400, 300);
img.copy(cam, 0, 0, cam.width, cam.height, 0, 300, 400, 300);
img.copy(cam, 0, 0, cam.width, cam.height, 400, 300, 400, 300);
img.updatePixels();
cam.read();
}
loadPixels();
cam.loadPixels();
img.loadPixels();
//inizio algoritmo
for (int index=0;index<width*height; index++)
{
int myPixel = pixels[index];
int r = myPixel >>24 & 0xFF;
int g = myPixel >>8 & 0xFF;
int b = myPixel >>4 & 0xFF;
int av = (r*2);
if (av>128){
r=av<<16;
g=av<<8;
b=av;
pixels[index]= r|g|b;
}
}
for (int y = 0; y<height; y+=1 ) {
for (int x = 0; x<width; x+=1) {
int loc = x + y*img.width;
float r = red (img.pixels[loc]);
float g = green (img.pixels[loc]);
float b = blue (img.pixels[loc]);
float av = ((r+g)/2.0);
pushMatrix();
translate(x,y);
if (b >10 && b < 15) {
stroke(0,g/random(.3),b/random(.6,.7),random(15,80));
line(0,0, random(-100,100), 0, 0, random(-100,100));
}
if (g >80 && g < 90) {
stroke(r/random(.5,.6),g/random(.3),b/random(.6,.7),random(200,255));
point(random(width/2)*.25,random(height/2)*.25, random(-10,10));
}
if (r >80 && r < 85) {
strokeWeight(random(.25,.95));
stroke(r/random(-.5,.5),g*(random(1.9)),b/random(b, 0),random(200,250));
point(random(width/2)*.25,random(height/2)*.25, random(-50,50));
point(random(width/2)*.25,random(height/2)*.25, random(-10,10));
stroke(r/random(5),g,b/random(.6));
noFill();
point(random(width/2)*.25,random(height/2)*.25, random(-10,10));
}
popMatrix();
//filter(BLUR,1);
}
}}
I tried to quadruplicate and mirror the capture before process it, but it neither worked.
import processing.video.*;
Capture cam;
PImage img;
void setup() {
size(800, 600);
img = createImage(width, height, RGB);
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(cameras[i]);
}
// The camera can be initialized directly using an
// element from the array returned by list():
cam = new Capture(this, 640, 480,cameras[3]);
cam.start();
}
}
void draw() {
if (!cam.available()) return;
cam.read();
image(cam, 0, 0, 320, 240);
pushMatrix();
scale(-1,1);
image(cam, -640, 0, 320, 240);
popMatrix();
pushMatrix();
scale(1,-1);
image(cam, 0, -480, 320, 240);
popMatrix();
pushMatrix();
scale(-1,-1);
image(cam, -640, -480, 320, 240);
popMatrix();
img.updatePixels();
cam.read();
loadPixels();
cam.loadPixels();
img.loadPixels();
//inizio algoritmo
for (int index=0;index<width*height; index++)
{
int myPixel = pixels[index];
int r = myPixel >>24 & 0xFF;
int g = myPixel >>8 & 0xFF;
int b = myPixel >>4 & 0xFF;
int av = (r*2);
if (av>128){
r=av<<16;
g=av<<8;
b=av;
pixels[index]= r|g|b;
}
}
for (int y = 0; y<height; y+=1 ) {
for (int x = 0; x<width; x+=1) {
int loc = x + y*img.width;
float r = red (img.pixels[loc]);
float g = green (img.pixels[loc]);
float b = blue (img.pixels[loc]);
float av = ((r+g)/2.0);
pushMatrix();
translate(x,y);
if (b >10 && b < 15) {
stroke(0,g/random(.3),b/random(.6,.7),random(15,80));
line(0,0, random(-100,100), 0, 0, random(-100,100));
}
if (g >80 && g < 90) {
stroke(r/random(.5,.6),g/random(.3),b/random(.6,.7),random(200,255));
point(random(width/2)*.25,random(height/2)*.25, random(-10,10));
}
if (r >80 && r < 85) {
strokeWeight(random(.25,.95));
stroke(r/random(-.5,.5),g*(random(1.9)),b/random(b, 0),random(200,250));
point(random(width/2)*.25,random(height/2)*.25, random(-50,50));
point(random(width/2)*.25,random(height/2)*.25, random(-10,10));
stroke(r/random(5),g,b/random(.6));
noFill();
point(random(width/2)*.25,random(height/2)*.25, random(-10,10));
}
popMatrix();
//filter(BLUR,1);
}
}
}
It should be projected on real time, so I suppose I can't save frames and then work on them.
is there any suggestion? whats wrong with codes (I suppose a lot of things, but what's basic to run it properly)?
Thank you very much, Andrea