We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I'm (really) new with processing. Can anyone help me with this code? please :) I cannot find why I get unexpected token: void() in this code:
import processing.video.*; Capture webcam; int w=400; int h=400; int pixn=w*h; int keyhits; PImage img; int i= 0
void setup() { size(w, h); webcam = new Capture(this, 400, 400); webcam.start(); loadPixels(); }
void captureEvent(Capture webcam) { webcam.read(); } void draw() { image(webcam, 0, 0); }
void keyPressed() {
if ( key == '1' ) { save("capture" + ++keyhits + ".jpg"); }
img = loadImage("capture"+keyhits+".jpg"); int x = int(img.width); int y = int(img.height); float r = red(img.pixels[i]); float g = green(img.pixels[i]); float b = blue(img.pixels[i]);
for (int i=0; i<pixn; i++) { float sumar = sumar + red(img.pixels[i]); float sumag = sumag + green(img.pixels[i]); float sumab = sumab + blue(img.pixels[i]); }
float mediar = sumar / pixn); float mediag = sumag / pixn); float mediab = sumab / pixn);
if ( key == '2' ) { fill(mediar, mediag, mediab, 255); rect(0, 0, 400, 400); save("average_color"+ keyhits + ".jpg"); } }
Answers
First of all you need to learn to format your code for this forum. Look here
There are several errors in your code. The first is in line 8 where the statement
int i = 0
needs a semicolonThen the variables sumar, sumag and sumab are declared local to the for loop and have not been initialised before use.
Then you have extra unneeded
)
The corrected code looks like
And you haven't formatted the code properly.
Many thanks, Lord_of_the_Galaxy!;