Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7965973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:17:51+00:00 2026-06-04T06:17:51+00:00

I am new to Kinect. i am trying to use skeleton tracking but i

  • 0

I am new to Kinect. i am trying to use skeleton tracking but i kept receiving this warning “Warning: An ImageFrame instance was not Disposed.”. Do you know any solution for that ?

Here is my code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Kinect;
using Coding4Fun.Kinect.Wpf;
using System.Diagnostics;
using System.IO;

namespace KinectSkeleton
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        bool closing = false;
        const int skeletonCount = 6;
        Skeleton[] allSkeletons = new Skeleton[skeletonCount];

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            myKinectSensorChooser.KinectSensorChanged += new DependencyPropertyChangedEventHandler(myKinectSensorChooser_KinectSensorChanged);
        }

        void myKinectSensorChooser_KinectSensorChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            KinectSensor oldSensor = (KinectSensor)e.OldValue;
            if (oldSensor != null)
            {
                oldSensor.Stop();
                oldSensor.AudioSource.Stop();
            }

            KinectSensor mySensor = (KinectSensor)e.NewValue;
            if (mySensor == null)
                return;

            mySensor.DepthStream.Enable(DepthImageFormat.Resolution320x240Fps30);
            mySensor.ColorStream.Enable();
            mySensor.SkeletonStream.Enable();
            mySensor.AllFramesReady += new EventHandler<AllFramesReadyEventArgs>(mySensor_AllFramesReady);

            try
            {
                mySensor.Start();
                Debug.WriteLine("Starting Sensor .....");
                Debug.WriteLine("The Current Elevation Angle is: " + mySensor.ElevationAngle.ToString());
                mySensor.ElevationAngle = 0;
            }
            catch (System.IO.IOException)
            {
                //another app is using Kinect
                myKinectSensorChooser.AppConflictOccurred();
            }
        }

        void mySensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            if (closing)
                return;

            byte[] depthImagePixels;
            DepthImageFrame depthFrame = e.OpenDepthImageFrame();
            if (depthFrame == null)
                return;

            depthImagePixels = GenerateDepthImage(depthFrame);
            int stride = depthFrame.Width*4;
            image1.Source =
                BitmapSource.Create(depthFrame.Width, depthFrame.Height,
                96, 96, PixelFormats.Bgr32, null, depthImagePixels, stride);


            //Get a skeleton
            Skeleton first = GetFirstSkeleton(e);
            if (first == null)
                return;

            Debug.WriteLine("Head Position is : " + first.Joints[JointType.Head].ToString());

            depthFrame.Dispose();

        }

        private byte[] GenerateDepthImage(DepthImageFrame depthFrame)
        {
            //get the raw data from the frame with the depth for every pixel
            short[] rawDepthData = new short[depthFrame.PixelDataLength];
            depthFrame.CopyPixelDataTo(rawDepthData);

            //use frame to create the image to display on-screen
            //frame contains color information for all pixels in image
            //Height x Width x 4 (Red, Green, Blue, empty byte)
            Byte[] pixels = new byte[depthFrame.Height * depthFrame.Width * 4];

            //hardcoded locations to Blue, Green, Red (BGR) index positions       
            const int BlueIndex = 0;
            const int GreenIndex = 1;
            const int RedIndex = 2;
            int player, depth;

            //loop through all distances
            //pick a RGB color based on distance
            for (int depthIndex = 0, colorIndex = 0;
                depthIndex < rawDepthData.Length && colorIndex < pixels.Length;
                depthIndex++, colorIndex += 4)
            {
                //get the player (requires skeleton tracking enabled for values)
                player = rawDepthData[depthIndex] & DepthImageFrame.PlayerIndexBitmask;

                //gets the depth value
                depth = rawDepthData[depthIndex] >> DepthImageFrame.PlayerIndexBitmaskWidth;

                if (player > 0)
                {
                    pixels[colorIndex + BlueIndex] = Colors.Gold.B;
                    pixels[colorIndex + GreenIndex] = Colors.Gold.G;
                    pixels[colorIndex + RedIndex] = Colors.Gold.R;
                }
                else
                {
                    pixels[colorIndex + BlueIndex] = Colors.Green.B;
                    pixels[colorIndex + GreenIndex] = Colors.Green.G;
                    pixels[colorIndex + RedIndex] = Colors.Green.R;
                }
            }
            //depthFrame.Dispose();
            return pixels;
        }

        Skeleton GetFirstSkeleton(AllFramesReadyEventArgs e)
        {
            using (SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame())
            {
                if (skeletonFrameData == null)
                {
                    return null;
                }
                skeletonFrameData.CopySkeletonDataTo(allSkeletons);

                //get the first tracked skeleton
                Skeleton first = (from s in allSkeletons
                                  where s.TrackingState == SkeletonTrackingState.Tracked
                                  select s).FirstOrDefault();

                return first;
            }
        }

        void StopKinect(KinectSensor sensor)
        {
            if (sensor != null)
            {
                if (sensor.IsRunning)
                {
                    sensor.ElevationAngle = 0;
                    sensor.Stop();
                    if (sensor.AudioSource != null)
                    {
                        sensor.AudioSource.Stop();
                    }
                }
            }
        }
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            closing = true;
            Debug.WriteLine("Closing window...");
            StopKinect(myKinectSensorChooser.Kinect);
        }
    }
}

Thanks a lot,
Michael

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:17:52+00:00Added an answer on June 4, 2026 at 6:17 am

    in method mySensor_AllFramesReady you wrote

           //Get a skeleton
            Skeleton first = GetFirstSkeleton(e);
            if (first == null)
                return; // Here if first skeleton is null then you are returning without disposing depthFrame frame.
    

    Use using block while opening the depth frame as below

      using(DepthImageFrame depthFrame = e.OpenDepthImageFrame())
      {
            if (depthFrame == null)
                return;
    
            depthImagePixels = GenerateDepthImage(depthFrame);
            int stride = depthFrame.Width*4;
            image1.Source =
                BitmapSource.Create(depthFrame.Width, depthFrame.Height,
                96, 96, PixelFormats.Bgr32, null, depthImagePixels, stride);
    
    
            //Get a skeleton
            Skeleton first = GetFirstSkeleton(e);
            if (first == null)
                return;
    
            Debug.WriteLine("Head Position is : " + first.Joints[JointType.Head].ToString());
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use Microsoft Kinect, for audio recognition. This is on a
I'm a new comer to the kinect environment, and i was trying to modify
New programmer here, I am trying to understand and break down this code below
New to Windows Azure was not sure if its a good idea to use
This is a pretty simple issue but I am new to Python and I
I'm trying to recognize rectangular boxes using Kinect, I know I can use OpenCV
I'm trying to upgrade my Kinect SDK to the new version and having some
I am trying to use a KinectColorViewer in a project using Kinect for windows
I'm new to C++ and trying to add OpenCV into Microsoft's Kinect samples. I
I trying to do some Joint Tracking with kinect (just put a ellipse inside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.