We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
Answers
have you tried
scale(-1, 1);
for horizontal reflection?yes, yes you have, sorry.
ok, i'd recommend you remove the camera stuff and just load an image until you get it working, it'll be easier (and easier for those of us without a camera to replicate)
Yes I applied in some way as the examples above, but is not working
https://forum.Processing.org/two/discussion/15065/can-i-store-another-images-pixel-into-a-different-image-s-pixel-buffer#Item_1
ok, i did this using a generated image and your mirroring appears to work
i would recommend using a 320x240 camera if one's available, rather than downsizing the camera input 4 times.
(and that way you could use raw pixels to make things a bit more efficient - basically pixel[x, y] can be copied to pixel[x, 480 - y], pixel[640 - x, y] and pixel[640 - x][480 - y])
Thanks so much for your replies
GoToLoop, im going to try it.
Koogs, i tried it, but at the moment is not working... iI'm not familiar with Pgraphic but im gonna study it ... anyway, should I apply it in some way like this or it's totaly wrong (it says NullPointerException at graphEndDraw(); ) ?
Thanks Again
PGraphic just lets me create an image and draw on it (was easier to do that than rely on external dependencies like a camera or an image). it works just like an image, like your camera data.