Java4Kinect检索3D关节坐标

时间:2017-09-10 05:39:59

标签: java arrays coordinates kinect kinect-sdk

我一直在尝试使用J4K来实现一个功能,允许我使用XBox 360检测到的人体手势来驱动机器人。目前,我正在尝试读取和打印X坐标右手,尽管能够检测骨骼,但只返回0.0。我也尝试用其他关节常数替换HAND_RIGHT,但无济于事。

这是我的myKinect类,它读取Kinect中的值:

package printTest;

import edu.ufl.digitalworlds.j4k.J4KSDK;
import edu.ufl.digitalworlds.j4k.Skeleton;

public class myKinect extends J4KSDK{

    int maxSkeletons = getMaxNumberOfSkeletons();

    Skeleton skeleton;

    @Override
    public void onColorFrameEvent(byte[] arg0) {    
    }

    @Override
    public void onDepthFrameEvent(short[] arg0, byte[] arg1, float[] arg2, float[] arg3) {  
    }

    @Override
    public void onSkeletonFrameEvent(boolean[] flags, float[] positions, float[] orientations, byte[] state) {
        System.out.print(".");
        for (int i = 0; i < maxSkeletons; i++) {
            skeleton = Skeleton.getSkeleton(i, flags, positions, orientations, state, this);

            if (flags[i]){
                skeleton.get3DJoint(Skeleton.HAND_RIGHT);
            }
        }       
    }
}

这是我的KinectPrint类,它打印出坐标值:

package printTest;

import edu.ufl.digitalworlds.j4k.J4KSDK;
import edu.ufl.digitalworlds.j4k.Skeleton;

public class KinectPrint {

    public static void main(String[] args) {
        myKinect kinect = new myKinect();
        kinect.start(J4KSDK.SKELETON);
        kinect.setSeatedSkeletonTracking(true);
        System.out.println("Initializing...");

        try {
            Thread.sleep(5000);
        } catch(InterruptedException e) {}

        float handX;
        for(int i = 0; i < 10; i++) {
            handX = kinect.skeleton.get3DJointX(Skeleton.HAND_RIGHT);
            System.out.println(handX);
            try {
                Thread.sleep(1000);
            } catch(InterruptedException e) {}
        }

        kinect.stop();
        System.out.println("Completed!");
    }
}

目前的输出是:

Initializing... ..........................................................................................................0.0 ..............................0.0 .............................0.0 ............................0.0 ..............................0.0 ..............................0.0 ..............................0.0 ..............................0.0 ..............................0.0 ..............................0.0 ..............................Completed!

0 个答案:

没有答案