Hi!
I wonder how to get and display the average color between the frames of a movie on the one hand, and my webcam on the other hand.
I have tried to use Ben Fry's ColorSorting Example but couldn't make it work for both videos: only for the cam.
I know there must be a problem in my sketch but I am so unfamiliar with coding...
- void draw() {
- if (myMovie.available()) {
- myMovie.read();
- background(0);
- noStroke();
- int index = 0;
- int rtot = 0;
- int gtot = 0;
- int btot = 0;
- for (int j = 0; j < myMovie.height; j += increment) {
- for (int i = 0; i < myMovie.width; i += increment) {
- int pixelColor = myMovie.pixels[j*myMovie.width + i];
- int r = (pixelColor >> 16) & 0xff;
- int g = (pixelColor >> 8) & 0xff;
- int b = pixelColor & 0xff;
- rtot = rtot + r;
- gtot = gtot + g;
- btot = btot + b;
- index++;
- }
- }
- }
- if (myCapture.available()) {
- myCapture.read();
- background(0);
- noStroke();
- int index = 0;
- int rtot = 0;
- int gtot = 0;
- int btot = 0;
- for (int j = 0; j < myCapture.height; j += increment) {
- for (int i = 0; i < myCapture.width; i += increment) {
- int pixelColor = myCapture.pixels[j*myCapture.width + i];
- int r = (pixelColor >> 16) & 0xff;
- int g = (pixelColor >> 8) & 0xff;
- int b = pixelColor & 0xff;
- rtot = rtot + r;
- gtot = gtot + g;
- btot = btot + b;
- index++;
- }
- }
- rtot = rtot/index;
- gtot = gtot/index;
- btot = btot/index;
- myColor = color(rtot,gtot,btot);
- fill(myColor);
- rect(0,0,w,h);
- // Faster method of displaying pixels array on screen
- image(myMovie,0,0,myMovie.width/4,myMovie.height/4);
- image(myCapture,100,0,myCapture.width/4,myCapture.height/4);
- }
- }
Thanks a lot
1