Skip to content

Commit

Permalink
More changes to PreviewControl. RGB/IR work in 8 bit formats. Depth w…
Browse files Browse the repository at this point in the history
…orks in 10/11 bit formats.

Signed-off-by: Aditya Gaddam <adityagaddam@gmail.com> (LostInCake)
  • Loading branch information
lostinspacebar committed May 21, 2011
1 parent fc667d3 commit 02459b6
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 24 deletions.
15 changes: 13 additions & 2 deletions wrappers/csharp/src/test/KinectDemo/MainWindow.UI.cs
Expand Up @@ -229,6 +229,15 @@ private void InitializeComponents()
this.contentPanel.Controls.Add(this.previewControl);
this.contentPanel.Controls.Add(this.controlsPanel);

///
/// aboutButton
///
this.aboutButton = new ToolStripButton();
this.aboutButton.Text = "About";
this.aboutButton.Padding = new Padding(7, 0, 7, 0);
this.aboutButton.Margin = new Padding(10, 7, 0, 7);
this.aboutButton.Click += HandleAboutButtonClick;

///
/// disconnectButton
///
Expand Down Expand Up @@ -277,12 +286,13 @@ private void InitializeComponents()
this.mainToolbar.Items.Add(this.refreshButton);
this.mainToolbar.Items.Add(this.connectButton);
this.mainToolbar.Items.Add(this.disconnectButton);
this.mainToolbar.Items.Add(this.aboutButton);

///
/// MainWindow
///
this.Width = 1300;
this.Height = 650;
this.Width = 1280;
this.Height = 630;
this.Text = "Kinect.NET Demo";
this.Font = new Font(this.Font.FontFamily, 9.0f);
this.Controls.Add(this.contentPanel);
Expand Down Expand Up @@ -320,6 +330,7 @@ private void InitializeComponents()
private ToolStripButton refreshButton;
private ToolStripButton connectButton;
private ToolStripButton disconnectButton;
private ToolStripButton aboutButton;

private GroupBox selectVideoModeGroup;
private ComboBox selectVideoModeCombo;
Expand Down
101 changes: 89 additions & 12 deletions wrappers/csharp/src/test/KinectDemo/MainWindow.cs
Expand Up @@ -4,6 +4,8 @@
using System.Windows.Forms;
using System.Threading;
using freenect;
using System.Drawing;
using System.Diagnostics;

namespace KinectDemo
{
Expand Down Expand Up @@ -65,14 +67,12 @@ private void UpdateDeviceList()

// Enable buttons
this.connectButton.Visible = this.connectButton.Enabled = true;
this.refreshButton.Visible = this.refreshButton.Enabled = true;
this.disconnectButton.Visible = false;
}
else
{
// Disable buttons
this.connectButton.Visible = false;
this.refreshButton.Visible = false;
this.disconnectButton.Visible = false;
}
}
Expand All @@ -87,11 +87,6 @@ private void UpdateModeList()
this.selectVideoModeCombo.Items.Add("Disabled");
foreach(var mode in this.kinect.VideoCamera.Modes)
{
if(mode.Format == VideoFormat.InfraredPacked10Bit)
{
// Don't do packed for now
continue;
}
string videoMode = mode.Width + "x" + mode.Height + " : " + mode.Format;
this.selectVideoModeCombo.Items.Add(videoMode);
}
Expand All @@ -107,11 +102,6 @@ private void UpdateModeList()
this.selectDepthModeCombo.Items.Add("Disabled");
foreach(var mode in this.kinect.DepthCamera.Modes)
{
if(mode.Format == DepthFormat.DepthPacked10Bit || mode.Format == DepthFormat.DepthPacked11Bit)
{
// Don't do packed for now
continue;
}
string depthMode = mode.Width + "x" + mode.Height + " : " + mode.Format;
this.selectDepthModeCombo.Items.Add(depthMode);
}
Expand Down Expand Up @@ -260,6 +250,8 @@ private void HandleStatusUpdateTimerTick (object sender, EventArgs e)
this.accelerometerXValueLabel.Text = Math.Round(this.kinect.Accelerometer.X, 2).ToString();
this.accelerometerYValueLabel.Text = Math.Round(this.kinect.Accelerometer.Y, 2).ToString();
this.accelerometerZValueLabel.Text = Math.Round(this.kinect.Accelerometer.Z, 2).ToString();

this.Text = "Kinect.NET Demo - Video FPS: " + this.previewControl.VideoFPS + " | Depth FPS: " + this.previewControl.DepthFPS;
}

/// <summary>
Expand Down Expand Up @@ -346,6 +338,20 @@ private void HandleDisconnectButtonClick (object sender, EventArgs e)
this.Disconnect();
}

/// <summary>
/// Handle about button
/// </summary>
/// <param name="sender">
/// A <see cref="System.Object"/>
/// </param>
/// <param name="e">
/// A <see cref="EventArgs"/>
/// </param>
private void HandleAboutButtonClick (object sender, EventArgs e)
{
new AboutWindow().ShowDialog();
}

/// <summary>
/// Handle depth mode being changed
/// </summary>
Expand Down Expand Up @@ -461,5 +467,76 @@ private void HandleVideoPreviewWindowFormClosing (object sender, FormClosingEven
e.Cancel = true;
this.selectVideoModeCombo.SelectedIndex = 0;
}

