none
As soon as video is turned on computer crashes RRS feed

  • Question

  • I have this section of code, it works fine without the video data, the skeletal data capture is very quick. However as soon as I turn on the video input, the CPU usage goes crazy and the program just crashes. I can't figure out whats gong on, can anyone help?

     

        public void StartMotionTracking()
        {
          backgroundWorker2.RunWorkerAsync();
        }
    
        private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
          nui = new Runtime();
    
          try
          {
            nui.Initialize(RuntimeOptions.UseSkeletalTracking | RuntimeOptions.UseColor);
            nui.SkeletonEngine.TransformSmooth = true;
    
            var parameters = new TransformSmoothParameters
            {
              Smoothing = 0.75f,
              Correction = 0.0f,
              Prediction = 0.0f,
              JitterRadius = 0.05f,
              MaxDeviationRadius = 0.04f
            };
    
            nui.SkeletonEngine.SmoothParameters = parameters;
    
            nui.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color);
          }
          catch (InvalidOperationException)
          {
            System.Windows.MessageBox.Show
              ("There is a problem with the Kinect device. Please make sure the device is plugged in.");
    
            startUp.Show();
    
            this.Hide();
    
            return;
          }
    
          this.backgroundWorker1.RunWorkerAsync();
    
          nui.VideoFrameReady += new EventHandler<ImageFrameReadyEventArgs>(nui_ImageFrameReady);
          nui.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(nui_SkeletonFrameReady);
        }
    
        void nui_ImageFrameReady(object sender, ImageFrameReadyEventArgs e)
        {
          PlanarImage Image = e.ImageFrame.Image;
          Bitmap bmap = PImageToBitmap(Image);
          pictureBox1.Image = bmap;
        }
    
        Bitmap PImageToBitmap(PlanarImage PImage)
        {
          Bitmap bmap = new Bitmap(PImage.Width, PImage.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
    
          BitmapData bmapdata = bmap.LockBits(new System.Drawing.Rectangle(0, 0, PImage.Width, PImage.Height), 
            ImageLockMode.WriteOnly, bmap.PixelFormat);
    
          IntPtr ptr = bmapdata.Scan0;
          Marshal.Copy(PImage.Bits, 0, ptr, PImage.Width * PImage.BytesPerPixel * PImage.Height);
    
          bmap.UnlockBits(bmapdata);
    
          return bmap;
        }
    


    Saturday, July 2, 2011 5:12 PM

Answers

  • chris,

    I'd like to help you, so could you give me a couple more details such as:

    - what is your application callstack when it crashes?
    - what is the specific exception thrown?
    - what is the debug output?
    - does this only happen with RuntimeOptions.UseColor, or also with RuntimeOptions.UseDepth?

    Eddy


    I'm here to help
    Thursday, July 7, 2011 12:10 AM
  • I would say eddy is right but if all else fails trying reinstalling the sdk which includes the drivers and it will install the drivers fresh. Make sure to uninstall the kinect drivers in device manager first. I found similar programs stopped behaving this way after this but it could just be a simple code error too. Never know till you try.
    Thursday, July 28, 2011 1:54 PM

All replies

  • chris,

    I'd like to help you, so could you give me a couple more details such as:

    - what is your application callstack when it crashes?
    - what is the specific exception thrown?
    - what is the debug output?
    - does this only happen with RuntimeOptions.UseColor, or also with RuntimeOptions.UseDepth?

    Eddy


    I'm here to help
    Thursday, July 7, 2011 12:10 AM
  • Hi Eddy,

    Thanks for the help, its appreciated.

    I've been working on it for a couple of days now and managed to smooth out some of the errors.I think the biggest problem was that there was too much code for the program to run eefectively in debug mode as there was such a low FPS rate.

    The biggest problem I seem to have now that I;ve narrowed it down to is that my nui_SKeletonFrameReady loop doesn't complete before nui_videoFrameReady loop is called and hence sections of the code are never used. Any reason why this would happen?


    • Edited by chris_golby Thursday, August 18, 2011 3:38 PM
    Friday, July 8, 2011 7:21 AM
  • Are you saying that nui_ImageFrameReady method (from code above) never gets called? I.e.: you set a breakpoint there and it is never hit?

    Eddy


    I'm here to help
    Friday, July 8, 2011 10:27 PM
  • I would say eddy is right but if all else fails trying reinstalling the sdk which includes the drivers and it will install the drivers fresh. Make sure to uninstall the kinect drivers in device manager first. I found similar programs stopped behaving this way after this but it could just be a simple code error too. Never know till you try.
    Thursday, July 28, 2011 1:54 PM