1

I get this error whenever I run an example code from OpenKinect Kinect v1 example PointCloud.

 Unsatisfied link error: Unable to load library 'freenect': Native library (linux-arm/libfreenect.so) not found in resource path. 
A library relies on native code that's not available.

The OpenKinect library is made specifically for ARM Linux architecture and can be found here. The basic problem is that I don't think it is finding the libfreenect.so library correctly even though the library has it. I guess its not in the path.

See below for the example code that is being run (the importing of the library freenect.* is what I believe is causing the problem):

// Daniel Shiffman
// Kinect Point Cloud example

// https://github.com/shiffman/OpenKinect-for-Processing
// http://shiffman.net/p5/kinect/

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

// Kinect Library object
Kinect kinect;

// Angle for rotation
float a = 0;

// We'll use a lookup table so that we don't have to repeat the math over and over
float[] depthLookUp = new float[2048];

void setup() {
  // Rendering in P3D
  size(800, 600, P3D);
  kinect = new Kinect(this);
  kinect.initDepth();

  // Lookup table for all possible depth values (0 - 2047)
  for (int i = 0; i < depthLookUp.length; i++) {
    depthLookUp[i] = rawDepthToMeters(i);
  }
}

void draw() {

  background(0);

  // Get the raw depth as array of integers
  int[] depth = kinect.getRawDepth();

  // We're just going to calculate and draw every 4th pixel (equivalent of 160x120)
  int skip = 4;

  // Translate and rotate
  translate(width/2, height/2, -50);
  rotateY(a);

  for (int x = 0; x < kinect.width; x += skip) {
    for (int y = 0; y < kinect.height; y += skip) {
      int offset = x + y*kinect.width;

      // Convert kinect data to world xyz coordinate
      int rawDepth = depth[offset];
      PVector v = depthToWorld(x, y, rawDepth);

      stroke(255);
      pushMatrix();
      // Scale up by 200
      float factor = 200;
      translate(v.x*factor, v.y*factor, factor-v.z*factor);
      // Draw a point
      point(0, 0);
      popMatrix();
    }
  }

  // Rotate
  a += 0.015f;
}

// These functions come from: http://graphics.stanford.edu/~mdfisher/Kinect.html
float rawDepthToMeters(int depthValue) {
  if (depthValue < 2047) {
    return (float)(1.0 / ((double)(depthValue) * -0.0030711016 + 3.3309495161));
  }
  return 0.0f;
}

PVector depthToWorld(int x, int y, int depthValue) {

  final double fx_d = 1.0 / 5.9421434211923247e+02;
  final double fy_d = 1.0 / 5.9104053696870778e+02;
  final double cx_d = 3.3930780975300314e+02;
  final double cy_d = 2.4273913761751615e+02;

  PVector result = new PVector();
  double depth =  depthLookUp[depthValue];//rawDepthToMeters(depthValue);
  result.x = (float)((x - cx_d) * depth * fx_d);
  result.y = (float)((y - cy_d) * depth * fy_d);
  result.z = (float)(depth);
  return result;
}

EDIT Here is picture of what I am getting:

I always get this missing native code error

Eric Reyna
  • 181
  • 1
  • 3
  • 13
  • How do you call your code and how you set the property `java.library.path`? – SubOptimal Sep 20 '16 at 06:35
  • on Processing, I just click the run button and it runs it for me. It is able to successfully find and `import org.openkinect.processing.*;` but on importing the freenect library driver for the Kinect `import org.openkinect.freenect.*;` it gives that error. What do I need to do to see where my `java.library.path` is set? – Eric Reyna Sep 20 '16 at 13:11
  • Do you have```openkinect_processing/library/v1/linux-armv6hf/libfreenect.so``` ? If so, can you try copying/moving it to ```openkinect_processing/library/v1/linux-arm/libfreenect.so```, restarting Processing then trying to run the sketch again ? – George Profenza Sep 21 '16 at 10:46
  • In my `/Downloads/` folder I have the `openkinect_processing/library/v1/linux-armv6hf/libfreenect.so` that I downloaded from the link above that should work for the linux-arm boards. Are you saying I should place the project there or copy the file `libfreenect.so` and place it in Processing's library folder? – Eric Reyna Sep 21 '16 at 12:54
  • Yes, please: `/home/pi/sketchbook/libraries`. Let me know if that works – George Profenza Sep 21 '16 at 15:36
  • @EricReyna any joy ? – George Profenza Sep 22 '16 at 08:55
  • No dice. I put in `/home/pi/sketchbook/libraries/` and that didn't work. I created a new folder in the libraries folder called `linux-armv6hf` and placed the libfreenect.so from the open-kinect library I downloaded and tried and that did not work as well – Eric Reyna Sep 22 '16 at 14:23
  • See my updated picture for what I am getting – Eric Reyna Sep 22 '16 at 14:57
  • Can you please try adding this [libfreenect.so](https://github.com/shiffman/OpenKinect-for-Processing/raw/master/OpenKinect-Processing/lib/v1/linux-armv6hf/libfreenect.so) into ```/home/pi/sketchbook/libraries/openkinect_processing/library/v1/linux-arm``` , restarting Processing and trying to run the sketch again ? – George Profenza Sep 22 '16 at 17:01
  • I figured out what was wrong. I will add my answer below, you were on the right track George – Eric Reyna Sep 23 '16 at 18:05

2 Answers2

2

So it was a more simpler fix than I thought (isn't it always?) So I had to go to my /home/pi/sketchbook/libraries/ and delete any existing openKinect libraries. Then download the openKinect library zip file specifically made for the Raspberry Pi armv6hf boards and extract in into the /home/pi/sketchbook/libraries/. Then restart Processing and open it up the examples and then it found the library. Thanks George Profenza for the input.

Eric Reyna
  • 181
  • 1
  • 3
  • 13
0

I don't know Processing. But following should help to solve the problem.

To get your current java.library.path setting, you can print it with

System.out.println(System.getProperty("java.library.path"));

To specify it on command line

java -Djava.library.path=/your/additional/directory

The library must be in directory

/your/additional/directory/linux-arm/libfreenect.so

How to specify this property in Processing I cannot answer. But you should now be able to search for it.

edit: If your output is /usr/java/packages/lib/arm:/lib:/usr/lib then you could store the library for example as

/usr/lib/linux-arm/libfreenect.so
SubOptimal
  • 22,518
  • 3
  • 53
  • 69