我在我的应用程序中使用 Kinect OpenTK
。在一个类中,我使用WindowLoaded
方法,该方法在循环中调用SensorSkeletonFrameReady
并写入控制台计算的右手坐标。
在我调用的主窗口类OnRenderFrame
中,它在循环中将立方体绘制到视口。
所以基本上我需要将坐标从SensorSkeletonFrameReady
kinectControl 发送到OnRenderFrame
主窗口类。
我试过用线程来完成这个,但我不知道如何发送值。
编辑:
这是主窗口类:
...
public class MainWindow : GameWindow
{
...
/*Kinect thread start*/
kinectControl kinectObject = new kinectControl();
Thread oThread = new Thread(new ThreadStart(kinectObject.WindowLoaded));
oThread.Start();
...
protected override void OnRenderFrame(FrameEventArgs e)
{
...
//Here I need get coordinates from kinectControl
DrawCube();
...
这是 kinectControl 类:
...
private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
...
foreach (Skeleton skeleton in skeletons)
{
Joint rightHand = skeleton.Joints[JointType.HandRight];
Joint leftHand = skeleton.Joints[JointType.HandLeft];
Joint head = skeleton.Joints[JointType.Head];
double leftY = leftHand.Position.Y;
double headY = head.Position.Y;
// get the individual points of the right hand
double rightX = rightHand.Position.X;
double rightY = rightHand.Position.Y;
double rightZ = rightHand.Position.Z;
//here I need send this coordinates to mainwindow class
...
Edit2:我找到了解决方案,而不是注册事件,而是在 OnRenderFrame 方法中使用 OpenNextFrame 方法进行轮询。
public void findSkeleton()//random name of function
{
Skeleton[] skeletons = new Skeleton[0];
SkeletonFrame skeletonFrame = this.sensor.SkeletonStream.OpenNextFrame(0);
if (skeletonFrame != null)
{
skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
skeletonFrame.CopySkeletonDataTo(skeletons);
}
...//rest is the same as in SensorSkeletonFrameReady event