Пример #1
0
        // 描画
        private unsafe void xnDraw()
        {
            // カメライメージの更新を待ち、画像データを取得する
            context.WaitOneUpdateAll(image);
            ImageMetaData imageMD = image.GetMetaData();

            Graphics g;

            // カメラ画像の作成
            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();

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

                bitmap.UnlockBits(data);

                // 手の軌跡を描画
                if (handPoints.Count != 0)
                {
                    Point3D start = depth.ConvertRealWorldToProjective(handPoints.Peek());
                    foreach (Point3D handPoint in handPoints)
                    {
                        Point3D pt = depth.ConvertRealWorldToProjective(handPoint);
                        g = Graphics.FromImage(bitmap);
                        g.DrawLine(pen, start.X, start.Y, pt.X, pt.Y);
                        start = pt;
                    }

                    // 先頭要素を削除
                    if (handPoints.Count > MAX_POINT)
                    {
                        handPoints.Dequeue();
                    }
                }
            }


            // 現在の状態を表示する
            g = Graphics.FromImage(bitmap);
            string message = "Gesture:RaiseHand" +
                             ", Status:" + gestureStatus.ToString() + "\n" +
                             "Hand:" + handStates.ToString();

            g.DrawString(message, font, brush, point);
        }
        /// <summary>
        /// Loads the 2D data for a specific skeleton joint.
        /// </summary>
        private void GetJoint(SkeletonCapability source,
                              int user, SkeletonJoint joint,
                              Dictionary <SkeletonJoint, SkeletonJointPosition> target)
        {
            SkeletonJointPosition pos;

            if (joint == SkeletonJoint.Waist)
            {
                // Calculate the joint position as arithmetic mean of right
                // and left hip joints, as it is not possible to poll it
                // directly.

                pos = new SkeletonJointPosition();

                SkeletonJointPosition posLeft  = source.GetSkeletonJointPosition(user, SkeletonJoint.LeftHip);
                SkeletonJointPosition posRight = source.GetSkeletonJointPosition(user, SkeletonJoint.RightHip);

                if (posLeft.Position.Z == 0 || posRight.Position.Z == 0)
                {
                    pos.Confidence = 0;
                    pos.Position   = new Point3D(
                        (posLeft.Position.X + posRight.Position.X) / 2,
                        (posLeft.Position.Y + posRight.Position.Y) / 2,
                        0);
                }
                else
                {
                    pos.Confidence = Math.Min(posLeft.Confidence, posRight.Confidence);
                    pos.Position   = depthGenerator.ConvertRealWorldToProjective(
                        new Point3D(
                            (posLeft.Position.X + posRight.Position.X) / 2,
                            (posLeft.Position.Y + posRight.Position.Y) / 2,
                            (posLeft.Position.Z + posRight.Position.Z) / 2));
                }
            }
            else
            {
                pos = source.GetSkeletonJointPosition(user, joint);
                if (pos.Position.Z == 0)
                {
                    pos.Confidence = 0;
                }
                else
                {
                    pos.Position = depthGenerator.ConvertRealWorldToProjective(pos.Position);
                }
            }

            target[joint] = pos;
        }
Пример #3
0
    public int WhichUserDoesThisPointBelongTo(Point3D point)
    {
        // get userID of user to whom the hand is attached
        Point3D       ProjectiveHandPoint = depthGenerator.ConvertRealWorldToProjective(point);
        SceneMetaData sceneMD             = userGenerator.GetUserPixels(0);

        return(sceneMD[(int)ProjectiveHandPoint.X, (int)ProjectiveHandPoint.Y]);
    }
