For this week’s recitation, after the map() function workshop, I chose to attend the media manipulation workshop, as it was what aligned the most with my project. What I wanted to work on in this workshop, was to learn how to manipulate pixels in webcam.
Initially, I attempted to change directly the RGB colors in the webcam, as during the workshop I was told that there may not be the possibility of adding a filter to it (similar with an image). As this process wasn’t being effective in creating a negative image effect, I did some research and it was possible to add filters to webcam with cam.filter() function.
After adding an inverse black and white filter effect on the webcam, I also attempted to make the image brighter and darker by manipulating the HSB values of the pixels. It was quite challenging, however this media manipulation workshop provided me with a better head-start towards my project and allowed me to explore further ways in which pixels could be manipulated in webcam through processing.
The code was the following:
//int r = 50; //int g = 50; //int b = 50; import processing.video.*; Capture cam; //color invertColor( int r, int g, int b) { // return color(255 - r, 255 - g, 255 - b); //} void setup() { size(640, 480); colorMode(HSB); cam = new Capture(this, 640, 480); cam.start(); } void draw() { if (cam.available()) { cam.read(); image(cam, 0, 0); cam.filter(GRAY); cam.filter(INVERT); //background(invertColor(r,g,b)); } cam.loadPixels(); //Pixels, code with Arduino Distance Sensor noStroke(); int rectSize = 10; int w = cam.width; int h = cam.height; for (int y = 0; y < h; y+=rectSize) { for (int x = 0; x < w; x+=rectSize) { int i = x + y * w; fill( cam.pixels[i] ); rect(x, y, rectSize, rectSize); //for (int y = 0; y < h; y++) { // for (int x = 0; x < w; x++) { // int i = x + y*w; // *** IMPORTANT *** float b = brightness(cam.pixels[i]); float s = saturation(cam.pixels[i]); float u = hue(cam.pixels[i]); float ch = map(mouseX, 0, 255, height, width); cam.pixels[i] = color(u, s, b+ch); } cam.updatePixels(); } } // } //}