Esempio n. 1
0
        // Should be called intermittently to examine skeleton data. Determines
        // whether any gestures have been completed and interacts with the gestures'
        // targets.
        public void checkGestures()
        {
            Console.Write("Called checkGestures().");

            int[] users = userGenerator.GetUsers();
            foreach (int user in users)
            {
                if (userGenerator.SkeletonCapability.IsTracking(user))
                {
                    if (!calibrated)
                    {
                        // Use the first user to calibrate system.
                        calibrate(user);
                        break;
                    }
                    checkUserGestures(user);
                }
                else
                {
                    for (int i = 0; i < raysToBeAnimated.Length; i++)
                    {
                        raysToBeAnimated[i] = null;
                    }
                }
            }
        }
Esempio n. 2
0
        public void DrawStickFigure(ref WriteableBitmap image, DepthGenerator depthGenerator, DepthMetaData data,
                                    UserGenerator userGenerator, Ray3D[] rays)
        {
            Point3D corner = new Point3D(data.XRes, data.YRes, data.ZRes);

            corner = depthGenerator.ConvertProjectiveToRealWorld(corner);
            this.depthGenerator = depthGenerator;

            int nXRes = data.XRes;
            int nYRes = data.YRes;

            // TODO: Fix these.

            /*foreach (Ray3D ray in rays)
             * {
             *  if (ray != null)
             *  {
             *      int[] p0 = ray.point0();
             *      int[] p1 = ray.point1();
             *      DrawTheLine(ref image, p0, p1);
             *  }
             * }*/

            int[] users = userGenerator.GetUsers();
            foreach (int user in users)
            {
                if (userGenerator.SkeletonCapability.IsTracking(user))
                {
                    DrawSingleUser(ref image, user, userGenerator, corner);
                }
            }
        }
Esempio n. 3
0
 void AttemptCalibrationForAllUsers()
 {
     foreach (int id in userGenerator.GetUsers())
     {
         if (!skeletonCapbility.IsCalibrating(id) && !skeletonCapbility.IsTracking(id))
         {
             this.poseDetectionCapability.StartPoseDetection(this.calibPose, id);
         }
     }
 }
