diwi / dLibs

processing/java - kinect library

Home Page:http://thomasdiewald.com/blog/?p=109

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Connecting more than 2 devices

orgicus opened this issue · comments

Hello,

I have just downloaded and tested the library. Currently I'm interested in using 3 or 4 devices, but ran into problems if I use more than 2. I've used a slightly modified version of the kinect_basic_multipleDevices example, but here's the output I've got with 3 devices:

=========================================================
  library: dLibs.freenect.*
  version: 02.25
  author : (c) thomas diewald

  openkinect-version(freenect.dll): "OpenKinect-libfreenect-v0.1.1-0-gdbfd4ce"
  tested on winXP-x86/x64, win7-x86/x64
=========================================================

#_KINECT_INFO____#
    message:    os.name              = Windows 7
    message:    sun.arch.data.model  = 32 bit
    message:    java.runtime.version = 1.6.0_24-b07
    message:    java.home            = C:\Users\T-bird\Desktop\AAC\processing\java

#_KINECT_INFO____#
    message:    LIBRARY LOADED
    message:    path = "C:\Users\T-bird\Documents\Processing\libraries\dLibs_freenect\library/windows32/freenect.dll"

#_KINECT_INFO____#
    message:    available devices: 3

#_KINECT_INFO____#
    on device:  0
    message:    created new device!

#_KINECT_INFO____#
    on device:  0
    message:    STARTED Thread: processeEvents(...)

#_KINECT_INFO____#
    on device:  1
    message:    created new device!

#_KINECT_INFO____#
    on device:  1
    message:    STARTED Thread: processeEvents(...)

#_KINECT_ERROR___#
    location:   dLibs.freenect.KinectCore.openDevice(Unknown Source)
    on device:  2
    message:    FAILED: open new device
    message:    native call returned: -1

#_KINECT_INFO____#
    on device:  2
    message:    STARTED Thread: processeEvents(...)

#_KINECT_WARNING_#
    location:   dLibs.freenect.KinectCore.setDepthFormat(Unknown Source)
    on device:  2
    message:    FAILED: set depth format
    message:    no device opened

#_KINECT_WARNING_#
    location:   dLibs.freenect.KinectCore.setDepthBuffer(Unknown Source)
    on device:  2
    message:    FAILED: set depth buffer
    message:    no device opened

#_KINECT_WARNING_#
    location:   dLibs.freenect.KinectCore.startDepth(Unknown Source)
    on device:  2
    message:    FAILED: start depth
    message:    no device opened

#_KINECT_WARNING_#
    location:   dLibs.freenect.KinectCore.stopDepth(Unknown Source)
    on device:  2
    message:    FAILED: stop depth
    message:    no device opened

#_KINECT_WARNING_#
    location:   dLibs.freenect.KinectCore.closeDevice(Unknown Source)
    on device:  2
    message:    FAILED: close device
    message:    device already closed

#_KINECT_INFO____#
    on device:  1
    message:    closed device!

#_KINECT_INFO____#
    on device:  0
    message:    closed device!

#_KINECT_DEBUG___#
    location:   dLibs.freenect.Kinect.shutDown(Unknown Source)
    message:    KINECT SHUTDOWN
ERROR in libusbemu -- source file 'libusbemu.cpp' at line 257 -- libusb0-dll:err [set_configuration] could not set config 1: win error: A device attached to the system is not functioning.


Could not claim interface on camera: -99

and for reference here's the sketch code:

//---------------------------------------------
//
// author: thomas diewald
// date:   29.07.2011
// 
//---------------------------------------------
// note: sometimes, the kinects depth/video wont start at the very first run,
//       in this case, just re-start the sketch!

import dLibs.freenect.toolbox.*;
import dLibs.freenect.constants.*;
import dLibs.freenect.interfaces.*;
import dLibs.freenect.*;


//-------------------------------------------------------------------
int device_count = 0;
int kinectFrame_size_x = VIDEO_FORMAT._RGB_.getWidth();   // width of kinect frame
int kinectFrame_size_y = VIDEO_FORMAT._RGB_.getHeight();  // height of kinect frame

Kinect kinect_[];                     // main kinect-object
KinectFrameDepth kinect_depth_[];     // depth frame
//-------------------------------------------------------------------

PImage depth_frame_[];  // images



