c# - WPF application very slow - Kinect SDK 1.7 -
i have 1 simple application kinect seems consumes lot of resources. works 1-2 minutes , lag becomes unbearable.
this configuration:
intel core i3 cpu m330 2.13 ghz
4 gb ram
ati radeon hd 4570
this code application window:
public partial class mainwindow : window { public mainwindow() { initializecomponent(); loaded += mainwindow_loaded; } void mainwindow_loaded(object sender, routedeventargs e) { this.windowstate = system.windows.windowstate.maximized; } private void stopkinect(kinectsensor sensor) { if (sensor != null) { if (sensor.isrunning) { //stop sensor sensor.stop(); //stop audio if not null if (sensor.audiosource != null) { sensor.audiosource.stop(); } } } } private void window_closing_1(object sender, system.componentmodel.canceleventargs e) { stopkinect(generics.globalkinectsensorchooser.kinect); } }
this code main menu (first screen):
public partial class mainmenu : page { #region "kinect" private kinectsensorchooser sensorchooser; #endregion public mainmenu() { this.initializecomponent(); if (generics.globalkinectsensorchooser == null) { // initialize sensor chooser , ui this.sensorchooser = new kinectsensorchooser(); this.sensorchooser.kinectchanged += sensorchooseronkinectchanged; this.sensorchooserui.kinectsensorchooser = this.sensorchooser; this.sensorchooser.start(); generics.globalkinectsensorchooser = this.sensorchooser; } else { // initialize sensor chooser , ui this.sensorchooser = new kinectsensorchooser(); this.sensorchooser = generics.globalkinectsensorchooser; this.sensorchooser.kinectchanged += sensorchooseronkinectchanged; this.sensorchooserui.kinectsensorchooser = sensorchooser; } // bind sensor chooser's current sensor kinectregion var regionsensorbinding = new binding("kinect") { source = this.sensorchooser }; bindingoperations.setbinding(this.kinectregion, kinectregion.kinectsensorproperty, regionsensorbinding); } private void sensorchooseronkinectchanged(object sender, kinectchangedeventargs args) { bool error = false; if (args.oldsensor != null) { try { args.oldsensor.depthstream.range = depthrange.default; args.oldsensor.skeletonstream.enabletrackinginnearrange = false; args.oldsensor.depthstream.disable(); args.oldsensor.skeletonstream.disable(); args.oldsensor.colorstream.disable(); } catch (invalidoperationexception) { // kinectsensor might enter invalid state while enabling/disabling streams or stream features. // e.g.: sensor might abruptly unplugged. error = true; } } if (args.newsensor != null) { try { args.newsensor.depthstream.enable(depthimageformat.resolution640x480fps30); args.newsensor.colorstream.enable(colorimageformat.rgbresolution640x480fps30); args.newsensor.skeletonstream.enable(); } catch (invalidoperationexception) { error = true; } } if (!error) kinectregion.kinectsensor = args.newsensor; } private void screen1buttononclick(object sender, routedeventargs e) { this.sensorchooser.kinectchanged -= sensorchooseronkinectchanged; (application.current.mainwindow.findname("_mainframe") frame).source = new uri("depth.xaml", urikind.relative); } }
and code screen1:
public partial class depth : page { #region "kinect" private kinectsensorchooser sensorchooser; #endregion const float maxdepthdistance = 4095; // max value returned const float mindepthdistance = 850; // min value returned const float maxdepthdistanceoffset = maxdepthdistance - mindepthdistance; public depth() { this.initializecomponent(); // initialize sensor chooser , ui this.sensorchooser = new kinectsensorchooser(); //assign sensor chooser sensor chooser mainwindow. //we reusing sensorchoosing declared in first window can in contact kinect this.sensorchooser = generics.globalkinectsensorchooser; //subscribe sensorchooseronkinectchanged event this.sensorchooser.kinectchanged += sensorchooseronkinectchanged; //assign kinect sensorchooser sensorchooser got our static class this.sensorchooserui.kinectsensorchooser = sensorchooser; // bind sensor chooser's current sensor kinectregion var regionsensorbinding = new binding("kinect") { source = this.sensorchooser }; bindingoperations.setbinding(this.kinectregion, kinectregion.kinectsensorproperty, regionsensorbinding); } private void sensorchooseronkinectchanged(object sender, kinectchangedeventargs args) { bool error = false; if (args.oldsensor != null) { try { args.oldsensor.depthstream.range = depthrange.default; args.oldsensor.skeletonstream.enabletrackinginnearrange = false; args.oldsensor.depthstream.disable(); args.oldsensor.skeletonstream.disable(); args.oldsensor.colorstream.disable(); } catch (invalidoperationexception) { error = true; } } if (args.newsensor != null) { try { args.newsensor.depthstream.enable(depthimageformat.resolution640x480fps30); args.newsensor.colorstream.enable(colorimageformat.rgbresolution640x480fps30); args.newsensor.skeletonstream.enable(); } catch (invalidoperationexception) { error = true; } } if (!error) kinectregion.kinectsensor = args.newsensor; } private void menubuttononclick(object sender, routedeventargs e) { //unsubscribe sensorchooser's event sensorchooseronkinectchanged this.sensorchooser.kinectchanged -= sensorchooseronkinectchanged; (application.current.mainwindow.findname("_mainframe") frame).source = new uri("mainscreen.xaml", urikind.relative); } }
there couple of more screens, choosed screen i'm using kinectdepthviewer wpfviewers. screen has worst lag, application unusable instantly. other screens have buttons don't have lag @ beginning after 2-3 minutes of usage.
i don't know doing wrong in initialization maybe. hope has advice. i've read people didn't have problems development on weaker configurations hope it's not because of that.
thank you!
your graphics adapter suggests you're using notebook computer. while there might in code improved, think problem hardware. notebooks specs listed have trouble running cpu intensive you're trying kinect.
Comments
Post a Comment