[Kinect, OpenNI, Osceleton] How to create an ArrayList with floats and PImage?
in
Contributed Library Questions
•
1 year ago
Hi All,
How to create an ArrayList with float[] and PImage[] structures?
I want to associate each pointers from kinect Osceletor to your float position (x,y,z) and your image.
For example: headCoords has x, y and z position and an cerebral image associated.
My code return
NullPointerException...
Lets go:
I have a class Skeleton:
- class Skeleton {
- float headCoords[] = new float[3]
- float neckCoords[] = new float[3]
- PImage headImg[] = new PImage[1];
- PImage neckImg[] = new PImage[1];
- float[] allCoords[] = {headCoords, neckCoords};
- PImage[] orgaos[] = {headImg, neckImg}
- int id;
- Skeleton(int id) {
- this.id = id;
- }
- }
in main i have:
- import processing.opengl.*;
- import oscP5.*;
- import netP5.*;
- OscP5 oscP5;
- Hashtable<Integer, Skeleton> skels = new Hashtable<Integer, Skeleton>();
- void setup() {
- size(screen.height*4/3/2, screen.height/2, OPENGL); //Keep 4/3 aspect ratio, since it matches the kinect's.
- oscP5 = new OscP5(this, "127.0.0.1", 7110);
- hint(ENABLE_OPENGL_4X_SMOOTH);
- noStroke();
- }
- void oscEvent(OscMessage msg) {
- msg.print();
- if (msg.checkAddrPattern("/joint") && msg.checkTypetag("sifff")) {
- // We have received joint coordinates, let's find out which skeleton/joint and save the values ;)
- Integer id = msg.get(1).intValue();
- Skeleton s = skels.get(id);
- if (s == null) {
- s = new Skeleton(id);
- skels.put(id, s);
- }
- if (msg.get(0).stringValue().equals("head")) {
- s.headCoords[0] = msg.get(2).floatValue();
- s.headCoords[1] = msg.get(3).floatValue();
- s.headCoords[2] = msg.get(4).floatValue();
- s.headImg[0] = loadImage("data/1.png");
- }
- else if (msg.get(0).stringValue().equals("neck")) {
- s.neckCoords[0] = msg.get(2).floatValue();
- s.neckCoords[1] = msg.get(3).floatValue();
- s.neckCoords[2] = msg.get(4).floatValue();
- s.neckImg[0] = loadImage("data/2.png");
- }
- }
- else if (msg.checkAddrPattern("/new_user") && msg.checkTypetag("i")) {
- // A new user is in front of the kinect... Tell him to do the calibration pose!
- println("New user with ID = " + msg.get(0).intValue());
- }
- else if(msg.checkAddrPattern("/new_skel") && msg.checkTypetag("i")) {
- //New skeleton calibrated! Lets create it!
- Integer id = msg.get(0).intValue();
- Skeleton s = new Skeleton(id);
- skels.put(id, s);
- }
- else if(msg.checkAddrPattern("/lost_user") && msg.checkTypetag("i")) {
- //Lost user/skeleton
- Integer id = msg.get(0).intValue();
- println("Lost user " + id);
- skels.remove(id);
- }
- }
- void draw()
- {
- background(0);
- for (Skeleton s: skels.values()) {
- for (float[] j: s.allCoords) {
- for (PImage[] i: s.orgaos) {
- pushMatrix();
- translate(j[0]*width, j[1]*height, -j[2]*300);
- image(i[0], j[1], j[2]);
- popMatrix();
- }
- }
- }
- }
- }
Any suggestion?
This code is hacked from
https://github.com/Sensebloom/OSCeleton-examples/tree/master/processing/MotionCapture3D
best from brazil.
1