Esempio n. 4
0
        // 描画
        private unsafe void xnDraw()
        {
            // カメライメージの更新を待ち、画像データを取得する
            context.WaitOneUpdateAll(image);
            ImageMetaData imageMD = image.GetMetaData();
            SceneMetaData sceneMD = user.GetUserPixels(0);

            // カメラ画像の作成
            lock (this) {
                // 書き込み用のビットマップデータを作成
                Rectangle  rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
                BitmapData data = bitmap.LockBits(rect, ImageLockMode.WriteOnly,
                                                  System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                // 生データへのポインタを取得
                byte *  dst   = (byte *)data.Scan0.ToPointer();
                byte *  src   = (byte *)image.ImageMapPtr.ToPointer();
                ushort *label = (ushort *)sceneMD.LabelMapPtr.ToPointer();

                for (int i = 0; i < imageMD.DataSize; i += 3, src += 3, dst += 3, ++label)
                {
                    dst[0] = (byte)(src[2] * colors[*label, 0]);
                    dst[1] = (byte)(src[1] * colors[*label, 1]);
                    dst[2] = (byte)(src[0] * colors[*label, 2]);
                }

                bitmap.UnlockBits(data);

                // スケルトンの描画
                foreach (int id in user.GetUsers())
                {
                    // トラッキング対象のユーザーでなければ次へ
                    if (!user.SkeletonCapability.IsTracking(id))
                    {
                        continue;
                    }

                    // スケルトンを描画する
                    DrawSkeleton(id);

                    // 腕の交点を描画する
                    DrawCrossPoint(id);
                }


                // 現在の状態を表示する
                Graphics g = Graphics.FromImage(bitmap);
                g.DrawString(message, font, brush, point);
            }
        }
Esempio n. 5
0
        public void DrawStickFigure(ref WriteableBitmap image, DepthGenerator depthGenerator, DepthMetaData data, UserGenerator userGenerator)
        {
            Point3D corner = new Point3D(data.XRes, data.YRes, data.ZRes);

            corner = depthGenerator.ConvertProjectiveToRealWorld(corner);
            this.depthGenerator = depthGenerator;

            int nXRes = data.XRes;
            int nYRes = data.YRes;

            int[] users = userGenerator.GetUsers();
            foreach (int user in users)
            {
                if (userGenerator.SkeletonCapability.IsTracking(user))
                {
                    DrawSingleUser(ref image, user, userGenerator, corner);
                }
            }
        }
Esempio n. 6
0
    void Start()
    {
        calibratedUsers  = new List <int>();
        calibratingUsers = new List <int>();
        allUsers         = new List <int>();

        this.userGenerator           = OpenNIContext.OpenNode(NodeType.User) as UserGenerator; //new UserGenerator(this.Context.context);
        this.skeletonCapbility       = this.userGenerator.SkeletonCapability;
        this.poseDetectionCapability = this.userGenerator.PoseDetectionCapability;
        this.calibPose = this.skeletonCapbility.CalibrationPose;
        this.skeletonCapbility.SetSkeletonProfile(SkeletonProfile.All);

        this.userGenerator.NewUser  += new EventHandler <NewUserEventArgs>(userGenerator_NewUser);
        this.userGenerator.LostUser += new EventHandler <UserLostEventArgs>(userGenerator_LostUser);
        this.poseDetectionCapability.PoseDetected += new EventHandler <PoseDetectedEventArgs>(poseDetectionCapability_PoseDetected);
        this.skeletonCapbility.CalibrationEnd     += new EventHandler <CalibrationEndEventArgs>(skeletonCapbility_CalibrationEnd);

        foreach (int userId in userGenerator.GetUsers())
        {
            allUsers.Add(userId);
        }
        AttemptCalibrationForAllUsers();
    }
Esempio n. 7
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (FContextChanged)
            {
                if (FContextIn.PluginIO.IsConnected)
                {
                    if (FContextIn[0] != null)
                    {
                        try
                        {
                            // Creates the User Generator from the Context Object
                            FUserGenerator = new UserGenerator(FContextIn[0]);

                            //Set the resolution of the texture
                            FTexWidth  = FUserGenerator.GetUserPixels(0).FullXRes;
                            FTexHeight = FUserGenerator.GetUserPixels(0).FullYRes;

                            //Reinitalie the vvvv texture
                            Reinitialize();

                            FUserGenerator.StartGenerating();

                            FContextChanged = false;
                        }
                        catch (Exception ex)
                        {
                            FLogger.Log(ex);
                        }
                    }
                }
                else
                {
                    CleanUp();
                    FContextChanged = false;
                }
            }

            //create new texture if outputmode changed
            if (FOutputMode.IsChanged)
            {
                Reinitialize();
            }

            if (FUserGenerator != null)
            {
                if (FEnabledIn.IsChanged)
                {
                    if (FEnabledIn[0])
                    {
                        FUserGenerator.StartGenerating();
                    }
                    else
                    {
                        FUserGenerator.StopGenerating();
                    }
                }

                if (FUserGenerator.IsDataNew)
                {
                    FUserIdOut.SliceCount   = FUserGenerator.NumberOfUsers;
                    FPositionOut.SliceCount = FUserGenerator.NumberOfUsers;
                    FTextureOut.SliceCount  = 1;

                    if (FUserGenerator.NumberOfUsers > 0)
                    {
                        //copies a list of all users and sort them
                        int[] tUsers = FUserGenerator.GetUsers();
                        int[] Users  = (int[])tUsers.Clone();
                        Array.Sort(Users);

                        for (int i = 0; i < Users.Length; i++)
                        {
                            FUserIdOut[i] = Users[i];
                            try
                            {
                                //middle point of the User
                                Point3D  Point    = FUserGenerator.GetCoM(Users[i]);
                                Vector3D Position = new Vector3D(Point.X, Point.Y, Point.Z);

                                //map postion values to vvvv coordinates
                                FPositionOut[i] = Position / 1000;
                            }
                            catch (StatusException ex)
                            {
                                FLogger.Log(ex);
                            }
                        }
                    }

                    //update the vvvv texture
                    Update();
                }
            }
            else
            {
                FUserIdOut.SliceCount   = 0;
                FPositionOut.SliceCount = 0;
                FTextureOut.SliceCount  = 0;
            }
        }
