本文整理汇总了C#中Microsoft.Kinect.DepthImageFrameReadyEventArgs.OpenDepthImageFrame方法的典型用法代码示例。如果您正苦于以下问题:C# DepthImageFrameReadyEventArgs.OpenDepthImageFrame方法的具体用法?C# DepthImageFrameReadyEventArgs.OpenDepthImageFrame怎么用?C# DepthImageFrameReadyEventArgs.OpenDepthImageFrame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Kinect.DepthImageFrameReadyEventArgs
的用法示例。
在下文中一共展示了DepthImageFrameReadyEventArgs.OpenDepthImageFrame方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: kinectSensor_DepthFrameReady
void kinectSensor_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
{
using (var frame = e.OpenDepthImageFrame())
{
if (frame == null)
return;
if (depthFrame32 == null)
{
pixelData = new short[frame.PixelDataLength];
depthFrame32 = new byte[frame.Width * frame.Height * sizeof(int)];
}
frame.CopyPixelDataTo(pixelData);
if (bitmap == null)
{
bitmap = new WriteableBitmap(frame.Width, frame.Height, 96, 96, PixelFormats.Bgra32, null);
image.Source = bitmap;
}
ConvertDepthFrame(pixelData);
int stride = bitmap.PixelWidth * sizeof(int);
Int32Rect dirtyRect = new Int32Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight);
bitmap.WritePixels(dirtyRect, depthFrame32, stride, 0);
}
}
示例2: SensorDepthFrameReady
/// <summary>
/// Event handler for Kinect sensor's DepthFrameReady event
/// </summary>
/// <param name="sender">object sending the event</param>
/// <param name="e">event arguments</param>
private void SensorDepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
{
using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
{
if (depthFrame != null)
{
// Copy the pixel data from the image to a temporary array
depthFrame.CopyPixelDataTo(this.depthPixels);
// Convert the depth to RGB
int width = 480;
int height = 640;
int start = width * (height / 2 - 1); //start at the beginning of the middle line
for (int i = 0; i < 480; ++i)
{
// discard the portion of the depth that contains only the player index
short depth = (short)(this.depthPixels[i + start] >> DepthImageFrame.PlayerIndexBitmaskWidth);
//find the angle to the left (if negative) or right (if positive) of the depth. The kinect's fov is 58
//so we halve it because it's going to be either left or right
double angle = (i - 240) / 29 * Math.PI / 180;
double xFromRBot = Math.Sin(angle) * depth;
double yFromRBot = Math.Cos(angle) * depth;
Vector2D posFromRBot = new Vector2D(xFromRBot, yFromRBot);
posFromRBot.translate(rbotPos);
posFromRBot.rotate(rbotAngle);
Vector2D absolutePos = posFromRBot;
}
}
}
}
示例3: Sensor_DepthFrameReady
void Sensor_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
{
using (DepthImageFrame imageFrame = e.OpenDepthImageFrame())
{
if (imageFrame != null)
{
depthMap = new Texture2D(Game.GraphicsDevice, imageFrame.Width, imageFrame.Height, false, SurfaceFormat.Color);
short[] data = new short[imageFrame.PixelDataLength];
Color[] depthData = new Color[imageFrame.Width * imageFrame.Height];
imageFrame.CopyPixelDataTo(data);
ConvertDepthFrame(data, Sensor.DepthStream, ref depthData);
depthMap.SetData<Color>(depthData);
}
else
{
// imageFrame is null because the request did not arrive in time
}
}
}
示例4: DepthFrameReady
private void DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
{
DepthImageFrame frame = e.OpenDepthImageFrame();
if (frame != null)
{
if (this.first || frame.Format != this.format)
{
this.InitBuffers(frame);
this.DisposeTextures();
}
this.FInvalidate = true;
this.frameindex = frame.FrameNumber;
lock (m_lock)
{
frame.CopyDepthImagePixelDataTo(this.depthpixels);
for (int i16 = 0; i16 < this.width * this.height; i16++)
{
this.rawdepth[i16] = this.depthpixels[i16].Depth;
}
}
frame.Dispose();
}
}
示例5: sensor_DepthFrameReady
unsafe void sensor_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
{
using (var image = e.OpenDepthImageFrame()) {
if (image != null) {
var data = new short[image.PixelDataLength];
image.CopyPixelDataTo(data);
BitmapData bitmapData = this.CurrentValue.LockBits(new System.Drawing.Rectangle(0, 0, this.Width, this.Height), ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
int pointer = 0;
int width = this.Width;
int height = this.Height;
for (int y = 0; y < height; y++) {
byte* pDest = (byte*)bitmapData.Scan0.ToPointer() + y * bitmapData.Stride;
for (int x = 0; x < width; x++, pointer++, pDest += 3) {
int realDepth = data[pointer] >> DepthImageFrame.PlayerIndexBitmaskWidth;
byte intensity = (byte)(~(realDepth >> 4));
pDest[0] = intensity;
pDest[1] = intensity;
pDest[2] = intensity;
}
}
this.CurrentValue.UnlockBits(bitmapData);
this.OnNewDataAvailable();
}
}
}
示例6: KinectOnDepthFrameReady
private void KinectOnDepthFrameReady(object sender, DepthImageFrameReadyEventArgs depthImageFrameReadyEventArgs)
{
using (DepthImageFrame temp = depthImageFrameReadyEventArgs.OpenDepthImageFrame())
{
if (temp == null) return;
short[] depthData = new short[640 * 480];
byte[] depthColorData = new byte[640 * 480 * 4];
temp.CopyPixelDataTo(depthData);
for (int i = 0, i32 = 0; i < depthData.Length && i32 < depthColorData.Length; i++, i32 += 4)
{
//深度情報のみ取得
int realDepth = depthData[i] >> DepthImageFrame.PlayerIndexBitmaskWidth;
//得られた深度を256段階のグレースケールに
byte intensity = (byte)(255 - (255 * realDepth / 4095));
depthColorData[i32] = intensity;
depthColorData[i32+1] = intensity;
depthColorData[i32+2] = intensity;
}
//深度情報の配列をBitmapにして表示
this.pictureBox1.Image = ConvertToBitmap(depthColorData, 640, 480);
}
}
示例7: kinect_DepthFrameReady
/// <summary>
/// 距離カメラのフレーム更新イベント
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void kinect_DepthFrameReady( object sender, DepthImageFrameReadyEventArgs e )
{
using ( var depthFrame = e.OpenDepthImageFrame() ) {
if ( depthFrame != null ) {
imageDepthCamera.Source = depthFrame.ToBitmapSource();
}
}
}
示例8: kinect_DepthFrameReady
// 距離カメラのフレーム更新イベント
void kinect_DepthFrameReady( object sender, DepthImageFrameReadyEventArgs e )
{
// Disposableなのでusingでくくる
using ( DepthImageFrame depthFrame = e.OpenDepthImageFrame() ) {
if ( depthFrame != null ) {
imageDepthCamera.Source = depthFrame.ToBitmapSource();
}
}
}
示例9: kinectRuntime_DepthFrameReady
void kinectRuntime_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
{
var frame = e.OpenDepthImageFrame();
if (frame == null)
return;
depthStreamManager.Update(frame);
}
示例10: kinect_DepthFrameReady
void kinect_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
{
ad++;
if (kinect != null && !depthFramyBusy)
{
var ts = new ThreadStart(delegate { depthFrameSetUp(e.OpenDepthImageFrame(), depthPixels, depthArray, depthTarget); });
new Thread(ts).Start();
}
}
示例11: sensor_DepthFrameReady
static void sensor_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
{
using (var depthFrame=e.OpenDepthImageFrame())
{
if (depthFrame == null) return;
short[] bits = new short[depthFrame.PixelDataLength];
depthFrame.CopyPixelDataTo(bits);
foreach (var bit in bits)
Console.Write(bit);
}
}
示例12: SensorDepthFrameReady
public void SensorDepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
{
using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
{
if (depthFrame != null)
{
// Copy the pixel data from the image to a temporary array
depthFrame.CopyDepthImagePixelDataTo(this.DepthPixels);
// Get the min and max reliable depth for the current frame
int minDepth = depthFrame.MinDepth;
int maxDepth = depthFrame.MaxDepth;
// Convert the depth to RGB
int colorPixelIndex = 0;
for (int i = 0; i < this.DepthPixels.Length; ++i)
{
// Get the depth for this pixel
short depth = DepthPixels[i].Depth;
// To convert to a byte, we're discarding the most-significant
// rather than least-significant bits.
// We're preserving detail, although the intensity will "wrap."
// Values outside the reliable depth range are mapped to 0 (black).
// Note: Using conditionals in this loop could degrade performance.
// Consider using a lookup table instead when writing production code.
// See the KinectDepthViewer class used by the KinectExplorer sample
// for a lookup table example.
byte intensity = (byte)(depth >= minDepth && depth <= maxDepth ? depth : 0);
// Write out blue byte
this.ColorPixels[colorPixelIndex++] = intensity;
// Write out green byte
this.ColorPixels[colorPixelIndex++] = intensity;
// Write out red byte
this.ColorPixels[colorPixelIndex++] = intensity;
// We're outputting BGR, the last byte in the 32 bits is unused so skip it
// If we were outputting BGRA, we would write alpha here.
++colorPixelIndex;
}
// Write the pixel data into our bitmap
this.ColorBitmap.WritePixels(
new Int32Rect(0, 0, this.ColorBitmap.PixelWidth, this.ColorBitmap.PixelHeight),
this.ColorPixels,
this.ColorBitmap.PixelWidth * sizeof(int),
0);
}
}
}
示例13: Sensor_DepthFrameReady
void Sensor_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
{
using (var frame = e.OpenDepthImageFrame())
{
if (frame != null)
{
if (_mode == Mode.Depth)
{
camera.Source = frame.ToBitmap();
}
}
}
}
示例14: sensor_DepthFrameReady
void sensor_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
{
using (DepthImageFrame depthImageFrame = e.OpenDepthImageFrame())
{
if (depthImageFrame == null)
{
return;
}
this.Camera.Source = ImageFrameExtensions.ToBitmapSource(depthImageFrame);
}
return;
}
示例15: DepthImageReady
/// <summary>
/// DepthImageReady:
/// This function will be called every time a new depth frame is ready
/// </summary>
private void DepthImageReady(object sender, DepthImageFrameReadyEventArgs e)
{
using (DepthImageFrame imageFrame = e.OpenDepthImageFrame())
{
//We expect this to be always true since we are coming from a triggered event
if (imageFrame != null)
{
//Check if the format of the image has changed.
//This always happens when you run the program for the first time and every time you minimize the window
bool NewFormat = this.lastImageFormat != imageFrame.Format;
if (NewFormat)
{
//Update the image to the new format
this.pixelData = new short[imageFrame.PixelDataLength];
this.depthFrame32 = new byte[imageFrame.Width * imageFrame.Height * Bgr32BytesPerPixel];
//Create the new Bitmap
this.outputBitmap = new WriteableBitmap(
imageFrame.Width,
imageFrame.Height,
96, // DpiX
96, // DpiY
PixelFormats.Bgr32,
null);
this.kinectDepthImage.Source = this.outputBitmap;
}
//Copy the stream to its short version
imageFrame.CopyPixelDataTo(this.pixelData);
//Convert the pixel data into its RGB Version.
//Here is where the magic happens
byte[] convertedDepthBits = this.ConvertDepthFrame(this.pixelData, ((KinectSensor)sender).DepthStream);
//Copy the RGB matrix to the bitmap to make it visible
this.outputBitmap.WritePixels(
new Int32Rect(0, 0, imageFrame.Width, imageFrame.Height),
convertedDepthBits,
imageFrame.Width * Bgr32BytesPerPixel,
0);
//Update the Format
this.lastImageFormat = imageFrame.Format;
}
//Since we are coming from a triggered event, we are not expecting anything here, at least for this short tutorial.
else { }
}
}