c# - using Kinect Depth View to show an Object inside the Human Body -
c# - using Kinect Depth View to show an Object inside the Human Body -
i working on depth info on kinect sdk v1.8 on xna , wanna show image within depth view of human body. image below illustration of wanna :
http://static.gamespot.com/uploads/original/1535/15354745/2429785-screen4.jpg
for depth view, i've done :
void kinectsensor_depthframeready(object sender, depthimageframereadyeventargs e) { using (depthimageframe depthimageframe = e.opendepthimageframe()) { if (depthimageframe != null) { short[] pixelsfromframe = new short[depthimageframe.pixeldatalength]; depthimageframe.copypixeldatato(pixelsfromframe); byte[] convertedpixels = convertdepthframe(pixelsfromframe, ((kinectsensor)sender).depthstream, 640 * 480 * 4); color[] color = new color[depthimageframe.height * depthimageframe.width]; kinectrgbvideo = new texture2d(graphics.graphicsdevice, depthimageframe.width, depthimageframe.height); // set convertedpixels depthimageframe datasource our texture2d kinectrgbvideo.setdata<byte>(convertedpixels); } } } // converts 16-bit grayscale depth frame includes player indexes 32-bit frame // displays different players in different colors private byte[] convertdepthframe(short[] depthframe, depthimagestream depthstream, int depthframe32length) { int tooneardepth = depthstream.tooneardepth; int toofardepth = depthstream.toofardepth; int unknowndepth = depthstream.unknowndepth; byte[] depthframe32 = new byte[depthframe32length]; (int i16 = 0, i32 = 0; i16 < depthframe.length && i32 < depthframe32.length; i16++, i32 += 4) { int player = depthframe[i16] & depthimageframe.playerindexbitmask; int realdepth = depthframe[i16] >> depthimageframe.playerindexbitmaskwidth; // transform 13-bit depth info 8-bit intensity appropriate // display (we disregard info in important bit) byte intensity = (byte)(~(realdepth >> 4)); if (player == 0 && realdepth == 0) { // white depthframe32[i32 + redindex] = 255; depthframe32[i32 + greenindex] = 255; depthframe32[i32 + blueindex] = 255; } else if (player == 0 && realdepth == toofardepth) { // dark violet depthframe32[i32 + redindex] = 66; depthframe32[i32 + greenindex] = 0; depthframe32[i32 + blueindex] = 66; } else if (player == 0 && realdepth == unknowndepth) { // dark brownish depthframe32[i32 + redindex] = 66; depthframe32[i32 + greenindex] = 66; depthframe32[i32 + blueindex] = 33; } else { // tint intensity dividing per-player values depthframe32[i32 + redindex] = (byte)(intensity >> intensityshiftbyplayerr[player]); depthframe32[i32 + greenindex] = (byte)(intensity >> intensityshiftbyplayerg[player]); depthframe32[i32 + blueindex] = (byte)(intensity >> intensityshiftbyplayerb[player]); } } homecoming depthframe32; }
but i'm not have thought how show object within depth view of body appropriate if help me. thanks
i wrote hlsl code transparency , transparent 1 image within body , image used foreground :
sampler stream : register(s0); sampler : register(s1); sampler character : register(s2); float4 depthtorgb(float2 texcoord : texcoord0) : color0 { // can't sample non-normalized data, // texture short packed stuffed bgra4444 (4 bit per component normalized) // it's not bgra4444 why have reverse normalization here float4 color = tex2d(stream, texcoord); float4 backcolor = tex2d(back, texcoord); float4 charactercolor = tex2d(character, texcoord); // convert [0,1] [0,15] color *= 15.01f; // unpack individual components single int int4 icolor = (int4)color; int depthv = icolor.w * 4096 + icolor.x * 256 + icolor.y * 16 + icolor.z; // player mask in lower 8 bits int playerid = depthv % 8; if(playerid == 0) { //not yet recognized homecoming backcolor * float4(1.0, 1.0, 1.0, 1.0); } else { homecoming backcolor * charactercolor; } } technique kinectdepth { pass kinectdepth { pixelshader = compile ps_2_0 depthtorgb(); } }
c# xna kinect hlsl kinect-sdk
Comments
Post a Comment