Ask Your Question

Revision history [back]

Conflict between two OpenCV Processing commands

Hello there!

I get a NullPointerException when I am trying to run both findCannyEdges and the BackgroundSubstraction effect from this library.

When you comment out one of the two codelines that are conflicting, you can see the effects that I am trying to show next to one another.

I'm a bit stuck as to how I can solve this?

import gab.opencv.*;  
import processing.video.*;
Capture cam;

OpenCV opencv;
PImage edges, movement;

void setup() {
  size(1200, 760);

  //Start webcam capture
  cam = new Capture(this, 320, 240, 30);
  cam.start();

  opencv = new OpenCV(this, 320, 240);
  opencv.startBackgroundSubtraction(5, 3, 0.5);
}

void draw() {
  background(51);

  // Read webcam image
  if(cam.available()) {
    cam.read();
  }

  //Display depth map
  image(cam, 25, height*0.05, width/3, height/2);

  showMovement();
  showEdges();
}

void showEdges(){
  opencv = new OpenCV(this, cam); //THIS ONE CONFLICTS WITH updateBackground
  opencv.findCannyEdges(20,75);
  edges = opencv.getSnapshot();
  image(edges, width/3, height*0.05, width/3, height/2); 
}

void showMovement(){
  opencv.loadImage(cam);
  opencv.updateBackground(); //THIS ONE CONFLICTS WITH new OpenCV
  opencv.dilate();
  opencv.erode();
  noFill();
  stroke(255, 0, 0);
  strokeWeight(3);
  for (Contour contour : opencv.findContours()) {
    contour.draw();
  }  
}

// Called every time a new frame is available to read
void movieEvent(Movie m) {
  m.read();
}