Kinect painting C#, WPF, SDK Kinect

戏子无情 提交于 2020-01-17 03:49:08

问题


I am new on this site and I really need your help or just a piece of advice guys.

Does anyone know how to do or can help me with making a app similar to this one ?

Draw smooth line in InkCanvas WPF with Kinect

Inline Link

or something like that

Inline Link

I know how to access my Kinect, detect and track each of the joint etc. The only thnig i do not know and with I have problems is that i really do not know how to make a function that will track for example right hand and draw a line on canvas.

Can anyone help me ?


回答1:


Here you have lots of examples:

  • http://www.microsoft.com/en-us/kinectforwindows/develop/how-to-videos.aspx

The powerpoint control example show you how to detect and track the the hands, and even how to detect some gestures.

EDIT:

Following the example of powerpoint control, in the following code i show you how to track my hands with an ellipse:

void sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            try
            {
                using (var skeletonFrame = e.OpenSkeletonFrame())
                {
                    if (skeletonFrame == null)
                        return;

                    if (skeletons == null ||
                        skeletons.Length != skeletonFrame.SkeletonArrayLength)
                    {
                        skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    }
                    skeletonFrame.CopySkeletonDataTo(skeletons);
                }
                Skeleton closestSkeleton = skeletons.Where(s => s.TrackingState == SkeletonTrackingState.Tracked)
                                                    .OrderBy(s => s.Position.Z * Math.Abs(s.Position.X))
                                                    .FirstOrDefault();
                if (closestSkeleton == null)
                    return;

                var rightFoot = closestSkeleton.Joints[JointType.FootRight];
                var leftFoot = closestSkeleton.Joints[JointType.FootLeft];
                var rightHand = closestSkeleton.Joints[JointType.HandRight];
                var leftHand = closestSkeleton.Joints[JointType.HandLeft];

                if (rightFoot.TrackingState == JointTrackingState.NotTracked ||
                    rightHand.TrackingState == JointTrackingState.NotTracked ||
                    leftHand.TrackingState == JointTrackingState.NotTracked)
                {
                    //Don't have a good read on the joints so we cannot process gestures
                    return;
                }

                CoordinateMapper mapper = sensor.CoordinateMapper;
                var point = mapper.MapSkeletonPointToColorPoint(closestSkeleton.Joints[JointType.Head].Position, sensor.ColorStream.Format);
                var point1 = mapper.MapSkeletonPointToColorPoint(rightHand.Position, sensor.ColorStream.Format);
                var point2 = mapper.MapSkeletonPointToColorPoint(leftHand.Position, sensor.ColorStream.Format);
                    // - Put Your Draw Code Here insted of the following:
                    SetEllipsePosition(ellipseRightFoot, rightFoot, false);
                    SetEllipsePosition(ellipseLeftFoot, leftFoot, false);
                    SetEllipsePosition(ellipseLeftHand, leftHand, isBackGestureActive);
                    SetEllipsePosition(ellipseRightHand, rightHand, isForwardGestureActive);
                    SetImagePosition(punhal, rightHand);
                    SetImagePosition2(punhal2, leftHand);
                    // -------------------------------------------------
            catch
            {
                myException(this, new EventArgs());
            }
        }

This is a method from Microsoft SDK that is called everytime Kinect traks efficiently you skeleton. You just have to put your code for Painting whatever you want where i have my SetEllipsePosition and SetImagePosition.



来源:https://stackoverflow.com/questions/25606565/kinect-painting-c-wpf-sdk-kinect

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!