1

I'm trying to run two Kinect V1 cameras simultaneously in Processing 3. I have gotten to a solution that is not sustainable, and am I trying to make something more stable/reliable.

At the moment, whenever I try to run both cameras simultaneously on a single sketch, I am hit with the error

"Could not claim interface on camera: -3 Failed to open camera subdevice or it is not disabled.Failed to open motor subddevice or it is not disabled.Failed to open audio subdevice or it is not disabled.There are no kinects, returning null"

One camera opens, the other does not. It is not always consistent which camera opens, which leads me to believe there's something tripping over permissions after the objects are created, or when the second object is initialized.

My code is as such

import SimpleOpenNI.*;
import org.openkinect.freenect.*;
import org.openkinect.freenect2.*;
import org.openkinect.processing.*;
import org.openkinect.tests.*;

//Imported libraries
//Some might be unnecessary but I don't have time to check
//Better safe than sorry, maybe I'll delete later

Kinect kinect;
Kinect kinect2;

PImage depthImage;
PImage depthImage2;

//Set depth threshold
float minDepth = 996;
float maxDepth = 2493;

float iWidth1 = 0;
float iHeight1 = 0;
float iWidth2 = 0;
float iHeight2 = 0;



//Double check for the number of devices, mostly for troubleshooting
int numDevices = 0;

//control which device is being controlled (in case I want device control)
int deviceIndex = 0;

void setup() {
  //set Arbitrary size
  size(640, 360);

  
  //Set up window to resize, need to figure out how to keep things centered
  surface.setResizable(true);
  
  //not necessary, but good for window management. Window label
  surface.setTitle("KINECT 1");
  
  //get number of devices, print to console
  numDevices = Kinect.countDevices();
  println("number of V1 Kinects = "+numDevices);
  
  //set up depth for the first kinect tracking
  kinect = new Kinect(this);
  kinect.initDepth();
  
  //Blank Image
  depthImage = new PImage(kinect.width, kinect.height);
  
  //set up second window
  String [] args = {"2 Frame Test"};
  SecondApplet sa = new SecondApplet();
  PApplet.runSketch(args, sa);
}

//Draw first window's Kinect Threshold
void draw () {
  
  if ((width/1.7778) < height) {
    iWidth1 = width;
    iHeight1 = width/1.7778;
  } else {
    iWidth1 = height*1.7778;
    iHeight1 = height;
  }
  
  //Raw Image
  image(kinect.getDepthImage(), 0, 0, iWidth1, iHeight1);
  
  //Threshold Equation
  int[] rawDepth = kinect.getRawDepth();
  for (int i=0; i < rawDepth.length; i++) {
    if (rawDepth[i] >= minDepth && rawDepth[i] <= maxDepth) {
    depthImage.pixels[i] = color(255);
  } else {
    depthImage.pixels[i] = color(1);
  }
 }
 
}

public class SecondApplet extends PApplet {
  
  public void settings() {
    //arbitrary size
    size(640, 360);
    
    kinect2 = new Kinect(this);
    kinect2.initDepth();
    
    //Blank Image
    depthImage2 = new PImage(kinect2.width, kinect2.height);
  }
  
  void draw () {
   
     if ((width/1.7778) < height) {
    iWidth2 = width;
    iHeight2 = width/1.7778;
  } else {
    iWidth2 = height*1.7778;
    iHeight2 = height;
  }
    
    image(kinect2.getDepthImage(), 0, 0, iWidth2, iHeight2);
    surface.setResizable(true);
    surface.setTitle("KINECT 2");
    
    int[] rawDepth2 = kinect2.getRawDepth();
    for (int i=0; i < rawDepth2.length; i++) {
      if (rawDepth2[i] >= minDepth && rawDepth2[i] <= maxDepth) {
      depthImage2.pixels[i] = color(255);
    } else {
      depthImage2.pixels[i] = color(1);
    }
  }
 }
}

Curiously, the code returns a confirmation that there are two kinect devices connected in the console. For some reason, it cannot access both at the same time.

I'm not a very experienced code, so this code might look amateur. Open to feedback on other parts, but really just looking to solve this problem.

This code returns the error pasted above when there are two Kinect V1's connected to the computer.

Running Mac OS11.6.8 on an Intel MacBook Pro

Using Daniel Schiffman's OpenKinect for Processing as a starting point for the code.

I've run a successful iteration of this code with a slimmed down version of Daniel Schiffman's Depth Threshold example.

import org.openkinect.freenect.*;
import org.openkinect.processing.*;

Kinect kinect;

// Depth image
PImage depthImg;

// Which pixels do we care about?
// These thresholds can also be found with a variaty of methods
float minDepth =  996;
float maxDepth = 2493;

// What is the kinect's angle
float angle;

void setup() {
  size(1280, 480);

  kinect = new Kinect(this);
  kinect.initDepth();
  angle = kinect.getTilt();

  // Blank image
  depthImg = new PImage(kinect.width, kinect.height);
}

void draw() {
  // Draw the raw image
  image(kinect.getDepthImage(), 0, 0);

  // Calibration
   //minDepth = map(mouseX,0,width, 0, 4500);
  //maxDepth = map(mouseY,0,height, 0, 4500);

  // Threshold the depth image
  int[] rawDepth = kinect.getRawDepth();
  for (int i=0; i < rawDepth.length; i++) {
    if (rawDepth[i] >= minDepth && rawDepth[i] <= maxDepth) {
      depthImg.pixels[i] = color(255);
    } else {
      depthImg.pixels[i] = color(0);
    }
  }

  // Draw the thresholded image
  depthImg.updatePixels();
  image(depthImg, kinect.width, 0);
  
  //Comment for Calibration
  fill(0);
  text("TILT: " + angle, 10, 20);
  text("THRESHOLD: [" + minDepth + ", " + maxDepth + "]", 10, 36);
  
  //Calibration Text
  //fill(255);
  //textSize(32);
  //text(minDepth + " " + maxDepth, 10, 64);
}

Using this code, I was able to get both cameras operating using the following process:

  1. Connect a single Kinect v1 to the computer
  2. Open and run the above code
  3. Duplicate the sketch file
  4. Connect the second Kinect V1 to the computer
  5. Open and run the duplicated sketch of the same code

This worked for my purposes and remained stable for an extended period of time. However, this isn't a sustainable solution if anyone other than me wants to utilize this program.

Any help with this problem would be greatly appreciated

Jatniel
  • 1,967
  • 2
  • 19
  • 27

0 Answers0