Esempio n. 8
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (FContextChanged)
            {
                if (FContextIn.PluginIO.IsConnected)
                {
                    if (FContextIn[0] != null)
                    {
                        try
                        {
                            FUserGenerator           = new UserGenerator(FContextIn[0]);
                            FSkeletonCapability      = FUserGenerator.SkeletonCapability;
                            FPoseDetectionCapability = FUserGenerator.PoseDetectionCapability;
                            FCalibPose = FSkeletonCapability.CalibrationPose;

                            FUserGenerator.NewUser  += userGenerator_NewUser;
                            FUserGenerator.LostUser += userGenerator_LostUser;
                            FPoseDetectionCapability.PoseDetected   += poseDetectionCapability_PoseDetected;
                            FSkeletonCapability.CalibrationComplete += skeletonCapbility_CalibrationComplete;

                            FSkeletonCapability.SetSkeletonProfile(FSkeletonProfileIn[0]);
                            FJoints = new Dictionary <int, Dictionary <SkeletonJoint, SkeletonJointTransformation> >();

                            FUserGenerator.StartGenerating();

                            FContextChanged = false;
                        }
                        catch (Exception ex)
                        {
                            FLogger.Log(ex);
                        }
                    }
                }
                else
                {
                    CleanUp();
                    FContextChanged = false;
                }
            }

            if (FUserGenerator != null)
            {
                if (FEnabledIn.IsChanged)
                {
                    if (FEnabledIn[0])
                    {
                        FUserGenerator.StartGenerating();
                    }
                    else
                    {
                        FUserGenerator.StopGenerating();
                    }
                }

                if (FUserGenerator.IsDataNew)
                {
                    if (FSkeletonProfileIn.IsChanged)
                    {
                        FSkeletonCapability.SetSkeletonProfile(FSkeletonProfileIn[0]);
                    }

                    if (FSmoothingIn.IsChanged)
                    {
                        FSkeletonCapability.SetSmoothing(FSmoothingIn[0]);
                    }

                    FUserIdOut.SliceCount            = FUserGenerator.NumberOfUsers;
                    FStatusOut.SliceCount            = FUserGenerator.NumberOfUsers;
                    FJointPositionOut.SliceCount     = FUserGenerator.NumberOfUsers;
                    FJointOrientationXOut.SliceCount = FUserGenerator.NumberOfUsers;
                    FJointOrientationYOut.SliceCount = FUserGenerator.NumberOfUsers;
                    FJointOrientationZOut.SliceCount = FUserGenerator.NumberOfUsers;

                    if (FUserGenerator.NumberOfUsers > 0)
                    {
                        //get all Users and sort them
                        int[] users = FUserGenerator.GetUsers();
                        Array.Sort(users);

                        int slice = 0;
                        foreach (int user in users)
                        {
                            FUserIdOut[slice] = user;
                            if (FSkeletonCapability.IsTracking(user))
                            {
                                FStatusOut[slice] = "Tracking user " + user;

                                int u       = user - 1;
                                int binSize = FJointIn[u].SliceCount;
                                FJointPositionOut[u].SliceCount     = binSize;
                                FJointOrientationXOut[u].SliceCount = FJointOrientationYOut[u].SliceCount = FJointOrientationZOut[u].SliceCount = binSize;
                                for (int i = 0; i < binSize; i++)
                                {
                                    var j = GetJoint(user, FJointIn[u][i]);

                                    var p = j.Position.Position;
                                    if (j.Position.Confidence > 0.5)
                                    {
                                        FJointPositionOut[u][i] = new Vector3D(p.X, p.Y, p.Z) / 1000;
                                    }

                                    var o = j.Orientation;
                                    if (o.Confidence > FConfidenceIn[slice])
                                    {
                                        FJointOrientationXOut[u][i] = new Vector3D(o.X1, o.Y1, o.Z1);
                                        FJointOrientationYOut[u][i] = new Vector3D(o.X2, o.Y2, o.Z2);
                                        FJointOrientationZOut[u][i] = new Vector3D(o.X3, o.Y3, o.Z3);
                                    }
                                }
                            }
                            else if (FSkeletonCapability.IsCalibrating(user))
                            {
                                FStatusOut[slice] = "Calibrating user " + user;
                            }
                            else
                            {
                                FStatusOut[slice] = "Looking for pose on user " + user;
                            }

                            slice++;
                        }
                    }
                }
            }
            else
            {
                FUserIdOut.SliceCount            = 0;
                FStatusOut.SliceCount            = 0;
                FJointPositionOut.SliceCount     = 0;
                FJointOrientationXOut.SliceCount = 0;
                FJointOrientationYOut.SliceCount = 0;
                FJointOrientationZOut.SliceCount = 0;
            }
        }