c# - Kinect 2 fast handle frames -> low fps rate -


when use example color basics of kinect 2 , calculate time in millisecond between each image, it's around 30ms, when change inner code of function image event comment, time between frames are:

34,231,32,33,134,32,266,32,33,172,67,166,28,64,33,101,32,33,34,32,32,138,94,32,26 

and on (less 20 fps).

my computer using i7 (8 cures), total cpu 6% only, 8gb memory.. it's not problem.

relevant code:

public partial class mainwindow : window, inotifypropertychanged     {         /// <summary>         /// active kinect sensor         /// </summary>         private kinectsensor kinectsensor = null;          /// <summary>         /// reader color frames         /// </summary>         private colorframereader colorframereader = null;          /// <summary>         /// bitmap display         /// </summary>         private writeablebitmap colorbitmap = null;          /// <summary>         /// current status text display         /// </summary>         private string statustext = null;          /// <summary>         /// initializes new instance of mainwindow class.         /// </summary>         public mainwindow()         {             // kinectsensor object             this.kinectsensor = kinectsensor.getdefault();              // open reader color frames             this.colorframereader = this.kinectsensor.colorframesource.openreader();              // wire handler frame arrival             this.colorframereader.framearrived += this.reader_colorframearrived;              // create colorframedescription colorframesource using bgra format             framedescription colorframedescription = this.kinectsensor.colorframesource.createframedescription(colorimageformat.bgra);              // create bitmap display             this.colorbitmap = new writeablebitmap(colorframedescription.width, colorframedescription.height, 96.0, 96.0, pixelformats.bgr32, null);              // set isavailablechanged event notifier             this.kinectsensor.isavailablechanged += this.sensor_isavailablechanged;              // open sensor             this.kinectsensor.open();              // set status text             this.statustext = this.kinectsensor.isavailable ? properties.resources.runningstatustext                                                             : properties.resources.nosensorstatustext;              // use window object view model in simple example             this.datacontext = this;              // initialize components (controls) of window             this.initializecomponent();              sw.start();         }          stopwatch sw = new stopwatch();         /// <summary>         /// handles color frame data arriving sensor         /// </summary>         /// <param name="sender">object sending event</param>         /// <param name="e">event arguments</param>         private void reader_colorframearrived(object sender, colorframearrivedeventargs e)         {             system.console.writeline(sw.elapsedmilliseconds);             sw.restart();             // colorframe idisposable              // changed comment here:              /*using (colorframe colorframe = e.framereference.acquireframe())             {                 if (colorframe != null)                 {                     framedescription colorframedescription = colorframe.framedescription;                      using (kinectbuffer colorbuffer = colorframe.lockrawimagebuffer())                     {                         this.colorbitmap.lock();                          // verify data , write new color frame data display bitmap                         if ((colorframedescription.width == this.colorbitmap.pixelwidth) && (colorframedescription.height == this.colorbitmap.pixelheight))                         {                             colorframe.copyconvertedframedatatointptr(                                 this.colorbitmap.backbuffer,                                 (uint)(colorframedescription.width * colorframedescription.height * 4),                                 colorimageformat.bgra);                              this.colorbitmap.adddirtyrect(new int32rect(0, 0, this.colorbitmap.pixelwidth, this.colorbitmap.pixelheight));                         }                          this.colorbitmap.unlock();                     }                 }             }*/         }     } 

why , how solve it?

when "spend" enough time on function work perfect like:

for (int = 0 ; < 1000000; i++); 

i don't remember if used loop of 1 mil or 10 mil iterations (and it's depend computer), after use frame every 30ms.

it's bug of microsoft on kinect 2, last sdk release - 2.0 (and it's first).

pay attention: using thread.sleap wouldn't fix it.

so right solution (but bad) check run time (if fast) , spend time if needed.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -