Skip to content
This repository has been archived by the owner on Mar 2, 2019. It is now read-only.

Commit

Permalink
RGB video capture is working!!!!!!!!!!
Browse files Browse the repository at this point in the history
todo: mask users and overlay textures and fix timing. SO CLOSE!
  • Loading branch information
Vincent Purcell committed Feb 22, 2013
1 parent ba2cca0 commit 7e33a80
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 52 deletions.
87 changes: 35 additions & 52 deletions HIVE_KinectGame/HIVE_KinectGame/HIVE_KinectGame/Game1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public class Game1 : Microsoft.Xna.Framework.Game
/// <summary>
/// The final rendered image with the screenscreen processed onto it.
/// </summary>
private Texture2D finalImage = null;
private Texture2D colorVideo = null;

/// <summary>
/// The index of which slide in the slideshow we look at.
Expand Down Expand Up @@ -273,11 +273,6 @@ public class Game1 : Microsoft.Xna.Framework.Game
private Boolean updateAlpha = false;
private int fadeAmount = 10;

/// <summary>
/// Intermediate storage for the color data received from the camera
/// </summary>
private Byte[] colorPixels = null;

/// <summary>
/// Intermediate storage for the depth data received from the sensor
/// </summary>
Expand Down Expand Up @@ -559,6 +554,23 @@ protected void kinect_AllFramesReady(object sender, AllFramesReadyEventArgs imag

Array.Clear(greenScreenPixelData, 0, greenScreenPixelData.Length);

//Create array for pixel data and copy it from the image frame
Byte[] pixelData = new Byte[colorFrame.PixelDataLength];
colorFrame.CopyPixelDataTo(pixelData);

//Convert RGBA to BGRA
Byte[] bgraPixelData = new Byte[colorFrame.PixelDataLength];
for (int i = 0; i < pixelData.Length; i += 4)
{
bgraPixelData[i] = pixelData[i + 2];
bgraPixelData[i + 1] = pixelData[i + 1];
bgraPixelData[i + 2] = pixelData[i];
bgraPixelData[i + 3] = (Byte)255; //The video comes with 0 alpha so it is transparent
}

this.colorVideo = new Texture2D(this.graphics.GraphicsDevice, colorFrame.Width, colorFrame.Height);
this.colorVideo.SetData(bgraPixelData);

this.foundPlayer = false;
// loop over each row and column of the depth
for (int y = 0; y < 480; ++y)
Expand Down Expand Up @@ -606,45 +618,18 @@ protected void kinect_AllFramesReady(object sender, AllFramesReadyEventArgs imag
// If we've found a player in the image, then run through the player mask
// and copy pixels from the RGB camera to a final image
// and save it as a screenshot.
if (true)//this.foundPlayer)
if (this.colorVideo != null && this.foundPlayer == true)
{
// get the RGB color frame image
// this.colorFrame.CopyPixelDataTo(this.colorPixels);
byte[] colorFrameData = null;
RenderTarget2D cameraTexture = new RenderTarget2D(this.GraphicsDevice, 640, 480);
using (var frame = this.kinect.ColorStream.OpenNextFrame(0))
{
if (frame != null)
{
if (colorFrameData == null || colorFrameData.Length != frame.PixelDataLength)
{
colorFrameData = new byte[frame.PixelDataLength];
}

frame.CopyPixelDataTo(colorFrameData);
GraphicsDevice.Textures[0] = null;
cameraTexture.SetData<byte>(colorFrameData);

// TODO: Process the image and merge the player onto our background scene.



//finalImage.SetData(this.greenScreenPixelData);
Stream stream = File.OpenWrite(this.Content.RootDirectory + "\\screenshots\\" + "snapshot-" + this.snapNumber + ".png");
cameraTexture.SaveAsPng(stream, 640, 480);
//this.finalImage.SaveAsPng(stream, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);
this.snapNumber++;
stream.Close();

}
}




}
Stream stream = File.OpenWrite(this.Content.RootDirectory + "\\screenshots\\" + "snapshot-" + this.snapNumber + ".png");
//this.colorVideo.SaveAsJpeg(stream, 640, 480);
this.colorVideo.SaveAsPng(stream, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);
this.snapNumber++;
stream.Close();
this.sceneJustChanged = true;
}
this.takeScreencap = false;
this.sceneJustChanged = true;

}


Expand Down Expand Up @@ -920,7 +905,7 @@ protected override void Draw(GameTime gameTime)
{
// Clear the screen so we don't have artifacts from updating.
GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.White);

#region DisplaySplashScreenState
// If we are in the intro graphic screen. This will only happen at game startup.
if (this.gameState == 0)
Expand Down Expand Up @@ -950,14 +935,6 @@ protected override void Draw(GameTime gameTime)
if (this.gameState == 1)
{

if (this.finalImage != null)
{
// TEMPORARY FORCE DRAW RGB
spriteBatch.Begin();
spriteBatch.Draw(this.finalImage, new Rectangle(0, 0, 640, 480), Microsoft.Xna.Framework.Color.White);
spriteBatch.End();
}

// If we are changing the 3D environment, then ensure we load a different background image than we just had.
if (this.sceneJustChanged == true)
{
Expand Down Expand Up @@ -1104,7 +1081,13 @@ protected override void Draw(GameTime gameTime)
}

#endregion

// Draw RGB video
/*if (this.colorVideo != null && this.takeScreencap == true)
{
spriteBatch.Begin();
spriteBatch.Draw(this.colorVideo, new Rectangle(0, 0, 640, 480), Microsoft.Xna.Framework.Color.White);
spriteBatch.End();
} */
base.Draw(gameTime);
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 7e33a80

Please sign in to comment.