Skip to content

Instantly share code, notes, and snippets.

@yjiro0403
Last active June 27, 2016 03:34
Show Gist options
  • Save yjiro0403/2aa88d66ae413807288c5797c7bffc78 to your computer and use it in GitHub Desktop.
Save yjiro0403/2aa88d66ae413807288c5797c7bffc78 to your computer and use it in GitHub Desktop.
KinectのRGB-Dデータからポイントクラウドを生成してみた ref: http://qiita.com/yjiro0403/items/405e180ee5d1701d6b15
for (int y = 0; y < depthHeight; y += 2)
{
for (int x = 0; x < depthWidth; x += 2)
{
int depthIndex = (y * depthWidth) + x;
CameraSpacePoint p = cameraSpacePoints[depthIndex];
ColorSpacePoint colorPoint = colorSpacePoints[depthIndex];
byte r = 0;
byte g = 0;
byte b = 0;
byte a = 0;
int colorX = (int)System.Math.Floor(colorPoint.X + 0.5);
int colorY = (int)System.Math.Floor(colorPoint.Y + 0.5);
if ((colorX >= 0) && (colorX < colorWidth) && (colorY >= 0) && (colorY < colorHeight))
{
int colorIndex = ((colorY * colorWidth) + colorX) * bytesPerPixel;
int displayIndex = depthIndex * bytesPerPixel;
b = colorFrameData[colorIndex++];
g = colorFrameData[colorIndex++];
r = colorFrameData[colorIndex++];
a = colorFrameData[colorIndex++];
}
if (!(double.IsInfinity(p.X)) && !(double.IsInfinity(p.Y)) && !(double.IsInfinity(p.Z)))
{
particles[particleCount].position = new Vector3(p.X*scale, p.Y*scale, p.Z*scale);
particles[particleCount].startColor = new Color(r/255F,g/255F,b/255F,a/255F);
particles[particleCount].startSize = size;
particleCount++;
}
}
}
_particleSystem = gameObject.GetComponent<ParticleSystem>();
_particleSystem.SetParticles(particles, particles.Length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment