Reputation: 23
I am now updating my Kinect program from 1.8 to 2.0 but got problems.
//Please consider the follow code
public abstract class ISkeletonFrameHandler
{
//version 1.8
//public abstract void FrameReady(object sender, SkeletonFrameReadyEventArgs e);
//version 2.0
public abstract void FrameReady(object sender, BodyFrameArrivedEventArgs e);
}
public void AddSkeletonFrameHandler(ISkeletonFrameHandler handler)
{
if (this.IsSkeletonStreamReady)
{
try
{
//SDK 1.8 below is not problem
//this.Sensor.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(handler.FrameReady);
//SDK 2.0 below get error CS0029, cannot convert type to type
this.Sensor.BodyFrameSource.FrameCaptured += new EventHandler<BodyFrameArrivedEventArgs>(handler.FrameReady);
}
catch (Exception e)
{
Event.Track("Fail to start the skeleton event handler!", Event.Type.Warning, e);
}
}
}
How can I change the event statement to avoid error?
Upvotes: 1
Views: 781
Reputation: 8546
There is nothing as SkeletonFrame
in Kinect 2. In kinect 2 BodyFrame
provides skeletal data. Remember that, just because BodyFrame
provides the skeletal data doesn't mean it is same as SkeletonFrame
. There are a lot of difference in class structures and data.
Now, I think, this.Sensor.BodyFrameSource.FrameCaptured += new EventHandler<BodyFrameArrivedEventArgs>(handler.FrameReady);
this line of your program is responsible for the error you mentioned.
The error code is " CS0029 C# Cannot implicitly convert type
System.EventHandler<Microsoft.Kinect.BodyFrameArrivedEventArgs>
toSystem.EventHandler<Microsoft.Kinect.FrameCapturedEventArgs>
Write this.Sensor.BodyFrameSource.FrameCaptured
and then write +=
. Visual studio should suggest intellisence, if it doesn't, press Ctrl + Space then visual studio should show the suggestion.
Press Tab to insert. Visual Studio Intellisence should automatically suggest you to press Tab to generate the method stub. Press Tab. The method stub will be generated.
Write your event handler code inside the generated method.
Upvotes: 1