Issue with a video capture : NullPointerException

Hello !

I Want to use a sketch running an EXTERNE webcam (a logitech 310c). The sketch runs perfectly well with the built-in camera. But as soon as I plug and run the logitech webcam, I have the error message : NullPointerException for line 17 of the code below

String[] cameras = Capture.list();

To understand, I run the GettingStartedCapture.pde from the Video Library : I have the same error.

I try to run the sketch after disabling the built-in camera, I change the resolution of the webcam the lowest I can. I still have the =>NullPointerException

I use a MacBookPro OSX 10.9.5 and Processing 2.1.2

Does anybody here have encountered the same issue?

It would be a great help if someone could help me to understand. :)

Thank you very much. :)

Here is the code:

import processing.video.*;

Capture cam;
PImage pixelImage;  


float scalar = 2.2;
int offsetX = -10;
int offsetY = -10;


void setup(){

  size(1680, 900); // full screen
  noStroke();

  String[] cameras = Capture.list();

  if (cameras.length == 0) {
    println("There are no cameras available for capture."); // this relies on a camera.  no camera, no fun :(
    exit();
  } 
  else {
    println("Available cameras:");
    for (int i = 0; i < cameras.length; i++) {
      println(cameras[i]);
    }
    cam = new Capture(this, cameras[0]);
    cam.start();

    println("cam width " + cam.width);
  }
}


void draw(){

  // we are going to divide the drawing up into regions based on the pixels... 
  if (cam.available() == true) {
    cam.read();
  }

  pixelImage = cam;

  if(pixelImage.width != 0){
    scalar =1.4*(displayWidth/pixelImage.width);
  }
  //println("scalar" + scalar);
  int fiveTally = 0;

  int[] pVue;
  int tolerance = 5000;

  //image(pixelImage, 0, 0);

  float pixelDistort = 20;


  for(int m = 0; m<15000; m++){

    int randX = round(random(0, (pixelImage.width-40)/5))*5;
    int randY = round(random(0, (pixelImage.height-40)/5))*5;
    float randSize = 1.5;

    int c = pixelImage.get(randX, randY);

    drawRect(round(randX+random(0,5)), round(randY+random(0,5)), randSize, round(c));

  }

}

void drawRect(int xVal, int yVal, float w, color c){

  fill(c);
  rect((xVal*scalar)+offsetX, (yVal*scalar)+offsetY, w*scalar, w*scalar);

}

Answers

Sign In or Register to comment.