Webcam capture on Javascript mode don't work

edited December 2013 in JavaScript Mode

Hi guys, i'm trying to start webcam capture in Javascript mode but nothing happens. The script works on Processing but not in js mode. What can I do?

import processing.video.*;

color black = color(255);
color white = color(0);
int numPixels;
Capture video;

void setup() {
  size(1280, 960);
  strokeWeight(5);

  video = new Capture(this, width, height);

  video.start(); 

  numPixels = video.width * video.height;
  noCursor();
  smooth();
}

void draw() {
  if (video.available()) {
    video.read();
    video.loadPixels();
    int threshold = 140;
    float pixelBrightness; 
    loadPixels();
    for (int i = 0; i < numPixels; i++) {
      pixelBrightness = brightness(video.pixels[i]);
      if (pixelBrightness > threshold) { 
        pixels[i] = white; 
      } 
      else { 
        pixels[i] = black; // make it black
      }
    }
    updatePixels();

    int testValue = get(mouseX, mouseY);
    float testBrightness = brightness(testValue);
    if (testBrightness > threshold) { 
      fill(black); 
    } 
    else { // Otherwise,
      fill(white); 
    }

  }
}

Answers

  • Not much.

    You can't use any of the Java libraries with ProcessingJS. In other words: No import statements in your Processing code.

    HTML5 webcam support by the various browsers is still poor.

    See this tutorial for further help.

Sign In or Register to comment.