Quantcast
Channel: Kinect - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 530

expecting Rcurly, found 'else' (Kinect Physics Tutorial for Processing)

$
0
0

Good afternoon and merry christmas.

I'm trying to do the Kinect Physics Tutorial for Processing, using processing 1.5.1.

creativeapplications.net/processing/kinect-physics-tutorial-for-processing/

But when i try to run, the programm send me and error saying " expecting Rcurly, found 'else'

The error:

THE CODE IS:

import processing.opengl.*; // opengl

import SimpleOpenNI.*; // kinect

import blobDetection.*; // blobs

import java.awt.Polygon;

SimpleOpenNI context;

BlobDetection theBlobDetection;

PolygonBlob poly = new PolygonBlob();

PImage cam, blobs;

int kinectWidth = 640;

int kinectHeight = 480;

float reScale;

color bgColor; String[] palettes = { "-1117720,-13683658,-8410437,-9998215,-1849945,-5517090,-4250587,-14178341,-5804972,-3498634", "-67879,-9633503,-8858441,-144382,-4996094,-16604779,-588031", "-16711663,-13888933,-9029017,-5213092,-1787063,-11375744,-2167516,-15713402,-5389468,-2064585" };

Particle[] flow = new Particle[2250]; float globalX, globalY;

void setup() { size(1280, 720, OPENGL); context = new SimpleOpenNI(this); if (!context.enableScene()) { println("Kinect not connected!"); exit(); } else { context.setMirror(true); reScale = (float) width / kinectWidth; blobs = createImage(kinectWidth/3, kinectHeight/3, RGB); theBlobDetection = new BlobDetection(blobs.width, blobs.height); theBlobDetection.setThreshold(0.2); setupFlowfield(); } }

void draw() { noStroke(); fill(bgColor, 65); rect(0, 0, width, height); context.update(); cam = context.sceneImage().get(); blobs.copy(cam, 0, 0, cam.width, cam.height, 0, 0, blobs.width, blobs.height); blobs.filter(BLUR); theBlobDetection.computeBlobs(blobs.pixels); poly.reset(); poly.createPolygon(); drawFlowfield(); }

void setupFlowfield() { strokeWeight(2.5); for (int i=0; i<flow.length; i++) { flow[i] = new Particle(i/10000.0); } setRandomColors(1); }

void drawFlowfield() { translate(0, (height-kinectHeight*reScale)/2); scale(reScale); globalX = noise(frameCount * 0.01) * width/2 + width/4; globalY = noise(frameCount * 0.005 + 5) * height; for (Particle p : flow) { p.updateAndDisplay(); } setRandomColors(240); }

void setRandomColors(int nthFrame) { if (frameCount % nthFrame == 0) { String[] paletteStrings = split(palettes[int(random(palettes.length))], ","); color[] colorPalette = new color[paletteStrings.length]; for (int i=0; i<paletteStrings.length; i++) { colorPalette[i] = int(paletteStrings[i]); } bgColor = colorPalette[0]; for (int i=0; i<flow.length; i++) { flow[i].col = colorPalette[int(random(1, colorPalette.length))]; } } }

class Particle { float id, x, y, xp, yp, s, d; color col; // color

Particle(float id) { this.id = id; s = random(2, 6); // speed }

void updateAndDisplay() { id += 0.01; d = (noise(id, x/globalY, y/globalY)-0.5)globalX; x += cos(radians(d))s; y += sin(radians(d))*s;

if (x<-10) x=xp=kinectWidth+10;
if (x>kinectWidth+10) x=xp=-10;
if (y<-10) y=yp=kinectHeight+10;
if (y>kinectHeight+10) y=yp=-10;

if (poly.npoints > 0) {
  if (!poly.contains(x, y)) {
    while (!poly.contains (x, y)) {
      x = random(kinectWidth);
      y = random(kinectHeight);
    }
    xp=x;
    yp=y;
  }
}

stroke(col);
line(xp, yp, x, y);

xp=x;
yp=y;

} }

class PolygonBlob extends Polygon { void createPolygon() { ArrayList contours = new ArrayList(); int selectedContour = 0; int selectedPoint = 0;

for (int n=0 ; n<theBlobDetection.getBlobNb(); n++) {
  Blob b = theBlobDetection.getBlob(n);
  ArrayList contour = new ArrayList();
  for (int m=0; m<b.getEdgeNb(); m++) {
    if (contour.size() > 0) {
      contour.add(new PVector(eB.x*kinectWidth, eB.y*kinectHeight));
      contours.add(contour);
      contour = new ArrayList();
    }
    else {
      contour.add(new PVector(eA.x*kinectWidth, eA.y*kinectHeight));
    }
    else {
      contour.add(new PVector(eA.x*kinectWidth, eA.y*kinectHeight));
    }
  }
}

} }

while (contours.size () > 0) {

float distance = 999999999; if (npoints > 0) { PVector lastPoint = new PVector(xpoints[npoints-1], ypoints[npoints-1]); for (int i=0; i<contours.size(); i++) { ArrayList c = contours.get(i); PVector fp = c.get(0); PVector lp = c.get(c.size()-1); if (fp.dist(lastPoint) < distance) { distance = fp.dist(lastPoint); selectedContour = i; selectedPoint = 0; } if (lp.dist(lastPoint) < distance) { distance = lp.dist(lastPoint); selectedContour = i; selectedPoint = 1; } } } else { PVector closestPoint = new PVector(width, height); for (int i=0; i<contours.size(); i++) { ArrayList c = contours.get(i); PVector fp = c.get(0); PVector lp = c.get(c.size()-1); if (fp.y > kinectHeight-5 && fp.x < closestPoint.x) { closestPoint = lp; selectedContour = i; selectedPoint = 1; } } }

ArrayList contour = contours.get(selectedContour); if (selectedPoint > 0) { Collections.reverse(contour); } for (PVector p : contour) { addPoint(int(p.x), int(p.y)); } contours.remove(selectedContour); } } }


Viewing all articles
Browse latest Browse all 530

Trending Articles