简体   繁体   中英

Setup two kinect: v1 and v2

I planned to work with two Kinects. I have installed VS C#, SDK 1.8 and 2.0, of Kinect, and my issue is:

After adding one reference library (ex. 1.8), it is not possible to add the another (ex. 2.0, message "the reference... already exists"). I perceived that is due to the names of namespaces and classes are the same. So, I cannot instantiate the second sensor,

Please, suggest me what can I do to resolve it, specifically if there is any way to access the different versions of the same resource (ex. KinectSensor class in version 1.8 and 2.0)?

There are several solutions to your problem. The first one (probably the most naive), is to create two different projects, each of which has a different reference. Then you can write a third layer that uses data provided from the first two projects.

If you really need to use both the references in the same project, there is however another option, and it consists in using extern aliases .

First of all, add a single reference (for instance, Microsoft.Kinect, version 1.8). Then, save your project and close Visual Studio. In the project folder, you should find a .csproj file, that you can open with a text editor. Looking at its content, you will find a line like this:

<Reference Include="Microsoft.Kinect, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />

Now, change the above line with the following ones:

<Reference Include="Microsoft.Kinect, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
    <Aliases>KinectV1</Aliases>
</Reference>
<Reference Include="Microsoft.Kinect, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
    <Aliases>KinectV2</Aliases>
</Reference>

You should see now both references in the same project, also when you open it with Visual Studio.

Then you should be able to use something like this:

// You must declare aliases here:
extern alias KinectV1;
extern alias KinectV2;

// Then some using...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// ... and do not forget Kinect!
using KinectV1;
using KinectV2;

// Now you can do something like this:
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // Something from Microsft.Kinect V2
            KinectV2.Microsoft.Kinect.HandState hs = KinectV2.Microsoft.Kinect.HandState.Closed;

            // Something from Microsft.Kinect V1
            KinectV1.Microsoft.Kinect.Skeleton s = new KinectV1.Microsoft.Kinect.Skeleton();
        }
    }
}

If your project does not compile, try to close Visual Studio and delete the hidden .suo file (in the same folder of the .sln file of your project).

Take a look to this answer if you have any more troubles.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM