Continuous maintenance address: http://52coding.com/understanding-the-cpp-sample-application
This evening, I read the official C ++ example provided by Leap Motion. It feels great and awesome! Compared with Microsoft's Kinect program, their example encoding style is a little different, which is very efficient and simple! For cainiao, you should take a good look at their basic programming skills. For those who have a certain degree of foundation, you will be surprised after reading this article that the Leap Motion API is so concise and powerful. For the children who are engaged in developing Kinect, when you meet Leap, you will be immediately put into her arms.
The example is in the samples folder under LeapSDK. If you do not know where to download the SDK, you can go to this address or the official address (if this article is more than a month old, please go to the official address to download ).
At the same time, I am going to create an application for playing the piano. There is also a piano play application in Leap Motion (or a company engaged in commercial music software development), although its interface effect is very good, however, this is not the case (mainly because the user experience is poor and cannot accurately recognize the piano gesture ). Well, I started from scratch ~ Naturally, the focus is on how to accurately identify the fingers behind the feelings. If it is done well, I will ask the person who plays the piano to help debug the software. If nothing happens, all the code is open-source. You can learn from each other and learn from each other. At the same time, if anyone wants to cooperate with me, we are very welcome. Shanghai is a top priority ~
/*************************************** ***************************************\ * Copyright (C) 2012-2013 Leap Motion, Inc. all rights reserved. ** Leap Motion proprietary and confidential. not for distribution. ** Use subject to the terms of the Leap Motion SDK Agreement available at ** https://developer.leapmotion.com/sdk_agreement, or another agreement ** between Leap Motion and you, your compan Y or other organization. *\************************************** **************************************** /// # include <windows. h> // If the screen flushing is too fast, open this Definition 1 (a total of 2 places) # include <iostream> # include "Leap. h "using namespace Leap; class SampleListener: public Listener {public: virtual void onInit (const Controller &); virtual void onConnect (const Controller &); virtual void onDisconnect (const Controller &); virtual void onExit (Const Controller &); virtual void onFrame (const Controller &); virtual void onFocusGained (const Controller &); virtual void onFocusLost (const Controller &) ;}; void SampleListener :: onInit (const Controller & controller) {std: cout <"Initialized" <std: endl;} // enable void SampleListener for all gestures :: onConnect (const Controller & controller) {std: cout <"Connected" <std: endl; controller. enableGesture (Gesture: TYP E_CIRCLE); controller. enableGesture (Gesture: TYPE_KEY_TAP); controller. enableGesture (Gesture: TYPE_SCREEN_TAP); controller. enableGesture (Gesture: TYPE_SWIPE);} void SampleListener: onDisconnect (const Controller & controller) {// Note: not dispatched when running in a debugger. std: cout <"Disconnected" <std: endl;} void SampleListener: onExit (const Controller & controller) {std :: cout <"Exited" <std: Endl;} // core function. What should I do when I obtain a frame of Data? void SampleListener: onFrame (const Controller & controller) {// obtain the latest frame, and some basic information const Frame = controller is returned. frame (); std: cout <"Frame id:" <frame. id () <", timestamp:" <frame. timestamp () <", hands:" <frame. hands (). count () <", fingers:" <frame. fingers (). count () <", tools:" <frame. tools (). count () <", gestures:" <frame. gestures (). count () <std: Endl; // if (! Frame. hands (). empty () {// get the HandList structure returned by the first Hand [hands (), which can be operated like a container] const hand Hand = frame. hands () [0]; // check whether there are fingers in the hand. [if you have a fist, you cannot find the finger.] const FingerList fingers = hand. fingers (); if (! Fingers. empty () {// calculates the mean position coordinate Vector avgPos at the tip of the fingertip; for (int I = 0; I <fingers. count (); ++ I) {avgPos + = fingers [I]. tipPosition ();} avgPos/= (float) fingers. count (); std: cout <"Hand has" <fingers. count () <"fingers, average finger tip position" <avgPos <std: endl;} // obtain the coordinates of the ball center radius and palm of the hand std :: cout <"Hand sphere radius:"
The following figure shows the running effect: