C # Kinect v2 Learning Notes (v) overlay of skeletal images and color images

Source: Internet
Author: User

This time for you to bring the skeleton and color image overlay, in fact, is very simple, is to get the bone points to color image, the way to use the previous basis, or the old steps and tunes.

In practical use, the most is the use of the Kinect v2 skeleton data for actual interaction, very interesting stuff.

First take the skeleton type, used to draw the skeleton image; The connection order of skeleton images is the main trunk-> left-> right-> left foot-> right foot the skeleton points provided from the SDK constitute an array storage, as follows:

        Private jointtype[] _jointtype = new jointtype[]{Jointtype.spinebase,jointtype.spinemid, Jointtype.spinemid,jointtype.spineshoulder, Jointtype.spineshoulder,jointtype.neck, JointType.Neck , Jointtype.head, Jointtype.spineshoulder,jointtype.shoulderleft, Jointtype.shoulderleft,jointtype .
            Elbowleft, Jointtype.elbowleft,jointtype.wristleft, Jointtype.wristleft,jointtype.handleft, Jointtype.handleft,jointtype.handtipleft, Jointtype.handleft,jointtype.thumbleft, JointType . Spineshoulder,jointtype.shoulderright, Jointtype.shoulderright,jointtype.elbowright, JointType.Elb Owright,jointtype.wristright, Jointtype.wristright,jointtype.handright, Jointtype.handright,jointt Ype.
            Handtipright, Jointtype.handright,jointtype.thumbright, Jointtype.spinebase,jointtype.hipleft, JointtypE.hipleft,jointtype.kneeleft, Jointtype.kneeleft,jointtype.ankleleft, Jointtype.ankleleft,jointtyp
            E.footleft, Jointtype.spinebase,jointtype.hipright, Jointtype.hipright,jointtype.kneeright, Jointtype.kneeright,jointtype.ankleright, jointtype.ankleright,jointtype.footright};

After forming the skeleton, the Kinect opens a variety of data flow patterns, using the overlay of color and skeleton data stream images, which can be opened by reference to the previous series, or Microsoft's PPT.

Here is the process of painting the skeleton and displaying a color image:

 Open multiple frames Multisourceframe MSF = E.framereference.acquireframe (); is not an empty if (MSF!= null) {//Open skeleton frame and color frame using (bodyframe Bodyframe = Msf. Bodyframereference.acquireframe ()) {using (Colorframe Colorframe = MSF.  Colorframereference.acquireframe ()) {//skeleton frames and color frames are not empty if
                        (Bodyframe!= null && colorframe!= null) {//Color frame copy to array Colorframe.copyconvertedframedatatoarray (This._colorp

                            Ixeldata, Colorimageformat.bgra); The array is written in place in Figure this._colorbitmap.writepixels (This._colorbitmaprect, This._colorpixeldata, This._colo

                            Rbitmapstride, 0);

                            Bone data Copy to array bodyframe.getandrefreshbodydata (this._bodies); Emptied to ensure that everyA frame is painted once CanvasBody.Children.Clear ();

                        Draw Skeleton drawbodies ();
        Draw skeleton, six persons private void Drawbodies () {///Traverse 6 players for (int i = 0; i < 6; i++) {if (this._bodies[i].i stracked = = true) {lstate.content = ' state ' +this._bodies[i]. Joints[jointtype.spinebase].
                    Trackingstate.tostring ();
                    Brush color = colorbody[i% 6];
                    Body onebody = This._bodies[i];
                        Connect a joint point 22 through a loop for (int j = 0; J < this._jointtype.length j = 2) {
                        Line line = new Line (); Line.
                        Stroke = color; Line.

                        StrokeThickness = 5; The screen of the beginnings sitsScreen coordinates for the mark and end point STARTP = Getjointpointscreen (Onebody.joints[this._jointtype[j]);

                        Point ENDP = Getjointpointscreen (onebody.joints[this._jointtype[j + 1]]);
                        Ellipse sp = new Ellipse ();

                        Ellipse EP = new Ellipse (); Sp.
                        Width = 15; Sp.
                        Height = 15; Sp.
                        HorizontalAlignment = HorizontalAlignment.Left; Sp.
                        VerticalAlignment = Verticalalignment.top; Sp.
                        Fill = brushes.red; Ep.
                        Width = 15; Ep.
                        Height = 15; Ep.
                        HorizontalAlignment = HorizontalAlignment.Left; Ep.
                        VerticalAlignment = Verticalalignment.top; Ep.

                        Fill = brushes.red; Sp. Margin = new Thickness (STARTP.X-SP. WIDTH/2, Startp.y-sp.
                        HEIGHT/2, 0, 0); Ep. Margin = new Thickness (ENDP.X-EP. WIDTH/2, Endp.y-ep.

                        HEIGHT/2, 0, 0); Sets the coordinate line for the starting point and end point.
                        X1 = startp.x; Line.
                        Y1 = STARTP.Y; Line.
                        X2 = endp.x; Line.

                        Y2 = ENDP.Y;
                        Add the start point, end point, and connection to the grid.
                        CANVASBODY.CHILDREN.ADD (SP);
                        CANVASBODY.CHILDREN.ADD (EP);
                    CANVASBODY.CHILDREN.ADD (line); }
                }
            }
and coordinate conversion processing: (using the Coordinatemapping class with the SDK)

Finally, the most important is because of different data flow resolution between different, to take the image overlap must coordinate transformation, the following will be the image of the skeleton into a color image of the way.

Attachment: This application is based on. net4.0. net4.5, which is written in WPF; the Kinect image is in fact equivalent to a mirrored relationship, like a mirror, where a lot of information is stored in the skeleton stream, such as tracking status.


	    Bone coordinates are transformed into color image coordinates
            colorspacepoint colorpoint = This._kinectdevice.coordinatemapper.mapcamerapointtocolorspace ( onejoint.position);

            Color image coordinates are converted to screen coordinates

            colorpoint.x = (int) ((Colorpoint.x * canvasbody.width)/1920);
            COLORPOINT.Y = (int) ((COLORPOINT.Y * canvasbody.height)/1080);

            Returns the point type variable return
            to New Point (Colorpoint.x, COLORPOINT.Y);


The following are some of the effect graphs:



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.