【LeapMotion】Leap Motion C++配置/获取显示/显示并对齐手指

2024-03-11 06:58

本文主要是介绍【LeapMotion】Leap Motion C++配置/获取显示/显示并对齐手指,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!


 

Leap Motion 用EmguCV 显示图像并对齐手指

  阅读(334)  评论(0)
 

Leap Motion 使用OpenCV获取和显示图像

  阅读(593)  评论(0)
 

Leap Motion C++环境的配置


===================================================================================

Leap Motion C++环境的配置

先是建一个c++的win32项目 
然后配置项目的包含目录和库目录 
这里写图片描述 
包含目录中添加 
C:\Users\chengk\Documents\LeapDeveloperKit_2.3.0+31542_win\LeapSDK\include 
当然,路径要改为你自己的。 
这里写图片描述 
然后在库目录中添加: 
C:\Users\chengk\Documents\LeapDeveloperKit_2.3.0+31542_win\LeapSDK\lib\x86 
这里写图片描述

接下来级可以开始写代码了:

#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 cv;
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);}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48

这里重写了Listener类,让在Leap Motion连接时和frame可用是输出。 
中间需要暂停下,防止还没开始进程就结束了。 
这里写图片描述

==============================================================================

Leap Motion 使用OpenCV获取和显示图像

实现的并不难,就是先设置下可以读取图像,然后在onFrame里读取下图像并显示就可以了