/// <summary>
/// About Window
/// </summary>
private class AboutWindow : Form
{
public AboutWindow()
{

///
/// linkLabel
///
LinkLabel linkLabel = new LinkLabel();
linkLabel.Text = "openkinect.org";
linkLabel.Click += delegate(object sender, EventArgs e)
{
Process.Start("http://openkinect.org/wiki/CSharp_Wrapper");
};
linkLabel.Dock = DockStyle.Top;

///
/// authorLabel
///
Label authorLabel = new Label();
authorLabel.Text = "by Aditya Gaddam";
authorLabel.Dock = DockStyle.Top;

///
/// titleLabel
///
Label titleLabel = new Label();
titleLabel.Text = "Kinect.NET Demo";
titleLabel.Font = new Font(this.Font.FontFamily, 14.0f);
titleLabel.Dock = DockStyle.Top;

///
/// logoImageBox
///
PictureBox logoPictureBox = new PictureBox();
logoPictureBox.Image = Image.FromFile("openkinect_logo.png");
logoPictureBox.Dock = DockStyle.Left;
logoPictureBox.Width = 96;

///
/// aboutContentPanel
///
Panel aboutContentPanel = new Panel();
aboutContentPanel.Dock = DockStyle.Fill;
aboutContentPanel.Controls.Add(linkLabel);
aboutContentPanel.Controls.Add(authorLabel);
aboutContentPanel.Controls.Add(titleLabel);
aboutContentPanel.Padding = new Padding(7, 0, 0, 0);

///
/// AboutWindow
///
this.ShowInTaskbar = false;
//this.FormBorderStyle = FormBorderStyle.FixedSingle;
this.MinimizeBox = false;
this.MaximizeBox = false;
this.StartPosition = FormStartPosition.CenterScreen;
this.Text = "About";
this.Width = 350;
this.Height = 140;
this.Font = new System.Drawing.Font(this.Font.FontFamily, 9.0f);
this.BackColor = Color.White;
this.Controls.Add(aboutContentPanel);
this.Controls.Add(logoPictureBox);
this.Padding = new Padding(7);
}
}
}
}
56 changes: 56 additions & 0 deletions wrappers/csharp/src/test/KinectDemo/PreviewControl.cs
Expand Up @@ -96,6 +96,24 @@ public IntPtr DepthBackBuffer
}
}

/// <summary>
/// Gets the FPS for the depth feed
/// </summary>
public int DepthFPS
{
get;
private set;
}

/// <summary>
/// Gets the FPS for the video feed
/// </summary>
public int VideoFPS
{
get;
private set;
}

/// <summary>
/// Video mode
/// </summary>
Expand Down Expand Up @@ -149,6 +167,26 @@ public IntPtr DepthBackBuffer
// Gamma constants for color map generation
private UInt16[] gamma = new UInt16[2048];

/// <summary>
/// Last time FPS was updated for Depth
/// </summary>
private DateTime lastDepthFPSUpate = DateTime.Now;

/// <summary>
/// Number of frames since last FPS update for depth
/// </summary>
private int depthFrameCount = 0;

/// <summary>
/// Last time FPS was updated for video
/// </summary>
private DateTime lastVideoFPSUpdate = DateTime.Now;

/// <summary>
/// Number of frames since last FPS update for video
/// </summary>
private int videoFrameCount = 0;

/// <summary>
/// Constructor
/// </summary>
Expand All @@ -174,6 +212,15 @@ public void HandleVideoBackBufferUpdate()
// Swap middle and back buffers
this.videoDataBuffers.Swap(1, 2);

// Calculate FPS
this.videoFrameCount++;
if((DateTime.Now - this.lastVideoFPSUpdate).Seconds >= 1)
{
this.VideoFPS = this.videoFrameCount;
this.videoFrameCount = 0;
this.lastVideoFPSUpdate = DateTime.Now;
}

// New data!
this.videoDataPending = true;
}
Expand Down Expand Up @@ -235,6 +282,15 @@ public void HandleDepthBackBufferUpdate()
}
}

// Calculate FPS
this.depthFrameCount++;
if((DateTime.Now - this.lastDepthFPSUpate).Seconds >= 1)
{
this.DepthFPS = this.depthFrameCount;
this.depthFrameCount = 0;
this.lastDepthFPSUpate = DateTime.Now;
}

// New data!
this.depthDataPending = true;
}
Expand Down
6 changes: 6 additions & 0 deletions wrappers/csharp/src/test/KinectDemo/VS2008/KinectDemo.csproj
Expand Up @@ -82,4 +82,10 @@
<HintPath>..\..\..\..\bin\freenect.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="..\openkinect_logo.png">
<Link>openkinect_logo.png</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Binary file modified wrappers/csharp/src/test/KinectDemo/VS2008/KinectDemo.pidb
Binary file not shown.
11 changes: 1 addition & 10 deletions wrappers/csharp/src/test/KinectDemo/VS2008/KinectDemo.userprefs
@@ -1,15 +1,6 @@
<Properties>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" ctype="Workspace" />
<MonoDevelop.Ide.Workbench ActiveDocument="../PreviewControl.cs" ctype="Workbench">
<Files>
<File FileName="../MainWindow.cs" Line="426" Column="21" />
<File FileName="../MainWindow.UI.cs" Line="290" Column="42" />
<File FileName="../PreviewControl.cs" Line="247" Column="29" />
<File FileName="../PreviewControl.UI.cs" Line="34" Column="31" />
<File FileName="../PreviewWindow.cs" Line="1" Column="1" />
<File FileName="../DepthPreviewWindow.cs" Line="210" Column="4" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.Workbench ctype="Workbench" />
<MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore />
</MonoDevelop.Ide.DebuggingService.Breakpoints>
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 02459b6

Please sign in to comment.