Пример #4
0
        // 骨格の線を引く
        void DrawLine(int player, SkeletonJoint eJoint1, SkeletonJoint eJoint2)
        {
            // 各箇所の座標を取得する
            SkeletonJointPosition joint1 = GetJointPosition(player, eJoint1);
            SkeletonJointPosition joint2 = GetJointPosition(player, eJoint2);

            if (joint1.Confidence < 0.5 || joint2.Confidence < 0.5)
            {
                return;
            }

            // 現実の座標から画面の座標に変換する
            Point3D[] pt = new Point3D[] { joint1.Position, joint2.Position };
            pt = depth.ConvertRealWorldToProjective(pt);

            Graphics g = Graphics.FromImage(bitmap);

            g.DrawLine(pen, pt[0].X, pt[0].Y, pt[1].X, pt[1].Y);
        }
        /// <summary>
        /// Converts a JointDictionary with 3D data to the corresponding one
        /// with 2D data. Note that the Z-Coordinate is left unchanged, though
        /// it has no meaning in the resulting 2D space and can be seen as 0.
        /// </summary>
        public JointDictionary Convert3Dto2D(JointDictionary source, DepthGenerator generator)
        {
            if (!source.Is3DData)
            {
                return(new JointDictionary(source));
            }
            else
            {
                JointDictionary ret = new JointDictionary(false);

                foreach (SkeletonJoint joint in source.Keys)
                {
                    SkeletonJointPosition pos = new SkeletonJointPosition();
                    pos.Confidence = source[joint].Confidence;
                    pos.Position   = generator.ConvertRealWorldToProjective(source[joint].Position);
                    ret.Add(joint, pos);
                }
                return(ret);
            }
        }
Пример #6
0
        void steadydetector_Steady(object sender, SteadyEventArgs e)
        {
            //   System.Console.WriteLine("Steady Detected..");
            PointStatus      pt  = pointCollections[e.ID];
            HandPointContact hdc = null;

            is_steady = 1;
            for (int i = 0; i < HandPointBuffer.Count; i++)
            {
                hdc = HandPointBuffer[i] as HandPointContact;

                if (hdc.Id == e.ID)
                {
                    break;
                }
            }
            pt.is_non_steady = false;
            pt.SetColor(Brushes.Yellow);
            int     status = 0;
            Point3D hpoint = hdc.RowPoint;

            hpoint.Y = -hpoint.Y;
            Point3D pt3 = depthGen.ConvertRealWorldToProjective(hpoint);

            clipHandFromDepthMap(pt3);
            status = openpalm.isDetected(clipping, pt3);
            if (status == 1)
            {
                Console.WriteLine("OpenHand");
            }
            else if (status == 2)
            {
                Console.WriteLine("Close Hand");
            }
            Multitouch.Contracts.ContactState st = hdc.State;
            if (status == 1 && (st == Multitouch.Contracts.ContactState.Moved || st == Multitouch.Contracts.ContactState.New))
            {
                pt.SetColor(Brushes.Green);
                pt.steady_state = 1;
                pt.is_clicked   = false;

                System.Console.WriteLine("Release...");
                hdc.Update(pt.steady_point.X, pt.steady_point.Y, Multitouch.Contracts.ContactState.Removed);
                inputProvider.EnqueueContact(hdc, Multitouch.Contracts.ContactState.Removed);

                pt.steady_point = pt.Location;
            }
            else if (status == 2 && st == Multitouch.Contracts.ContactState.Removed)
            {
                System.Console.WriteLine("Grab...");
                pt.steady_state = 2;
                pt.is_clicked   = true;
                pt.SetColor(Brushes.Red);
                hdc.Update(pt.steady_point.X, pt.steady_point.Y, Multitouch.Contracts.ContactState.New);
                inputProvider.EnqueueContact(hdc, Multitouch.Contracts.ContactState.New);
                pt.steady_point = pt.Location;
            }
            else
            {
                pt.steady_point = pt.Location;
            }
        }
Пример #7
0
        public int[] ConvertCoord(SkeletonJointPosition joint, int offset)
        {
            Point3D point = depthGenerator.ConvertRealWorldToProjective(joint.Position);

            return(new int[] { (point.X >= 0) ? (int)(point.X + offset) : 0, (point.Y >= 0) ? (int)(point.Y + offset) : 0 });
        }