#define _CRT_SECURE_NO_DEPRECATE
#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 cv;
using namespace std;
using namespace cv::xfeatures2d;
using namespace cv::ml;
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&);
};void SampleListener::onInit(const Controller& controller) 
{std::cout << "Initialized" << std::endl;
}void SampleListener::onConnect(const Controller& controller) 
{std::cout << "Connected" << std::endl;
}void SampleListener::onDisconnect(const Controller& controller) 
{std::cout << "Disconnected" << std::endl;
}void SampleListener::onExit(const Controller& controller) 
{std::cout << "Exited" << std::endl;
}void SampleListener::onFrame(const Controller& controller) 
{const Frame frame = controller.frame();ImageList images = frame.images();Mat leftMat;Mat rightMat;if (images.count() == 2){leftMat = Mat(images[0].height(), images[0].width(), CV_8UC1, (void *)images[0].data());rightMat = Mat(images[1].height(), images[1].width(), CV_8UC1, (void *)images[1].data());imshow("leftMat", leftMat);imshow("rightMat", rightMat);waitKey(1);}}int main() 
{SampleListener listener;Controller leap;leap.addListener(listener);leap.setPolicy(Leap::Controller::POLICY_BACKGROUND_FRAMES);leap.setPolicy(Leap::Controller::POLICY_IMAGES);std::cin.get();leap.removeListener(listener);return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83

这里写图片描述

==================================================================================

Leap Motion 用EmguCV 显示图像并对齐手指

使用的为控制台应用程序。主要的代码都在重写的Listener类里,代码如下。 
中间需要对坐标转换下。 
我只显示了左边的那副图。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Leap;
using Emgu.CV;
using System.Drawing;
using Emgu.CV.Structure;
using Emgu.Util;
using System.Drawing.Imaging;namespace ConsoleApplication14
{class asas : Listener{Object thislock = new Object();Image<Gray, byte> left = new Image<Gray, byte>(640, 240);void safewriteline(string line){lock (thislock){Console.WriteLine(line);}}public override void OnConnect(Controller arg0){safewriteline("Conectted");}public override void OnFrame(Controller arg0){Frame frame = arg0.Frame();ImageList images = frame.Images;//HandList hands = frame.Hands;FingerList fingers = frame.Fingers;Image<Gray, byte> left = new Image<Gray, byte>(640,240);left.Bytes = images[0].Data;foreach(var f1 in fingers){Leap.Vector tip = f1.TipPosition;float h_slope = -(tip.x + 20 * (-1)) / tip.y;float v_slope = tip.z / tip.y;Leap.Vector pixel = images[0].Warp(new Leap.Vector(h_slope, v_slope, 0));CvInvoke.Circle(left, new Point((int)pixel.x, (int)pixel.y), (int)(1/tip.y*1000), new MCvScalar(255), (int)(1/tip.y*1000)*2);}CvInvoke.Imshow("asasa",left);CvInvoke.WaitKey(2);}public override void OnInit(Controller arg0){safewriteline("inti");}}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58

然后这个是主函数的代码

namespace ConsoleApplication14
{
    class MyApplication{static void Main(string[] args){Controller leap = new Controller();leap.AddListener(new asas());leap.SetPolicy(Controller.PolicyFlag.POLICY_IMAGES);Console.ReadKey();}}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

运行图: 
这里写图片描述


这篇关于【LeapMotion】Leap Motion C++配置/获取显示/显示并对齐手指的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/797008

相关文章

电脑显示mfc100u.dll丢失怎么办?系统报错mfc90u.dll丢失5种修复方案

《电脑显示mfc100u.dll丢失怎么办?系统报错mfc90u.dll丢失5种修复方案》最近有不少兄弟反映,电脑突然弹出“mfc100u.dll已加载,但找不到入口点”的错误提示,导致一些程序无法正... 在计算机使用过程中,我们经常会遇到一些错误提示,其中最常见的就是“找不到指定的模块”或“缺少某个DL

C#如何调用C++库

《C#如何调用C++库》:本文主要介绍C#如何调用C++库方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录方法一:使用P/Invoke1. 导出C++函数2. 定义P/Invoke签名3. 调用C++函数方法二:使用C++/CLI作为桥接1. 创建C++/CL

SpringBoot3.4配置校验新特性的用法详解

《SpringBoot3.4配置校验新特性的用法详解》SpringBoot3.4对配置校验支持进行了全面升级,这篇文章为大家详细介绍了一下它们的具体使用,文中的示例代码讲解详细,感兴趣的小伙伴可以参考... 目录基本用法示例定义配置类配置 application.yml注入使用嵌套对象与集合元素深度校验开发

SpringBoot整合mybatisPlus实现批量插入并获取ID详解

《SpringBoot整合mybatisPlus实现批量插入并获取ID详解》这篇文章主要为大家详细介绍了SpringBoot如何整合mybatisPlus实现批量插入并获取ID,文中的示例代码讲解详细... 目录【1】saveBATch(一万条数据总耗时:2478ms)【2】集合方式foreach(一万条数

IntelliJ IDEA 中配置 Spring MVC 环境的详细步骤及问题解决

《IntelliJIDEA中配置SpringMVC环境的详细步骤及问题解决》:本文主要介绍IntelliJIDEA中配置SpringMVC环境的详细步骤及问题解决,本文分步骤结合实例给大... 目录步骤 1:创建 Maven Web 项目步骤 2:添加 Spring MVC 依赖1、保存后执行2、将新的依赖

python获取网页表格的多种方法汇总

《python获取网页表格的多种方法汇总》我们在网页上看到很多的表格,如果要获取里面的数据或者转化成其他格式,就需要将表格获取下来并进行整理,在Python中,获取网页表格的方法有多种,下面就跟随小编... 目录1. 使用Pandas的read_html2. 使用BeautifulSoup和pandas3.

SpringBoot UserAgentUtils获取用户浏览器的用法

《SpringBootUserAgentUtils获取用户浏览器的用法》UserAgentUtils是于处理用户代理(User-Agent)字符串的工具类,一般用于解析和处理浏览器、操作系统以及设备... 目录介绍效果图依赖封装客户端工具封装IP工具实体类获取设备信息入库介绍UserAgentUtils

SpringBoot基于配置实现短信服务策略的动态切换

《SpringBoot基于配置实现短信服务策略的动态切换》这篇文章主要为大家详细介绍了SpringBoot在接入多个短信服务商(如阿里云、腾讯云、华为云)后,如何根据配置或环境切换使用不同的服务商,需... 目录目标功能示例配置(application.yml)配置类绑定短信发送策略接口示例:阿里云 & 腾

如何为Yarn配置国内源的详细教程

《如何为Yarn配置国内源的详细教程》在使用Yarn进行项目开发时,由于网络原因,直接使用官方源可能会导致下载速度慢或连接失败,配置国内源可以显著提高包的下载速度和稳定性,本文将详细介绍如何为Yarn... 目录一、查询当前使用的镜像源二、设置国内源1. 设置为淘宝镜像源2. 设置为其他国内源三、还原为官方

C++如何通过Qt反射机制实现数据类序列化

《C++如何通过Qt反射机制实现数据类序列化》在C++工程中经常需要使用数据类,并对数据类进行存储、打印、调试等操作,所以本文就来聊聊C++如何通过Qt反射机制实现数据类序列化吧... 目录设计预期设计思路代码实现使用方法在 C++ 工程中经常需要使用数据类,并对数据类进行存储、打印、调试等操作。由于数据类