Creating a "choose and zoom image" program
in
Core Library Questions
•
8 months ago
Good morning.
I'm a new user of Processing and also a new user in this forum.
I wanted to create a program in which if a person in front of a webcam raise his finger and touch a photo, the photo will zoom at the center of the screen.
Something like this (the person shoul not be displayed, of course):
Now, I have this code, and I wanted to create this project.
Could you give me a hand?
Thanks a lot.
I'm a new user of Processing and also a new user in this forum.
I wanted to create a program in which if a person in front of a webcam raise his finger and touch a photo, the photo will zoom at the center of the screen.
Something like this (the person shoul not be displayed, of course):
Now, I have this code, and I wanted to create this project.
Could you give me a hand?
Thanks a lot.
- import processing.video.*;
int numPixels;
int[] backgroundPixels;
int[] hist;
int[] histTop;
Capture video;
int pressed=0;
float presenceSum=0;
void setup() {
size(640, 480, P2D);
video = new Capture(this, width, height, 24);
numPixels = video.width * video.height;
backgroundPixels = new int[numPixels];
loadPixels();
}
void draw() {
if (video.available()) {
video.read();
video.loadPixels();
hist = new int[width];
float maxval = 0;
int maxposx=0;
int maxposy=0;
for (int i = 0; i < numPixels; i++) {
color currColor = video.pixels[i];
color bkgdColor = backgroundPixels[i];
float currR = red(currColor);
float currG = green(currColor);
float currB = blue(currColor);
float bkgdR = red(bkgdColor);
float bkgdG = green(bkgdColor);
float bkgdB = blue(bkgdColor);
float diffR = abs(currR - bkgdR);
float diffG = abs(currG - bkgdG);
float diffB = abs(currB - bkgdB);
if (diffR>20 && diffG>20 && diffB>20 && pressed==1){
pixels[i] = color(255, 255, 255);
presenceSum = presenceSum + 1;
}
else{
pixels[i] = color(0, 0, 0);
}
if(pressed==0){
pixels[i] = color(diffR, diffG, diffB);
}
}
updatePixels();
filter(ERODE);
filter(ERODE);
filter(ERODE);
filter(ERODE);
filter(ERODE);
if(pressed==1 && presenceSum>width*height/100){
for (int i=0; i<width; i++) {
for (int j=0; j<height; j++) {
if( int(red(get(i, j))) == 255 && int(green(get(i, j)))==255 && int(blue(get(i, j)))==255 )
hist[i]=hist[i]+1;
}
}
for (int i=0; i<width; i++) {
if(hist[i] > maxval) {
maxval = hist[i];
maxposx = i;
}
}
maxposy=height-int(maxval);
if(key=='g'){
//I want to put here the "choose image" program
background(127);
fill(0,0,255);
ellipse(width-maxposx,maxposy,50,50);
}
}
if(key=='v'){
for (int i = 1; i < width; i++) {
for (int j = 0; j < hist[i]; j++) {
color c = color(255, 0, 0);
set(i, j, c);
}
}
for (int i = maxposx-3; i < maxposx+4; i++) {
for (int j = 0; j < height; j++) {
color c = color(0, 255, 0);
set(i, j, c);
}
}
for (int j = height-int(maxval)-3; j < height-int(maxval)+4; j++) {
for (int i = 0; i < width; i++) {
color c = color(0, 255, 0);
set(i, j, c);
}
}
}
println(presenceSum);
}
}
void keyPressed() {
if(key==' '){
video.loadPixels();
arraycopy(video.pixels, backgroundPixels);
pressed=1;
}
}
1