Leap Motion的环境配置(使用c#)

来源:互联网 发布:pplive网络电视2015 编辑:程序博客网 时间:2024/06/10 08:45

开发用的sdk和驱动程序从这里下载https://developer.leapmotion.com/

官方的开发者文档在这里https://developer.leapmotion.com/documentation/index.html?proglang=current

(我用的是电信的宽带 ,上面两个链接需要翻墙才能打开)

官方下的sdk是个压缩包,解压到任意目录即可,解压后安装里面的那个安装程序

sdk里的dll文件在这里


根据所使用的.net版本来添加引用

vs里的平台也要改为x86或x64,然后把上图中对应文件夹里的文件复制到程序所在目录里就可以了,如果没有复制进去,会出现'Leap.LeapPINVOKE'的报错。

最后,附上官方的原话:

Creating a project in Visual Studio

This section illustrates how to create a project from scratch. Most of the steps also apply to adding Leap Motion support to an existing project. The example uses Visual Studio 2012.

To add Leap Motion support to a new or existing project:

Important: If you are creating a 64-bit application, use the libraries in the lib\x64 directory of the SDK, not the 32-bit libraries in the lib\x86 directory.

  1. Open or create a new project of the desired Windows Forms or WPF type.

  2. Make a LEAP_SDK system environment variable to point to your Leap Motion SDK folder. This step is optional, but does simplify creating references to the SDK files in your projects. (As a reminder, you can create and change system environment variables from the Windows System Properties dialog.)

  3. Add a reference to the Leap Motion .NET library that you wish to use.

    1. Select Project > Add Reference.

    2. In the References dialog, select Browse.

    3. Browse to your Leap Motion SDK folder.

    4. Choose either LeapCSharp.NET3.5.dll or LeapCSharp.NET4.0.dll. Both libraries support the full Leap Motion API, but you should choose the one appropriate for the version of .NET you are using in the project.

      Note: do not add any of the other Leap Motion library files as a reference.

  4. Set the target platform to x86 or x64:

    1. Open the project properties page with Project > ProjectName Properties.
    2. Select the Build page.
    3. Set the Configuration to All Configurations.
    4. Under General, set Platform target to either x86 or x64. Do not use the AnyCPU target.
  5. Edit the Post Build Event to copy the native libraries to the project’s target executable directory.

    1. Open the project properties page.

    2. Select the Build Events page.

    3. Click Edit Post-build...

    4. Edit the event field to copy the libraries.

      For 32-bit, x86 projects add:

      xcopy /yr "$(LEAP_SDK)\lib\x86\Leap.dll" "$(TargetDir)"xcopy /yr "$(LEAP_SDK)\lib\x86\LeapCSharp.dll" "$(TargetDir)"

      For 64-bit, x64 projects add:

      xcopy /yr "$(LEAP_SDK)\lib\x64\Leap.dll" "$(TargetDir)"xcopy /yr "$(LEAP_SDK)\lib\x64\LeapCSharp.dll" "$(TargetDir)"

      Note: if you didn’t create the LEAP_SDK environment variable, use the path to your SDK library in place of $(LEAP_SDK).

  6. Add your source code...

Note: If you get the error, TypeInitializationException:Thetypeinitializer for 'Leap.LeapPINVOKE' threw an exception, when you run your project, then the Leap Motion .NET code is not finding the correct native libraries. This can happen if you forget to copy Leap.dll and LeapCSharp.dll to the same directory as your executable or you copy the wrong version (64-bit instead of 32-bit or vice versa). The error can also occur if you use the AnyCPU target platform.

0 0
原创粉丝点击