This site requires JavaScript, please enable it in your browser!
Greenfoot back
s.hartmann
s.hartmann wrote ...

2012/3/1

Kinect for Windows

s.hartmann s.hartmann

2012/3/1

#
Hi everybody, has someone already connected the new Kinect for Windows to Greenfoot successfully? Thank you Steffen
pluess pluess

2012/4/28

#
Hi, You can connect the new Kinect for Windows (and the former Kinect for Xbox360) with Greenfoot by using our KinectJLib library (download from http://www.aplu.ch/kinect ). Only PCs under Windows 7 are supported. It is based on Microsoft's official Kinect for Windows distribution (not the OpenKinect software). A typical "Painter" scenario is pretty easy to program. First extend World by the KinectWorld class:
// KinectWorld.java
// Include in BlueJ preferences, tab 'Libraries':
//   jaw.jar
//   KinectJLib.jar
// KinectHandler.dll (or for 64-bit Java: KinectHandler64.dll) must reside in path, e.g. c:\windows

import greenfoot.*;
import ch.aplu.jaw.*;
import ch.aplu.kinect.*;

public class KinectWorld extends World
{
  String dllPath =  Kinect.is64bit()? "KinectHandler64" : "KinectHandler";
  String title = "Greenfoot Kinect Video Frame - Paint with your right hand - Raise left hand to erase";
  int ulx = 10; // Upper left x of window
  int uly = 20; // Upper left y of window
  int width = 600;  // Width of window in pixels
  int height = 400; // Height of window in pixels
  static int xRightHand = 1000;
  static int yRightHand = 1000;
  static int yLeftHand = 1000;

  public KinectWorld()
  {    
    super(600, 400, 1); 
    Painter p = new Painter();
    addObject(p, 300, 200);
    Greenfoot.setSpeed(50);
    Greenfoot.start();
    new Thread()
    {
        public void run()
        {
          runKinect();
        }
    }.start();
  }
  
  void runKinect()
  {
    Kinect kinect = new Kinect(dllPath, title, ulx, uly, width, height,
        NativeHandler.WS_BORDER | NativeHandler.WS_VISIBLE);  
    Point3D[] joints = new Point3D[20];
    for (int i = 0; i < 20; i++)
      joints[i] = new Point3D();
    while (true)
    {
      int skeletonId = kinect.getJoints(joints, 20);  // Blocks max 200 ms
      if (skeletonId > -1)  // Valid skeleton
      {
        int rightHandIndex = SkeletonJoint.HAND_RIGHT.ordinal();
        xRightHand = joints[rightHandIndex].x;
        yRightHand = joints[rightHandIndex].y;
        int leftHandIndex = SkeletonJoint.HAND_LEFT.ordinal();
        yLeftHand = joints[leftHandIndex].y;
      }
      else  // No valid skeleton
      {
        xRightHand = 1000;
        yRightHand = 1000;
        yLeftHand = 1000;
      }
    }
  }
}   
and derived from Actor
// Painter.java

import greenfoot.*;  

public class Painter extends Actor 
{
   public Painter()
   {
     setImage(new GreenfootImage(600, 400));
     getImage().setColor(java.awt.Color.GREEN);
   }
   
   public void act()
   {
     if (KinectWorld.yLeftHand < 100)
       getImage().clear();
     else
       getImage().fillOval(KinectWorld.xRightHand, KinectWorld.yRightHand, 20, 20);
   }
 }
In addition to the Greenfoot window you will see a native video window. Regards Aegidius (see screenvideo)
You need to login to post a reply.