void setup(){
  device_count = Kinect.count();

  KinectLogger.log(KinectLogger.TYPE.INFO, null, "available devices: "+device_count );
  size(kinectFrame_size_x*device_count, kinectFrame_size_y);

  kinect_       = new Kinect[device_count];
  kinect_depth_ = new KinectFrameDepth[device_count];
  depth_frame_  = new PImage[3];

  for(int i = 0; i < device_count; i++){
    kinect_[i] = new Kinect(i);                                       // create the main device-instance
    kinect_depth_[i] = new KinectFrameDepth(DEPTH_FORMAT._11BIT_);    // create a depth instance

    kinect_depth_[i].connect(kinect_[i]);  //connect the created depth instance to the main kinect

    kinect_depth_[i].setFrameRate(30);  // default is set to 60, which will be changed in the next update

    depth_frame_[i] = createImage(DEPTH_FORMAT._11BIT_.getWidth(), DEPTH_FORMAT._11BIT_   .getHeight(), RGB);
  }

}

//-------------------------------------------------------------------
void draw(){
  for(int i = 0; i < device_count; i++){
    assignPixels( depth_frame_[i], kinect_depth_[i]);
    image(depth_frame_[i], kinectFrame_size_x*i, 0);
  }
  //println(frameRate);
}


//-------------------------------------------------------------------
void assignPixels(PImage img, Pixelable kinect_dev){
  img.loadPixels();
    img.pixels = kinect_dev.getPixels();  // assign pixels of the kinect device to the image
  img.updatePixels();
}


//-------------------------------------------------------------------
// this is maybe not necessary, but is the proper way to close everything
void dispose(){
  Kinect.shutDown(); 
  super.dispose();
}

Any tips/hints on how I could get past this issue ?

Also, a bit off topic - does this library expose accelerometer values ?

hey,

i actually never had the chance to test 3 kinects, but i thought, if 2 are working then 3 should too.
the log says, that 3 devices are recognized, but then the error is thrown in the "libusbemu" file.
i assume, you testet each cam separately to make sure, none of them is broken ?!

people reported the same/similar issue here:
https://forum.processing.org/topic/multiple-kinects-with-dlibs-freenect-library
https://forum.processing.org/topic/kinect-library-dlibs-freenect

it turned out, that either, they didn't plug in the power-supply (or it was broken), or had to choose a different USB-port for each device. in your case i think its the later.

you can get the accelerometer values by instancing and connecting a new KinectTilt-object and call "getOrientation()",
i know, a bit misleading naming.
https://github.com/diwi/dLibs/blob/dLibs/dLibs_freenect/src/dLibs/freenect/KinectTilt.java#L79

hth,
thomas

Hi,

Thanks for the quick reply.

I had a look at both posts. I tried with 3 devices on a macbook with 2 usb ports and 1 usb hub (with it's separate power supply) but had no luck. Today I tested the code posted here on a friend's pc laptop ( a pretty good one (8GB ram, 8 i7 cores, 1.5 GB NVidia card) which has 4 separate USB ports ). I did try to plug in/out all kinects to test if each work individually, then gradually added one more kinect. With two kinects the sketch runs, although the second depth image updates a lot slower, but with three, either the sketch crashes (none work), either two work and the third doesn't initialize.

I've got a poorly recorded screencast here: http://screencast.com/t/QiZPivTR

I'll give it another shot later today and probably record a better screencast and post all errors/warning (as indicated in the Processing forum post)

Thanks for the accelerometer tip, it will come in handy !

try to run the following code. its the minimun to initialize a kinect device.

//------------------ PROCESSING/JAVA CODE ----------------------------------

import dLibs.freenect.toolbox.;
import dLibs.freenect.constants.
;
import dLibs.freenect.interfaces.;
import dLibs.freenect.
;

void setup(){
size(100, 100);

KinectLogger.TYPE.INFO .active(true);
KinectLogger.TYPE.DEBUG .active(true);
KinectLogger.TYPE.WARNING.active(true);
KinectLogger.TYPE.ERROR .active(true);

int device_count = Kinect.count();
KinectLogger.log(KinectLogger.TYPE.INFO, null, "USER_MSG: available devices: "+device_count );
Kinect[] kinect = new Kinect[device_count];

for(int i = 0; i < device_count; i++){
kinect[i] = new Kinect(i);
}
}

void draw(){
}

void dispose(){
Kinect.shutDown();
super.dispose();
}

//------------------/ PROCESSING/JAVA CODE ----------------------------------

(question of mine, how did you format the inserted code????)

so, if you dont get any errors, well, than try to connect depth instances (with a very low framerate, just for testing).
if you still get the "ERROR in libusbemu" than i still think it has to do with the USB-ports/hubs.
found your issue-report: OpenKinect/libfreenect#269
zarvox mentioned:" ... putting all the Kinects on separate root hubs ..." this might be it.

another thing, in your video, it seems that you have 2 devices pointing in the same direction. this causes an interference of the infrared-pattern, which will result in a poor quality of the depthmap. so this should be avoided in any case.

another thing to test:
you could try to slow down the process of instancing the devices, ... so init the first device( in setup),... then, let pass a view frames (or a view hundred milliseconds) and start the next device(in draw), and so on. i dont know if this has any effect, but i think its worth a try.

Hi,

Thank you very much for the detailed explanations.
Unfortunately I don't have access to many kinects all the time, so I couldn't test the other day.

With the test code above I still get the error on 1 device, which isn't a good sign:



=========================================================
  library: dLibs.freenect.*
  version: 02.25
  author : (c) thomas diewald

  openkinect-version(freenect.dll): "OpenKinect-libfreenect-v0.1.1-0-gdbfd4ce"
  tested on winXP-x86/x64, win7-x86/x64
=========================================================

#_KINECT_INFO____#
    message:    os.name              = Windows 7
    message:    sun.arch.data.model  = 32 bit
    message:    java.runtime.version = 1.6.0_24-b07
    message:    java.home            = C:\Users\T-bird\Desktop\AAC\processing\java

#_KINECT_INFO____#
    message:    LIBRARY LOADED
    message:    path = "C:\Users\T-bird\Documents\Processing\libraries\dLibs_freenect\library/windows32/freenect.dll"

#_KINECT_INFO____#
    message:    USER_MSG: available devices: 3

#_KINECT_INFO____#
    on device:  0
    message:    created new device!

#_KINECT_INFO____#
    on device:  0
    message:    STARTED Thread: processeEvents(...)

#_KINECT_INFO____#
    on device:  1
    message:    created new device!

#_KINECT_INFO____#
    on device:  1
    message:    STARTED Thread: processeEvents(...)

#_KINECT_ERROR___#
    location:   dLibs.freenect.KinectCore.openDevice(Unknown Source)
    on device:  2
    message:    FAILED: open new device
    message:    native call returned: -1

#_KINECT_INFO____#
    on device:  2
    message:    STARTED Thread: processeEvents(...)

#_KINECT_WARNING_#
    location:   dLibs.freenect.KinectCore.closeDevice(Unknown Source)
    on device:  2
    message:    FAILED: close device
    message:    device already closed

#_KINECT_INFO____#
    on device:  1
    message:    closed device!

#_KINECT_INFO____#
    on device:  0
    message:    closed device!

#_KINECT_DEBUG___#
    location:   dLibs.freenect.Kinect.shutDown(Unknown Source)
    message:    KINECT SHUTDOWN
ERROR in libusbemu -- source file 'libusbemu.cpp' at line 257 -- libusb0-dll:err [set_configuration] could not set config 1: win error: A device attached to the system is not functioning.


Could not claim interface on camera: -99

Sorry I didn't mention the issue opened on OpenKinect/libfreenect, should've mentioned that first.
I thought that using a machine with 4 usb ports would solve the issue, but then again, odds are each
port might not use a separate root hub.

I'm done the test suggested with instancing devices at an interval.
Here's the output:

=========================================================
  library: dLibs.freenect.*
  version: 02.25
  author : (c) thomas diewald

  openkinect-version(freenect.dll): "OpenKinect-libfreenect-v0.1.1-0-gdbfd4ce"
  tested on winXP-x86/x64, win7-x86/x64
=========================================================

#_KINECT_INFO____#
    message:    os.name              = Windows 7
    message:    sun.arch.data.model  = 32 bit
    message:    java.runtime.version = 1.6.0_24-b07
    message:    java.home            = C:\Users\T-bird\Desktop\AAC\processing\java

#_KINECT_INFO____#
    message:    LIBRARY LOADED
    message:    path = "C:\Users\T-bird\Documents\Processing\libraries\dLibs_freenect\library/windows32/freenect.dll"

#_KINECT_INFO____#
    message:    USER_MSG: available devices: 3

Initializing device: 0


#_KINECT_INFO____#
    on device:  0
    message:    created new device!

#_KINECT_INFO____#
    on device:  0
    message:    STARTED Thread: processeEvents(...)

Initializing device: 1


#_KINECT_INFO____#
    on device:  1
    message:    created new device!

#_KINECT_INFO____#
    on device:  1
    message:    STARTED Thread: processeEvents(...)

Initializing device: 2


#_KINECT_ERROR___#
    location:   dLibs.freenect.KinectCore.openDevice(Unknown Source)
    on device:  2
    message:    FAILED: open new device
    message:    native call returned: -1

#_KINECT_INFO____#
    on device:  2
    message:    STARTED Thread: processeEvents(...)

#_KINECT_WARNING_#
    location:   dLibs.freenect.KinectCore.setDepthFormat(Unknown Source)
    on device:  2
    message:    FAILED: set depth format
    message:    no device opened

#_KINECT_WARNING_#
    location:   dLibs.freenect.KinectCore.setDepthBuffer(Unknown Source)
    on device:  2
    message:    FAILED: set depth buffer
    message:    no device opened

#_KINECT_WARNING_#
    location:   dLibs.freenect.KinectCore.startDepth(Unknown Source)
    on device:  2
    message:    FAILED: start depth
    message:    no device opened
ERROR in libusbemu -- source file 'libusbemu.cpp' at line 257 -- libusb0-dll:err [set_configuration] could not set config 1: win error: A device attached to the system is not functioning.


Could not claim interface on camera: -99

Here's my test code:

import dLibs.freenect.toolbox.*;
import dLibs.freenect.constants.*;
import dLibs.freenect.interfaces.*;
import dLibs.freenect.*;

int initInterval = 3000;
int now;

int device_count;
Kinect[] kinect;
int kinectID = 0;

KinectFrameDepth kinect_depth_[];     // depth frame
PImage depth_frame_[];  // images

void setup() {
  size(640, 480);
  frameRate(12);
  KinectLogger.TYPE.INFO .active(true);
  KinectLogger.TYPE.DEBUG .active(true);
  KinectLogger.TYPE.WARNING.active(true);
  KinectLogger.TYPE.ERROR .active(true);

  device_count = Kinect.count();
  KinectLogger.log(KinectLogger.TYPE.INFO, null, "USER_MSG: available devices: "+device_count );
  kinect = new Kinect[device_count];
  kinect_depth_ = new KinectFrameDepth[device_count];
  depth_frame_  = new PImage[device_count];

  now = millis();
}

void draw() {
  if(millis() - now >= initInterval){
    now = millis();
    if(kinectID < device_count){
      if(kinect[kinectID] == null) {
        println("\nInitializing device: " + kinectID+"\n");
        kinect[kinectID] = new Kinect(kinectID);
        kinect_depth_[kinectID] = new KinectFrameDepth(DEPTH_FORMAT._11BIT_); 
        kinect_depth_[kinectID].connect(kinect[kinectID]);  //connect the created depth instance to the main kinect
        kinect_depth_[kinectID].setFrameRate(12);  // default is set to 60, which will be changed in the next update
        depth_frame_[kinectID] = createImage(DEPTH_FORMAT._11BIT_.getWidth(), DEPTH_FORMAT._11BIT_   .getHeight(), RGB);
        kinectID++;
      }
    } 
  }
  int i = 0;
  if(depth_frame_[i] != null &&  kinect_depth_[i] != null){
    assignPixels( depth_frame_[i], kinect_depth_[i]);
    image(depth_frame_[i],0,0);
  }
}

void assignPixels(PImage img, Pixelable kinect_dev){
  img.loadPixels();
    img.pixels = kinect_dev.getPixels();  // assign pixels of the kinect device to the image
  img.updatePixels();
}

void dispose() {
  Kinect.shutDown();
  super.dispose();
}

Any tips on how to get more root hubs would be handy.

Thanks again for the support !

Hi,

Sorry about the huge delay. The problem was indeed usb bandwidth usage and was reslved
installing a PCI card with 4 extra ports powered directly from the PSU (not via the motherboard).

I can confirm that the library works fine with 3 kinects :)