本文整理汇总了C#中Microsoft.Kinect.DepthImageFrame.CopyPixelDataTo方法的典型用法代码示例。如果您正苦于以下问题:C# DepthImageFrame.CopyPixelDataTo方法的具体用法?C# DepthImageFrame.CopyPixelDataTo怎么用?C# DepthImageFrame.CopyPixelDataTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Kinect.DepthImageFrame
的用法示例。
在下文中一共展示了DepthImageFrame.CopyPixelDataTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertDepthColor
/// <summary>
/// 距離データをカラー画像に変換する
/// </summary>
/// <param name="kinect"></param>
/// <param name="depthFrame"></param>
/// <returns></returns>
private byte[] ConvertDepthColor( KinectSensor kinect, DepthImageFrame depthFrame )
{
ColorImageStream colorStream = kinect.ColorStream;
DepthImageStream depthStream = kinect.DepthStream;
// 距離カメラのピクセルごとのデータを取得する
short[] depthPixel = new short[depthFrame.PixelDataLength];
depthFrame.CopyPixelDataTo( depthPixel );
// 距離カメラの座標に対応するRGBカメラの座標を取得する(座標合わせ)
ColorImagePoint[] colorPoint = new ColorImagePoint[depthFrame.PixelDataLength];
kinect.MapDepthFrameToColorFrame( depthStream.Format, depthPixel,
colorStream.Format, colorPoint );
byte[] depthColor = new byte[depthFrame.PixelDataLength * Bgr32BytesPerPixel];
for ( int index = 0; index < depthPixel.Length; index++ ) {
// 距離カメラのデータから、プレイヤーIDと距離を取得する
int player = depthPixel[index] & DepthImageFrame.PlayerIndexBitmask;
int distance = depthPixel[index] >> DepthImageFrame.PlayerIndexBitmaskWidth;
// 変換した結果が、フレームサイズを超えることがあるため、小さいほうを使う
int x = Math.Min( colorPoint[index].X, colorStream.FrameWidth - 1 );
int y = Math.Min( colorPoint[index].Y, colorStream.FrameHeight - 1 );
int colorIndex = ((y * depthFrame.Width) + x) * Bgr32BytesPerPixel;
if ( player != 0 ) {
depthColor[colorIndex] = 255;
depthColor[colorIndex + 1] = 255;
depthColor[colorIndex + 2] = 255;
}
else {
// サポート外 0-40cm
if ( distance == depthStream.UnknownDepth ) {
depthColor[colorIndex] = 0;
depthColor[colorIndex + 1] = 0;
depthColor[colorIndex + 2] = 255;
}
// 近すぎ 40cm-80cm(default mode)
else if ( distance == depthStream.TooNearDepth ) {
depthColor[colorIndex] = 0;
depthColor[colorIndex + 1] = 255;
depthColor[colorIndex + 2] = 0;
}
// 遠すぎ 3m(Near),4m(Default)-8m
else if ( distance == depthStream.TooFarDepth ) {
depthColor[colorIndex] = 255;
depthColor[colorIndex + 1] = 0;
depthColor[colorIndex + 2] = 0;
}
// 有効な距離データ
else {
depthColor[colorIndex] = 0;
depthColor[colorIndex + 1] = 255;
depthColor[colorIndex + 2] = 255;
}
}
}
return depthColor;
}
示例2: GetHeight
/// <summary>
/// 获取身高
/// </summary>
/// <param name="depthFrame">深度图像数据</param>
/// <returns></returns>
public int GetHeight(DepthImageFrame depthFrame)
{
int height;
short[] rawDepthData = new short[depthFrame.PixelDataLength];
depthFrame.CopyPixelDataTo(rawDepthData);
int Max = 0;
int Min = 480;
for (int depthIndex = 0; depthIndex < rawDepthData.Length; depthIndex++)
{
int player = rawDepthData[depthIndex] & DepthImageFrame.PlayerIndexBitmask;
if (player > 0)
{
int TempYdata = depthIndex / 640;
if (TempYdata > Max)
{
Max = TempYdata;
}
if (TempYdata < Min)
{
Min = TempYdata;
}
}
}
height = Max - Min;
return height;
}
示例3: Record
public void Record(DepthImageFrame frame)
{
// Header
writer.Write((int)KinectRecordOptions.Depth);
// Data
var time = DateTime.Now;
TimeSpan timeSpan = time.Subtract(referenceTime);
referenceTime = time;
writer.Write((long)timeSpan.TotalMilliseconds);
writer.Write(frame.BytesPerPixel);
writer.Write((int)frame.Format);
writer.Write(frame.Width);
writer.Write(frame.Height);
writer.Write(frame.FrameNumber);
// Bytes
short[] shorts = new short[frame.PixelDataLength];
frame.CopyPixelDataTo(shorts);
writer.Write(shorts.Length);
foreach (short s in shorts) {
writer.Write(s);
}
}
示例4: GenerateColoredBytes
private byte[] GenerateColoredBytes(DepthImageFrame depthFrame)
{
short[] rawDepthData = new short[depthFrame.PixelDataLength];
depthFrame.CopyPixelDataTo(rawDepthData);
Byte[] pixels = new byte[depthFrame.Height * depthFrame.Width * 4];
const int BlueIndex = 0;
const int GreenIndex = 1;
const int RedIndex = 2;
const int alpha = 3;
for (int depthIndex = 0, colorIndex = 0;
depthIndex < rawDepthData.Length && colorIndex < pixels.Length;
depthIndex++, colorIndex += 4)
{
int player = rawDepthData[depthIndex] & DepthImageFrame.PlayerIndexBitmask;
int depth = rawDepthData[depthIndex] >> DepthImageFrame.PlayerIndexBitmaskWidth;
if (depth <= 900)
{
pixels[colorIndex + BlueIndex] = 255; //closest objects blue
pixels[colorIndex + GreenIndex] = 0;
pixels[colorIndex + RedIndex] = 0;
pixels[colorIndex + alpha] = 255;
}
else if (depth < 2000)
{
pixels[colorIndex + BlueIndex] = 0;
pixels[colorIndex + GreenIndex] = 255; //medium depth is green
pixels[colorIndex + RedIndex] = 0;
pixels[colorIndex + alpha] = 255;
}
else
{
pixels[colorIndex + BlueIndex] = 0;
pixels[colorIndex + GreenIndex] = 0;
pixels[colorIndex + RedIndex] = 255; //farthest is red
pixels[colorIndex + alpha] = 255;
}
if (player > 0)
{
pixels[colorIndex + BlueIndex] = 0;
pixels[colorIndex + GreenIndex] = 255;
pixels[colorIndex + RedIndex] = 255;
pixels[colorIndex + alpha] = 255;
}
}
return pixels;
}
示例5: GenerateColoredBytes
private byte[] GenerateColoredBytes(DepthImageFrame depthFrame)
{
//get raw data from kinect
short[] rawDepthData = new short[depthFrame.PixelDataLength];
depthFrame.CopyPixelDataTo(rawDepthData);
Byte[] pixels = new byte[depthFrame.Width * depthFrame.Height * 4];
//constants
const int BlueIndex = 0;
const int GreenIndex = 1;
const int RedIndex = 2;
//loop through distances
for (int depthIndex = 0, colorIndex = 0; depthIndex < rawDepthData.Length && colorIndex < pixels.Length;
depthIndex++, colorIndex += 4)
{
//get player
int player = rawDepthData[depthIndex] & DepthImageFrame.PlayerIndexBitmask;
//get depth value
int depth = rawDepthData[depthIndex] >> DepthImageFrame.PlayerIndexBitmaskWidth;
//.9M or 2.95'
if (depth <= 900)
{
pixels[colorIndex + BlueIndex] = 0;
pixels[colorIndex + GreenIndex] = 0;
pixels[colorIndex + RedIndex] = 255;
}
//.9M - 2M or 2.95' - 6.26'
else if (depth > 900 && depth < 2000)
{
pixels[colorIndex + BlueIndex] = 0;
pixels[colorIndex + GreenIndex] = 255;
pixels[colorIndex + RedIndex] = 0;
}
//2M+ or 6.26'+
else if (depth > 2000)
{
pixels[colorIndex + BlueIndex] = 255;
pixels[colorIndex + GreenIndex] = 0;
pixels[colorIndex + RedIndex] = 0;
}
//byte intensity = CalculateIntensityFromDepth(depth);
//pixels[colorIndex + BlueIndex] = intensity;
//pixels[colorIndex + GreenIndex] = intensity;
//pixels[colorIndex + RedIndex] = intensity;
}
return pixels;
}
示例6: ApplyDistanceFilter
//distance given in inches
public BitmapSource ApplyDistanceFilter(DepthImageFrame frame, int dist)
{
double depthDist = dist * 25.4;
short[] depthArray = new short[frame.PixelDataLength];
frame.CopyPixelDataTo(depthArray);
depthArray = applyPixelFilter(depthArray, frame.Width, frame.Height);
// depthArray = applyWeightedAverageFilter(depthArray, frame.Width, frame.Height);
byte[] colorFrame = new byte[frame.Width * frame.Height * 4];
Parallel.For(0, frame.Height, i =>
{
// Process each pixel in the row
for (int j = 0; j < frame.Width; j++)
{
var distanceIndex = j + (i * frame.Width);
var index = distanceIndex * 4;
double depth = depthArray[distanceIndex]>> DepthImageFrame.PlayerIndexBitmaskWidth;
// Map the distance to an intesity that can be represented in RGB
if (depth < depthDist && depth > 0)
{
var intensity = CalculateIntensityFromDistance(depthArray[distanceIndex]);
colorFrame[index + BlueIndex] = intensity;
colorFrame[index + GreenIndex] = intensity;
colorFrame[index + RedIndex] = intensity;
colorFrame[index + AlphaIndex] = 250;
}
else
{
colorFrame[index + BlueIndex] = 112;
colorFrame[index + GreenIndex] = 25;
colorFrame[index + RedIndex] = 25;
colorFrame[index + AlphaIndex] = 200;
}
}
});
//rgba
BitmapSource bmps = BitmapSource.Create(frame.Width, frame.Height, 96, 96, PixelFormats.Bgra32, null, colorFrame, frame.Width * PixelFormats.Bgr32.BitsPerPixel / 8);
//rgb
//BitmapSource bmps = BitmapSource.Create(frame.Width, frame.Height, 96, 96, PixelFormats.Bgr32, null, colorFrame, frame.Width * PixelFormats.Bgr32.BitsPerPixel / 8);
return bmps;
}
示例7: GenerateColoredBytes
private static Byte[] GenerateColoredBytes(DepthImageFrame depthFrame, int minRange, int maxRange)
{
//get the raw data from kinect with the depth for every pixel
short[] rawDepthData = new short[depthFrame.PixelDataLength];
depthFrame.CopyPixelDataTo(rawDepthData);
//use depthFrame to create the image to display on-screen
//depthFrame contains color information for all pixels in image
//Height x Width x 4 (Red, Green, Blue, empty byte)
Byte[] pixels = new Byte[depthFrame.Height * depthFrame.Width * 4];
//Bgr32 - Blue, Green, Red, empty byte
//Bgra32 - Blue, Green, Red, transparency
//You must set transparency for Bgra as .NET defaults a byte to 0 = fully transparent
//hardcoded locations to Blue, Green, Red (BGR) index positions
const int BlueIndex = 0;
const int GreenIndex = 1;
const int RedIndex = 2;
//loop through all distances
//pick a RGB color based on distance
for (int depthIndex = 0, colorIndex = 0; depthIndex < rawDepthData.Length && colorIndex < pixels.Length; depthIndex++, colorIndex += 4)
{
int depth = rawDepthData[depthIndex] >> DepthImageFrame.PlayerIndexBitmaskWidth;
if (depth < 850 || depth > 4000)
{
pixels[colorIndex + BlueIndex] = 0;
pixels[colorIndex + GreenIndex] = 0;
pixels[colorIndex + RedIndex] = 0;
}
else if (depth <= minRange || depth > maxRange)
{
pixels[colorIndex + BlueIndex] = 0;
pixels[colorIndex + GreenIndex] = 0;
pixels[colorIndex + RedIndex] = 0;
}
else
{
pixels[colorIndex + BlueIndex] = 0;
pixels[colorIndex + GreenIndex] = 255;
pixels[colorIndex + RedIndex] = 0;
}
}
return pixels;
}
示例8: GetColoredBytes
byte[] GetColoredBytes(DepthImageFrame frame)
{
var depthData = new short[frame.PixelDataLength];
frame.CopyPixelDataTo(depthData);
//4 (Red, Green, Blue, empty byte)
var pixels = new byte[frame.Height * frame.Width * 4];
const int blueIndex = 0;
const int greenIndex = 1;
const int redIndex = 2;
//pick a RGB color based on distance
for (int depthIndex = 0, colorIndex = 0;
depthIndex < depthData.Length && colorIndex < pixels.Length;
depthIndex++, colorIndex += 4)
{
var player = depthData[depthIndex] & DepthImageFrame.PlayerIndexBitmask;
var depth = depthData[depthIndex] >> DepthImageFrame.PlayerIndexBitmaskWidth;
if (depth <= 900)
{
pixels[colorIndex + blueIndex] = 255;
pixels[colorIndex + greenIndex] = 0;
pixels[colorIndex + redIndex] = 0;
}
else if (depth > 900 && depth < 2000)
{
pixels[colorIndex + blueIndex] = 0;
pixels[colorIndex + greenIndex] = 255;
pixels[colorIndex + redIndex] = 0;
}
else if (depth > 2000)
{
pixels[colorIndex + blueIndex] = 0;
pixels[colorIndex + greenIndex] = 0;
pixels[colorIndex + redIndex] = 255;
}
if (player > 0)
{
pixels[colorIndex + blueIndex] = Colors.Gold.B;
pixels[colorIndex + greenIndex] = Colors.Gold.G;
pixels[colorIndex + redIndex] = Colors.Gold.R;
}
}
return pixels;
}
示例9: ConvertDepthToColorImage
/// <summary>
/// 距離データをカラー画像に変換する
/// </summary>
/// <param name="kinect"></param>
/// <param name="depthFrame"></param>
/// <returns></returns>
private byte[] ConvertDepthToColorImage(KinectSensor kinect, DepthImageFrame depthFrame)
{
DepthImageStream depthStream = kinect.DepthStream;
// 距離カメラのピクセルごとのデータを取得する
short[] depthPixel = new short[depthFrame.PixelDataLength];
depthFrame.CopyPixelDataTo(depthPixel);
byte[] depthColor = new byte[depthFrame.PixelDataLength * Bgr32BytesPerPixel];
for (int index = 0; index < depthPixel.Length; index++)
{
// 距離カメラのデータから、距離を取得する
int distance = depthPixel[index] >> DepthImageFrame.PlayerIndexBitmaskWidth;
int colorIndex = index * Bgr32BytesPerPixel;
// 赤:サポート外 0-40cm, 8m-
if (distance == depthStream.UnknownDepth)
{
depthColor[colorIndex] = 0;
depthColor[colorIndex + 1] = 0;
depthColor[colorIndex + 2] = 255;
}
// 緑:近すぎ 40cm-80cm(default mode)
else if (distance == depthStream.TooNearDepth)
{
depthColor[colorIndex] = 0;
depthColor[colorIndex + 1] = 255;
depthColor[colorIndex + 2] = 0;
}
// 青:遠すぎ 3m(Near),4m(Default)-8m
else if (distance == depthStream.TooFarDepth)
{
depthColor[colorIndex] = 255;
depthColor[colorIndex + 1] = 0;
depthColor[colorIndex + 2] = 0;
}
// 有効な距離データ
else
{
byte color = (byte)(255 * distance / depthStream.TooFarDepth);
depthColor[colorIndex] = 0;
depthColor[colorIndex + 1] = color;
depthColor[colorIndex + 2] = color;
}
}
return depthColor;
}
示例10: FromDepthImageFrame
public static ReplayDepthImageFrame FromDepthImageFrame(DepthImageFrame frame)
{
short[] pixelData = new short[frame.PixelDataLength];
frame.CopyPixelDataTo(pixelData);
return new ReplayDepthImageFrame()
{
FrameNumber = frame.FrameNumber,
BytesPerPixel = frame.BytesPerPixel,
PixelDataLength = frame.PixelDataLength,
Width = frame.Width,
Height = frame.Height,
Timestamp = frame.Timestamp,
PixelData = pixelData
};
}
示例11: Context_AllFramesUpdated
void Context_AllFramesUpdated(KinectSensor sensor, ColorImageFrame cf, DepthImageFrame df, SkeletonFrame sf)
{
this.sensor = sensor;
if (colorImage == null)
{
colorImage = new byte[cf.PixelDataLength];
depthImage = new short[df.PixelDataLength];
skeletonData = new Skeleton[sf.SkeletonArrayLength];
}
cf.CopyPixelDataTo(colorImage);
df.CopyPixelDataTo(depthImage);
sf.CopySkeletonDataTo(skeletonData);
TrackFace();
}
示例12: Generatecoloredbytes
private byte[] Generatecoloredbytes(DepthImageFrame depthframe)
{
short[] rawdepthdata = new short[depthframe.PixelDataLength];
depthframe.CopyPixelDataTo(rawdepthdata);
Byte[] pixels = new byte[depthframe.Height * depthframe.Width * 4];
const int blueindex = 0;
const int greenindex = 1;
const int redindex = 2;
for (int depthindex = 0, colorindex = 0; depthindex < rawdepthdata.Length && colorindex < pixels.Length; depthindex++, colorindex += 4)
{
int player = rawdepthdata[depthindex] & DepthImageFrame.PlayerIndexBitmask;
int depth = rawdepthdata[depthindex] >> DepthImageFrame.PlayerIndexBitmaskWidth;
if (depth <= 500)
{
pixels[colorindex + blueindex] = 255;
pixels[colorindex + greenindex] = 0;
pixels[colorindex + redindex] = 0;
}
else if (depth >= 500 && depth<= 1300)
{
pixels[colorindex + blueindex] = 0;
pixels[colorindex + greenindex] = 255;
pixels[colorindex + redindex] = 0;
}
else if (depth >1300 && depth<2000)
{
pixels[colorindex + blueindex] = 0;
pixels[colorindex + greenindex] = 0;
pixels[colorindex + redindex] = 255;
}
else if (depth >= 2000)
{
pixels[colorindex + blueindex] = 255;
pixels[colorindex + greenindex] = 255;
pixels[colorindex + redindex] = 0;
}
}
return pixels;
//throw new NotImplementedException();
}
示例13: GenerateColoredBytes
/// <summary>
/// 生成深度信息图像
/// </summary>
/// <param name="depthFrame">传入深入帧</param>
/// <returns>返回深度图像像素集</returns>
private byte[] GenerateColoredBytes(DepthImageFrame depthFrame)
{
short[] rawDepthData = new short[depthFrame.PixelDataLength];
depthFrame.CopyPixelDataTo(rawDepthData);
byte[] pixels = new byte[depthFrame.Width * depthFrame.Height * 4];
const int BlueIndex = 0;
const int GreenIndex = 1;
const int RedIndex = 2;
for (int depthIndex = 0, colorIndex = 0;
depthIndex < rawDepthData.Length && colorIndex < pixels.Length;
++depthIndex, colorIndex += 4)
{
int player = rawDepthData[depthIndex] & DepthImageFrame.PlayerIndexBitmask;
int depth = rawDepthData[depthIndex] >> DepthImageFrame.PlayerIndexBitmaskWidth;
if (depth <= 900)
{
pixels[colorIndex + BlueIndex] = 255;
pixels[colorIndex + GreenIndex] = 0;
pixels[colorIndex + RedIndex] = 0;
}
else if (depth > 900 && depth < 2000)
{
pixels[colorIndex + BlueIndex] = 0;
pixels[colorIndex + GreenIndex] = 255;
pixels[colorIndex + RedIndex] = 0;
}
else if (depth > 2000)
{
pixels[colorIndex + BlueIndex] = 0;
pixels[colorIndex + GreenIndex] = 0;
pixels[colorIndex + RedIndex] = 255;
}
byte intensity = CalculateIntensityFromeDepth(depth);
pixels[colorIndex + BlueIndex] = intensity;
pixels[colorIndex + GreenIndex] = intensity;
pixels[colorIndex + RedIndex] = intensity;
//if (player > 0)
//{
// pixels[colorIndex + BlueIndex] = Colors.Gold.B;
// pixels[colorIndex + GreenIndex] = Colors.Gold.G;
// pixels[colorIndex + RedIndex] = Colors.Gold.R;
//}
}
return pixels;
}
示例14: trimImage
private short[] trimImage(DepthImageFrame frame)
{
int pixeldatalength = frame.PixelDataLength;
short[] pixels = new short[pixeldatalength];
short[] newImagePixels = new short[153600];
frame.CopyPixelDataTo(pixels);
int newIndex = 0;
for (int x = 0; x < (640 * 320); x++)
{
if (x % 640 > 80 && x % 640 <= 560)
{
newImagePixels[newIndex] = pixels[x];
newIndex++;
}
}
return newImagePixels;
}
示例15: BackgroundMask
/// <summary>
/// プレーヤーだけ表示する
/// </summary>
/// <param name="colorFrame"></param>
/// <param name="depthFrame"></param>
/// <returns></returns>
private byte[] BackgroundMask( KinectSensor kinect,
ColorImageFrame colorFrame, DepthImageFrame depthFrame )
{
ColorImageStream colorStream = kinect.ColorStream;
DepthImageStream depthStream = kinect.DepthStream;
// RGBカメラのピクセルごとのデータを取得する
byte[] colorPixel = new byte[colorFrame.PixelDataLength];
colorFrame.CopyPixelDataTo( colorPixel );
// 距離カメラのピクセルごとのデータを取得する
short[] depthPixel = new short[depthFrame.PixelDataLength];
depthFrame.CopyPixelDataTo( depthPixel );
// 距離カメラの座標に対応するRGBカメラの座標を取得する(座標合わせ)
ColorImagePoint[] colorPoint = new ColorImagePoint[depthFrame.PixelDataLength];
kinect.MapDepthFrameToColorFrame( depthStream.Format, depthPixel,
colorStream.Format, colorPoint );
// 出力バッファ(初期値は白(255,255,255))
byte[] outputColor = new byte[colorPixel.Length];
for ( int i = 0; i < outputColor.Length; i += Bgr32BytesPerPixel ) {
outputColor[i] = 255;
outputColor[i + 1] = 255;
outputColor[i + 2] = 255;
}
for ( int index = 0; index < depthPixel.Length; index++ ) {
// プレイヤーを取得する
int player = depthPixel[index] & DepthImageFrame.PlayerIndexBitmask;
// 変換した結果が、フレームサイズを超えることがあるため、小さいほうを使う
int x = Math.Min( colorPoint[index].X, colorStream.FrameWidth - 1 );
int y = Math.Min( colorPoint[index].Y, colorStream.FrameHeight - 1 );
int colorIndex = ((y * depthFrame.Width) + x) * Bgr32BytesPerPixel;
// プレーヤーを検出した座標だけ、RGBカメラの画像を使う
if ( player != 0 ) {
outputColor[colorIndex] = colorPixel[colorIndex];
outputColor[colorIndex + 1] = colorPixel[colorIndex + 1];
outputColor[colorIndex + 2] = colorPixel[colorIndex + 2];
}
}
return outputColor;
}