First to build a C + + Win32 Project
Then configure the project's include Directory and library directory
Include Add in Directory
C:\users\chengk\documents\leapdeveloperkit_2.3.0+31542_win\leapsdk\include
Of course, the path should be your own.
Then add the following in the Library directory:
C:\users\chengk\documents\leapdeveloperkit_2.3.0+31542_win\leapsdk\lib\x86
The next level can start writing code:
#include <iostream> #include <stdio.h> #include "opencv2/core.hpp" #include "opencv2/core/utility.hpp" Include "Opencv2/core/ocl.hpp" #include "opencv2/imgcodecs.hpp" #include "opencv2/highgui.hpp" #include "opencv2/ Features2d.hpp "#include" opencv2/calib3d.hpp "#include" opencv2/imgproc.hpp "#include" opencv2/flann.hpp "#include" Opencv2/xfeatures2d.hpp "#include" opencv2/ml.hpp "#include" Leap.h "#pragma comment (lib," Leap.lib ") using namespace C
V
using namespace Std;
using namespace cv::xfeatures2d;
using namespace cv::ml;
using namespace Leap;
Class Samplelistener:public Listener {public:virtual void OnConnect (const controller&);
virtual void Onframe (const controller&);
};
void Samplelistener::onconnect (const controller& Controller) {std::cout << "Connected" << Std::endl; } void Samplelistener::onframe (const controller& Controller) {std::cout << "Frame available" << std
:: Endl; int main () {SampLelistener Listener;
Controller Leap;
Leap.addlistener (listener);
Cin.get ();
Leap.removelistener (listener); }
This overrides the listener class so that when the leap motion is connected and the frame can be output. The
has to be paused in the middle to prevent the process from beginning to end.