Getting Average Pixel Color Value from a PImage that is constantly changing.
in
Contributed Library Questions
•
3 months ago
Hi Everyone,
I have a sketch that focuses a of a small section of what someone is wearing.
I have loaded this into a PImage and have successfully displayed it in the corner of my sketch, now I want to take the data from the PImage and get a running average of the color data.
I could do with a little help!
Regards,
Oli
import hypermedia.video.*;
import java.awt.Rectangle;
OpenCV opencv;
// contrast/brightness values
int contrast_value = 0;
int brightness_value = 0;
int adv = 0;
PImage c;
int average;
int total = 0;
void setup() {
size( 320, 240 );
opencv = new OpenCV( this );
opencv.capture( width, height ); // open video stream
opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT ); // load detection description, here-> front face detection : "haarcascade_frontalface_alt.xml"
}
public void stop() {
opencv.stop();
super.stop();
}
void draw() {
// grab a new frame
opencv.read();
opencv.contrast( contrast_value );
opencv.brightness( brightness_value );
// proceed detection
Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 );
// display the image
image( opencv.image(), 0, 0 );
// draw face area(s)
noFill();
stroke(255, 0, 0);
for ( int i=0; i<faces.length; i++ ) {
c = get(faces[i].x, faces[i].y+100, faces[i].width-20, faces[i].height-20 );
image(c, 0, 0);
}
}
}
1