Friday, 2 August 2013

Leap Motion: A small step or a giant leap?

I've been playing with Leap Motion for the last few days and here are my first impressions with this tiny device.

First, this is a great piece of hardware and there are tons of things to be done with it. However it doesn't really have compelling software accompanying it and currently not really going beyond a geek device but still it is a great geek device!! Here are my feelings in a more visual way :)

As you might see, after the shipment my package moved to Paris from Czech Republic instead of coming to Istanbul. The unpacking and installiation was quite 'appleish'. The intro and the included demos were very impressive. The first thing I expected was an out of box replacement for the mouse which this device is definitely not. After a while playing with all the apps, I realized currently most apps are just mimicking a mouse experience instead of creating a unique one for Leap. Leap motion is great device offering a new way of controls and it must be treated that way, just like the iphone first released.

The accuracy of the controller is great! You may realize it loses some finger when you do sharp moves but the accuracy is great for any idea and any app, well may be not for flying a real plane. The gem of this device is the sdk. It is designed in a beautiful way and the more you dig into api, the more you want to write code on it. The APIs are implemented and designed in a beautiful way.

After downloading the sdk from leap's website all you need to do is to follow the guidelines to set up your favourite development environment.

I built some sample apps using Java so I'll continue with the provided Java SDK. Looking at the sample app provided with the sdk, the first thing you will notice is you need to create a class which extends the com.leapmotion.leap.Listener class. Next create another class with the main method and create a  com.leapmotion.leap.controller.Controller and add your listener to the controller you just created.

// your custom listener class
SampleListener listener = new SampleListener();
Controller controller = new Controller();
// add your listener to the controller

The custom listener class which extends Listener needs to implement several methods.

class SampleListener extends Listener {
    public void onInit(Controller controller) {
        //can check if controller.isConnected() and decide how to proceed
    public void onConnect(Controller controller) {
        //this method is invoked after your code is connected to the device
        //it is time to decide what to listen. You can register for swipe, tap, circle... etc
    public void onFrame(Controller controller) {
        // Get the most recent frame
        Frame frame = controller.frame();
        //this is where the fun begines, you can how many hands or fingers in the frame
        //and what they are doing such as moves, gestures...
        //lets see how many fingers are there in the frame
        if (!frame.hands().empty()) {
            Hand hand = frame.hands().get(0);
            FingerList fingers = hand.fingers();
            System.out.println("Fingers " + fingers.count());
        //checking gestures is not much different
        GestureList gestures = frame.gestures();
        for (int i = 0; i < gestures.count(); i++) {
            Gesture gesture = gestures.get(i);
            if (gesture.type()==Gesture.Type.TYPE_SWIPE){
                SwipeGesture swipe = new SwipeGesture(gesture);
                if (swipe.state()==swipe.state().STATE_START){
                        float x=swipe.direction().getX();
                        float y=swipe.direction().getY();
                        float z=swipe.direction().getZ();
                        System.out.println("Swipe started at: "+ x +", "+ y +", "+ z);
                if (swipe.state()==swipe.state().STATE_STOP){
                        float x=swipe.direction().getX();
                        float y=swipe.direction().getY();
                        float z=swipe.direction().getZ();
                        System.out.println("Swipe finished at: "+ x +", "+ y +", "+ z);

As you might see its pretty easy to detect hands, fingers and gestures. Combining those Java's Robot class you may end up with a simple mouse replacement app for Leap Motion or integrate some gestures to your favourite IDEs debugger to debug your code with simple gestures.

Leap Motion is a giant leap as a hardware unit which currently comes with a small step in software. However the opportunities are endless and what can be done with this little device is all up to your imagination!