0.0.5 • Published 7 years ago

@v.kiniv/kinect-js v0.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
7 years ago

kinect.js

It is a communication bridge between Kinect and Web. kinect.js receive data from Kinect through Host Application(Server) deployed on Windows machine. The server listens for incoming connections on default 8181 port on all interfaces.

Setup

Include kinect.js library:

#!html

<script type="text/javascript" src="../src/kinect.js"></script>

Create client instance and call connect method:

#!js
var kinect = new Kinect();
kinect.connect(); // 127.0.0.1 by default

To be able to use helper module that provide connection state monitor, include helper.js:

#!html

<script type="text/javascript" src="../src/helper.js"></script>

Add state view container to body:

#!html
<body>
<div id="k_state_view" src="../assets/state_view.html"></div>
<!-- ... -->
</body>

Pass client instance to KinectHelper constructor:

#!js
var kinect = new Kinect();
var kinect_helper = new KinectHelper(kinect);
kinect.connect("192.168.0.1");

Events

TypeDescription
stateConnection or sensor state has changed.
gestureGesture detected.
bodiesTracked bodies data updated.

Event subscription

To start receiving Kinect events, register event listeners:

#!js
var kinect = new Kinect();
...
// Listen for gesture events
kinect.addEventListener("gesture", event => {
  if(event.gesture == "Swipe_Left") {
    // Do something
  }
});

// Listen for state events
kinect.addEventListener("state", event => {
  if(event.connected) {
    // Do something
  }
});

The server is aware of active event listeners and sends only needed events to the browser. For instance, if you do not need user skeleton data, do not leave empty bodies event listener, remove addEventListener statement. You can also unsubscribe from the event at runtime:

#!js
kinect.removeEventListener("bodies", func_ref);

State event

Sample

#!json
{
  "connected": true,
  "available": true,
  "trackedBodies": 2
}

Members

MemberDescription
connectedClient - Host WebSockets connection state.
availableHost - Kinect sensor connection state.
trackedBodiesNumber of bodies tracked by the sensor at the current time.

Gesture event

Sample

#!json
{
  "gesture": "ThumbUp",
  "body": {
    "isClosest": true,
    "trackingId": 72057594037930130
  }
}

Members

MemberDescription
gestureGesture name as stated in gestures database.
bodyCompact version of Body object.

Gestures list

Current default database contain basic gestures:

  • Swipe_Left
  • Swipe_Right
  • Tap
  • HandsUp
  • ThumbUp

List of gestures above is subject to change as it is related to Kinect gestures database used by the host application.

Bodies event

Sample

#!js
{
  "bodies": [{
          "trackingId": 72057594037928860,
          "isClosest:": true,
          "handLeftConfidence": "High",
          "handLeftState": "Open",
          "handRightConfidence": "High",
          "handRightState": "Lasso",
          "leanTrackingState": "Tracked",
          "lean": {
              "x": 0.0,
              "y": 0.0
          },
          "skeleton": {
            "Head": {
                  "pos": {
                      "x": 0.0,
                      "y": 0.0,
                      "z": 0.0,
                  },
                  "orient": {
                      "w": 0.0,
                      "x": 0.0,
                      "y": 0.0,
                      "z": 0.0,
                  },
                  "state": "Tracked"
              },
              "Neck": {
                  "pos": {
                      "x": 0.0,
                      "y": 0.0,
                      "z": 0.0,
                  },
                  "orient": {
                      "w": 0.0,
                      "x": 0.0,
                      "y": 0.0,
                      "z": 0.0,
                  },
                  "state": "Inferred"
              },
              // ... 25 joints total
          }
      },
      // ... up to 6 bodies total
  ],
  "floorClipPlane": {
     "w": 0.0,
     "x": 0.0,
     "y": 0.0,
     "z": 0.0,
  }
}

Members

MemberDescription
bodiesArray of Body objects, each represent tracked user skeleton.
floorClipPlaneVector4 object. Gets the floor clip plane of the body frame in hessian normal form. The (x,y,z) components are a unit vector indicating the normal of the plane, and w is the distance from the plane to the origin in meters.

Reference

Body

object

Properties

MemberTypeDescription
trackingIdlong integerUnique body ID.
isClosestbooleanIndicate whenever body is closest to the sensor.
handLeftConfidenceTrackingConfidenceLeft hand tracking confidence.
handLeftStateHandStateLeft hand state.
handRightConfidenceTrackingConfidenceRight hand tracking confidence.
handRightStateHandStateRight hand state.
leanTrackingStateTrackingStateLean tracking state.
leanPointThe lean vector of the body.
skeletonSkeletonArray of joints.

Skeleton

object

Represent joint position and orientation.

MemberTypeDescription
AnkleLeftJointLeft ankle
AnkleRightJointRight ankle
ElbowLeftJointLeft elbow
ElbowRightJointRight elbow
FootLeftJointLeft foot
FootRightJointRight foot
HandLeftJointLeft hand
HandRightJointRight hand
HandTipLeftJointTip of the left hand
HandTipRightJointTip of the right hand
HeadJointHead
HipLeftJointLeft hip
HipRightJointRight hip
KneeLeftJointLeft knee
KneeRightJointRight knee
NeckJointNeck
ShoulderLeftJointLeft shoulder
ShoulderRightJointRight shoulder
SpineBaseJointBase of the spine
SpineMidJointMiddle of the spine
SpineShoulderJointSpine
ThumbLeftJointLeft thumb
ThumbRightJointRight thumb
WristLeftJointLeft wrist
WristRightJointRight wrist

Joint

object

Represent joint position and orientation.

MemberTypeDescription
posCameraSpacePointJoint position.
orientVector4Joint orientation.
stateTrackingStateJoint tracking state.

Point

object

Represents point in 2D space.

MemberTypeDescription
xdoubleThe x-coordinate.
ydoubleThe y-coordinate.

CameraSpacePoint

object

Represents point in camera 3D space.

Camera space refers to the 3D coordinate system used by Kinect. The coordinate system is defined as follows:

  • The origin (x=0, y=0, z=0) is located at the center of the IR sensor on Kinect
  • X grows to the sensor’s left
  • Y grows up (note that this direction is based on the sensor’s tilt)
  • Z grows out in the direction the sensor is facing
  • 1 unit = 1 meter
MemberTypeDescription
xdoubleThe X coordinate of the point, in meters.
ydoubleThe Y coordinate of the point, in meters.
zdoubleThe Z coordinate of the point, in meters.

Vector4

object

The Vector4 structure is a flexible type that is used to represent a four component vector of skeleton or stream (color, depth, infrared) data. This structure is similar to the XMVECTOR structure in the XNA math library. Represents a 4-element (X,Y,Z,W) vector.

MemberTypeDescription
xdoubleThe x-coordinate.
ydoubleThe y-coordinate.
zdoubleThe z-coordinate.
wdoubleFor the floor plane, the w value is the distance from the plane to the origin.

HandState

enum

Possible hand states.

ValueDescription
ClosedThe hand is closed.
LassoThe hand is in the lasso state.
NotTrackedHand state is not tracked.
OpenThe hand is open.
UnknownThe state of the hand is unknown.

TrackingConfidence

enum
ValueDescription
HighFully tracked.
LowNot tracked.

TrackingState

enum
ValueDescription
InferredThe joint data is inferred and confidence in the position data is lower than if it were Tracked.
NotTrackedThe joint data is not tracked and no data is known about this joint.
TrackedThe joint data is being tracked and the data can be trusted.
0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago