Kinect Taste (2) - Bone Recognition

Keywords: C# SDK html5

Author rotation, link to the original http://blog.csdn.net/nmlh7448...

text

_The last article briefly talked about the processing of Kinect color image and depth image. It is difficult to write some applications directly by processing color data stream and depth data stream, so Microsoft has packaged the skeleton recognition module in SDK. Although it's bone recognition, it actually recognizes joints, which can be used as a connection between two joints. Through this module, we can easily obtain the 3D position and coordinates of each joint of human body, so that we can easily develop some applications that need somatosensory recognition.
In fact, skeleton recognition is simpler. Through Microsoft SDK, all we have to do is call. The advantage of Microsoft doing this is that developers can reduce the time spent on the underlying, image processing and other aspects, concentrate on their own application logic, and quickly develop interesting or practical applications.
In order to learn skeleton recognition, I wrote a Demo that only captures the head position. In order to mark the position of the recognized head, I need to draw something in that coordinate position. Here I use a funny one. The color Image shown in the previous article is an Image control. It can also draw itself, but it is a little inefficient. So this article uses Canvas control. Yes, similar to the Canvas Canvas control in HTML5, we can draw color images and funny on the canvas. After adding canvas controls to the form, add Image and Ellipse child controls to the canvas. As for why Ellipse is used, because funny is round... The modified code is as follows.

<Canvas HorizontalAlignment="Left" Height="480" VerticalAlignment="Top" Width="640">  
    <Image x:Name="colorImage" HorizontalAlignment="Left"
      Height="480" VerticalAlignment="Top" Width="640"/>  
    <Ellipse x:Name="ellipse" Height="48" Canvas.Left="10" Canvas.Top="10" Width="48"/>  
</Canvas>  

In the. cs file, you first declare a Skeleton [] class, which is an array of Skeleton. Skeleton is a skeleton class that encapsulates all the skeletal information of a person identified. Since there may be multiple people in the field of vision, each person's skeleton information is stored in a Skeleton, so here declared as an array. Kinect and its SDK have done a good job of recognizing and distinguishing algorithms.

_kinect.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(KinectSkeletonFrameReady);  
private void KinectSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)  
{  
    bool isSkeletonDataReady = false;  
    using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())  
    {  
        if (skeletonFrame != null)  
        {  
            skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];  
            skeletonFrame.CopySkeletonDataTo(skeletons);  
            isSkeletonDataReady = true;  
        }  
    }  
    if (isSkeletonDataReady)  
    {  
        Skeleton currentSkeleton = (from s in skeletons  
                                    where  
                                    s.TrackingState == SkeletonTrackingState.Tracked  
                                    select s).FirstOrDefault();  
        if (currentSkeleton != null)  
        {  
            var brush = new ImageBrush(); //Define picture brushes.
            var converter = new ImageSourceConverter();  
            brush.ImageSource = (ImageSource)converter.ConvertFromString("Images/huaji.jpg");  
            ellipse.Fill = brush;  //To be optimized
  
            LockHeadWithRedSpot(currentSkeleton);  
        }  
        else  
        {  
            ellipse.Fill = null;  
        }  
   }  
}  

In using block, all skeleton information is copied into skeletons array. Since the number of frames in the Kinect view is uncertain and not necessarily a person, it is a variable-length array, so each frame is selected for reinitialization. In current Skeleton, we use the linq statement to query the first person being tracked, all of whom are sorted by distance from near to far. Make sure that Kinect is tracking at least one person, and then you can define a brush that I use as a source to fill ellipse with funny pictures. I used a new method, LockHeadWithRed Spot (Skeleton), to track the head.

private void LockHeadWithRedSpot(Skeleton s)  
{  
    Joint head = s.Joints[JointType.Head];  
    //Mapping skeletal point coordinates of the head to color video streams
    ColorImagePoint colorImagePoint = _kinect.CoordinateMapper.MapSkeletonPointToColorPoint(head.Position, _kinect.ColorStream.Format);  
    Point p = new Point((int)(colorImage.Width * colorImagePoint.X / _kinect.ColorStream.FrameWidth), (int)(colorImage.Height * colorImagePoint.Y / _kinect.ColorStream.FrameHeight));  
    Canvas.SetLeft(ellipse, p.X - 24);  
    Canvas.SetTop(ellipse, p.Y - 24);  
}  

Owing to the fact that all the methods used in this and previous chapters can only obtain the head position data, but not the head size data, the funny size should be controlled by oneself. Code 24 is the radius size I tried out by myself, which can be adjusted according to practical application.

Posted by jockey_jockey on Mon, 15 Apr 2019 11:24:32 -0700