{"id":1352,"date":"2012-01-15T03:19:31","date_gmt":"2012-01-14T18:19:31","guid":{"rendered":"http:\/\/teruaki-tsubokura.com\/Lab\/?p=1352"},"modified":"2012-01-15T03:24:26","modified_gmt":"2012-01-14T18:24:26","slug":"kinect-sdkcxna%e4%ba%ba%e3%81%8c%e5%b1%85%e3%82%8b%e3%83%bb%e5%b1%85%e3%81%aa%e3%81%84%e3%82%92%e5%88%a4%e6%96%ad%e3%81%97%e3%81%a6%e7%94%bb%e9%9d%a2%e8%a1%a8%e7%a4%ba%e3%82%92%e5%a4%89","status":"publish","type":"post","link":"https:\/\/teruaki-tsubokura.com\/Lab\/kinect-sdkcxna%e4%ba%ba%e3%81%8c%e5%b1%85%e3%82%8b%e3%83%bb%e5%b1%85%e3%81%aa%e3%81%84%e3%82%92%e5%88%a4%e6%96%ad%e3%81%97%e3%81%a6%e7%94%bb%e9%9d%a2%e8%a1%a8%e7%a4%ba%e3%82%92%e5%a4%89\/","title":{"rendered":"[Kinect SDK][C#][XNA]\u4eba\u304c\u5c45\u308b\u30fb\u5c45\u306a\u3044\u3092\u5224\u65ad\u3057\u3066\u753b\u9762\u8868\u793a\u3092\u5909\u3048\u308b"},"content":{"rendered":"<p>Kinect\u3092\u30c7\u30b8\u30bf\u30eb\u30b5\u30a4\u30cd\u30fc\u30b8\u306b\u5229\u7528\u3059\u308b\u30cf\u30c3\u30af\u306e\u7b2c\u4e00\u5f3e\u3067\u3059\u3002<\/p>\n<p>Visual C# 2010 Express \u3068 XNA Game Studio 4.0\u3001\u305d\u3057\u3066Kinect for Windows SDK Beta2\u3092\u4f7f\u7528\u3057\u3066\u5236\u4f5c\u3057\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f\u7b2c\u4e00\u5f3e\u3068\u3044\u3046\u4e8b\u3067\u3001\u975e\u5e38\u306b\u30b7\u30f3\u30d7\u30eb\u3067\u306f\u3042\u308a\u307e\u3059\u304c\u3001<br \/>\n\u300c\u4eba\u304c\u5c45\u308b\u30fb\u5c45\u306a\u3044\u3092\u5224\u65ad\u3057\u3066\u753b\u9762\u8868\u793a\u3092\u5909\u3048\u308b\u300d\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u3063\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\nKinect\u3067\u4eba\u304c\u5c45\u308b\u304b\u5c45\u306a\u3044\u304b\u3092\u5224\u65ad\u3059\u308b\u306b\u306f\u3001\u9aa8\u683c\u30c8\u30e9\u30c3\u30ad\u30f3\u30b0\u306e\u4ed6\u306b\u6df1\u5ea6\u30ab\u30e1\u30e9\u306e\u30d7\u30ec\u30a4\u30e4\u30fc\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u5229\u7528\u3059\u308b\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u9aa8\u683c\u30c8\u30e9\u30c3\u30ad\u30f3\u30b0\u306f\u4eba\u304cKinect\u306e\u524d\u306b\u5165\u3063\u3066\u304b\u3089\u9aa8\u683c\u306e\u8a8d\u8b58\u3092\u3059\u308b\u307e\u3067\u306b\u6642\u9593\u304c\u304b\u304b\u308b\u4e0a\u306b\u540c\u6642\u306b2\u4eba\u307e\u3067\u3057\u304b\u8a8d\u8b58\u3067\u304d\u306a\u3044\u306e\u3067\u3001\u4eca\u56de\u306f\u4eba\u306e\u8a8d\u8b58\u304c\u9ad8\u901f\u3067\u540c\u6642\u306b6\u4eba\u307e\u3067\u8a8d\u8b58\u3067\u304d\u308b\u6df1\u5ea6\u30ab\u30e1\u30e9\u306e\u30d7\u30ec\u30a4\u30e4\u30fc\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u30c7\u30b8\u30bf\u30eb\u30b5\u30a4\u30cd\u30fc\u30b8\u3092\u898b\u3066\u3044\u308b\u4eba\u304c\u5c45\u306a\u3044\u6642\u306b\u306fCM\u52d5\u753b\u7b49\u3092\u30eb\u30fc\u30d7\u518d\u751f\u3055\u305b\u3066\u304a\u304d\u3001\u4eba\u304c\u8fd1\u304f\u306b\u6765\u305f\u3089\u64cd\u4f5c\u753b\u9762\u306b\u5207\u308a\u66ff\u3048\u308b\u3002\u3068\u3044\u3063\u305f\u30b7\u30c1\u30e5\u30a8\u30fc\u30b7\u30e7\u30f3\u3067\u5f79\u306b\u7acb\u3064\u306e\u3067\u306f\u306a\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n<!--more--><\/p>\n<h3>\u25a0\u51e6\u7406\u306e\u6d41\u308c<\/h3>\n<p>Kinect\u306e\u6df1\u5ea6\u30ab\u30e1\u30e9\u306e\u6620\u50cf\u3092\u53d6\u5f97<br \/>\n\u2193<br \/>\n\u305d\u306e\u6620\u50cf\u306b\u542b\u307e\u308c\u308b\u30e6\u30fc\u30b6\u30fc\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u7a2e\u985e\u3092\u5408\u8a08\u3057\u3066\u30e6\u30fc\u30b6\u6570\u3092\u6c42\u3081\u308b<br \/>\n\u2193<br \/>\n2\u679a\u306e\u753b\u50cf\u3092\u7528\u610f\u3057\u3001\u8ab0\u3082\u4eba\u304c\u3044\u306a\u3044\u6642\u306b\u306f1\u679a\u76ee\u306e\u753b\u50cf\u3092\u8868\u793a\u3057\u3001\u4e00\u4eba\u4ee5\u4e0a\u4eba\u304c\u3044\u308b\u5834\u5408\u306f2\u679a\u76ee\u306e\u753b\u50cf\u3092\u8868\u793a\u3055\u305b\u308b<\/p>\n<p>&nbsp;<\/p>\n<h3>\u25a0\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u4f5c\u6210<\/h3>\n<p>\u521d\u3081\u306bVisual C# 2011 Express\u3067\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br \/>\n[\u30d5\u30a1\u30a4\u30eb\uff08F\uff09]\u2192[\u65b0\u3057\u3044\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\uff08P\uff09&#8230;]\u3092\u9078\u629e\u3057\u3066\u3001XNA Game Studio 4.0\u306e\u300cWindows Game (4.0)\u300d\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u4f7f\u7528\u3057\u3066\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u3053\u3053\u3067\u306f\u9069\u5f53\u306b\u300cKinect_UserCount\u300d\u3068\u3044\u3046\u540d\u524d\u3092\u4ed8\u3051\u307e\u3057\u305f\u3002<\/p>\n<p><a href=\"http:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture013.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1252\" title=\"capture013\" src=\"http:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture013-300x207.png\" alt=\"\" width=\"300\" height=\"207\" srcset=\"https:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture013-300x207.png 300w, https:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture013.png 955w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3>\u25a0Kinect SDK\u3078\u306e\u53c2\u7167\u306e\u8ffd\u52a0<\/h3>\n<p>Kinect\u306e\u6a5f\u80fd\u3092\u4f7f\u3046\u305f\u3081\u306b\u53c2\u7167\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<br \/>\n\u30bd\u30ea\u30e5\u30fc\u30b7\u30e7\u30f3 \u30a8\u30af\u30b9\u30d7\u30ed\u30fc\u30e9\u30fc\u306e\u53c2\u7167\u8a2d\u5b9a\u3067\u53f3\u30af\u30ea\u30c3\u30af\u3057\u3001[\u53c2\u7167\u306e\u8ffd\u52a0(F)&#8230;]\u3092\u30af\u30ea\u30c3\u30af\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1258\" title=\"capture023\" src=\"http:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture023-e1323526250552.png\" alt=\"\" width=\"320\" height=\"189\" srcset=\"https:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture023-e1323526250552.png 320w, https:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture023-e1323526250552-300x177.png 300w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><\/p>\n<p>Kinect SDK\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u6b63\u3057\u304f\u884c\u308f\u308c\u3066\u3044\u308c\u3070\u3001.NET\u30bf\u30d6\u306b[Microsoft.Research.Kinect]\u304c\u5b58\u5728\u3059\u308b\u306e\u3067\u9078\u629e\u3057\u3066\u3057\u3066[OK]<\/p>\n<p><a href=\"http:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture016.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1257\" title=\"capture016\" src=\"http:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture016-300x189.png\" alt=\"\" width=\"300\" height=\"189\" srcset=\"https:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture016-300x189.png 300w, https:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture016.png 654w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u3053\u308c\u3067Visual C#\u3067Kinect\u306e\u6a5f\u80fd\u3092\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<h3>\u25a0\u753b\u50cf\u30b3\u30f3\u30c6\u30f3\u30c4\u306e\u8ffd\u52a0<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1251\" title=\"capture012\" src=\"http:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture012-e1323523597101.png\" alt=\"\" width=\"608\" height=\"345\" srcset=\"https:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture012-e1323523597101.png 608w, https:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture012-e1323523597101-300x170.png 300w\" sizes=\"auto, (max-width: 608px) 100vw, 608px\" \/><\/p>\n<p>\u4eba\u304c\u5c45\u306a\u3044\u6642\u306b\u8868\u793a\u3059\u308b\u753b\u50cf\u3068\u3001\u4eba\u304c\u5c45\u308b\u6642\u306b\u8868\u793a\u3059\u308b\u753b\u50cf\u306e2\u679a\u3092\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002<br \/>\n[ZERO.png]\u3068[ONE.png]\u3068\u3044\u30462\u679a\u306e\u753b\u50cf\u3092\u7528\u610f\u3057\u305f\u306e\u3067\u305d\u308c\u3089\u3092\u30bd\u30ea\u30e5\u30fc\u30b7\u30e7\u30f3\u30a8\u30af\u30b9\u30d7\u30ed\u30fc\u30e9\u30fc\u306e\u300cKinect_UserCount(Content)\u300d\u3068\u306a\u3063\u3066\u3044\u308b\u90e8\u5206\u306b\u30c9\u30e9\u30c3\u30b0\u30a2\u30f3\u30c9\u30c9\u30ed\u30c3\u30d7\u3057\u307e\u3059\u3002<br \/>\n\u30bd\u30ea\u30e5\u30fc\u30b7\u30e7\u30f3\u30a8\u30af\u30b9\u30d7\u30ed\u30fc\u30e9\u30fc\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u306a\u3044\u5834\u5408\u306f[\u8868\u793a(V)]\u2192[\u305d\u306e\u4ed6\u306e\u30a6\u30a3\u30f3\u30c9\u30a6(E)]\u2192[\u30bd\u30ea\u30e5\u30fc\u30b7\u30e7\u30f3 \u30a8\u30af\u30b9\u30d7\u30ed\u30fc\u30e9\u30fc(P)]\u304b\u3089\u8868\u793a\u3067\u304d\u307e\u3059\u3002<br \/>\n\u753b\u50cf\u3092\u767b\u9332\u3059\u308b\u3068\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306eContent\u30d5\u30a9\u30eb\u30c0\u306e\u4e2d\u306b\u3082\u8907\u88fd\u3055\u308c\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30d5\u30a1\u30a4\u30eb\u540d\u3067\u753b\u50cf\u3092\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n<!-- code formatted by http:\/\/manoli.net\/csharpformat\/ --><\/p>\n<div class=\"csharpcode\">\n<pre class=\"alt\"><span class=\"kwrd\">this<\/span>.Content.Load&lt;Texture2D&gt;(<span class=\"str\">\"ZERO\"<\/span>);<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<h3>\u25a0\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<br \/>\n<!-- code formatted by http:\/\/manoli.net\/csharpformat\/ --><\/h3>\n<div class=\"csharpcode\">\n<pre class=\"alt\"><span class=\"kwrd\">using<\/span> System;<\/pre>\n<pre><span class=\"kwrd\">using<\/span> System.Collections.Generic;<\/pre>\n<pre class=\"alt\"><span class=\"kwrd\">using<\/span> System.Linq;<\/pre>\n<pre><span class=\"kwrd\">using<\/span> Microsoft.Xna.Framework;<\/pre>\n<pre class=\"alt\"><span class=\"kwrd\">using<\/span> Microsoft.Xna.Framework.Audio;<\/pre>\n<pre><span class=\"kwrd\">using<\/span> Microsoft.Xna.Framework.Content;<\/pre>\n<pre class=\"alt\"><span class=\"kwrd\">using<\/span> Microsoft.Xna.Framework.GamerServices;<\/pre>\n<pre><span class=\"kwrd\">using<\/span> Microsoft.Xna.Framework.Graphics;<\/pre>\n<pre class=\"alt\"><span class=\"kwrd\">using<\/span> Microsoft.Xna.Framework.Input;<\/pre>\n<pre><span class=\"kwrd\">using<\/span> Microsoft.Xna.Framework.Media;<\/pre>\n<pre class=\"alt\"><span class=\"kwrd\">using<\/span> Microsoft.Research.Kinect.Nui;    <span class=\"rem\">\/\/Kinect Nui\u306e\u8aad\u307f\u8fbc\u307f<\/span><\/pre>\n<pre><\/pre>\n<pre class=\"alt\"><span class=\"kwrd\">namespace<\/span> Kinect_UserCount<\/pre>\n<pre>{<\/pre>\n<pre class=\"alt\">    <span class=\"rem\">\/\/\/ &lt;summary&gt;<\/span><\/pre>\n<pre>    <span class=\"rem\">\/\/\/ \u57fa\u5e95 Game \u30af\u30e9\u30b9\u304b\u3089\u6d3e\u751f\u3057\u305f\u3001\u30b2\u30fc\u30e0\u306e\u30e1\u30a4\u30f3 \u30af\u30e9\u30b9\u3067\u3059\u3002<\/span><\/pre>\n<pre class=\"alt\">    <span class=\"rem\">\/\/\/ &lt;\/summary&gt;<\/span><\/pre>\n<pre>    <span class=\"kwrd\">public<\/span> <span class=\"kwrd\">class<\/span> Game1 : Microsoft.Xna.Framework.Game<\/pre>\n<pre class=\"alt\">    {<\/pre>\n<pre>        GraphicsDeviceManager graphics;<\/pre>\n<pre class=\"alt\">        Runtime Kinect;    <span class=\"rem\">\/\/Kinect\u306e\u30bb\u30f3\u30b5\u30af\u30e9\u30b9<\/span><\/pre>\n<pre><\/pre>\n<pre class=\"alt\">        SpriteBatch spriteBatch;<\/pre>\n<pre>        Texture2D texture_depth = <span class=\"kwrd\">null<\/span>;    <span class=\"rem\">\/\/\u5965\u884c\u30c6\u30af\u30b9\u30c1\u30e3<\/span><\/pre>\n<pre class=\"alt\">        Texture2D texture_ZERO = <span class=\"kwrd\">null<\/span>;    <span class=\"rem\">\/\/\u4eba\u304c\u5c45\u306a\u3044\u6642\u306e\u753b\u50cf<\/span><\/pre>\n<pre>        Texture2D texture_ONE = <span class=\"kwrd\">null<\/span>;    <span class=\"rem\">\/\/\u4eba\u304c\u5c45\u308b\u6642\u306e\u753b\u50cf<\/span><\/pre>\n<pre class=\"alt\">        <span class=\"kwrd\">private<\/span> Color[] depthColor;    <span class=\"rem\">\/\/\u8272\u60c5\u5831\u306e\u683c\u7d0d<\/span><\/pre>\n<pre>        <span class=\"kwrd\">private<\/span> <span class=\"kwrd\">bool<\/span>[] user_index = <span class=\"kwrd\">new<\/span> <span class=\"kwrd\">bool<\/span>[7];    <span class=\"rem\">\/\/\u30e6\u30fc\u30b6\u30a4\u30f3\u30c7\u30c3\u30af\u30b9<\/span><\/pre>\n<pre class=\"alt\">        <span class=\"kwrd\">private<\/span> <span class=\"kwrd\">int<\/span> user_count = 0;    <span class=\"rem\">\/\/\u30e6\u30fc\u30b6\u306e\u6570<\/span><\/pre>\n<pre><\/pre>\n<pre class=\"alt\">        <span class=\"kwrd\">public<\/span> Game1()<\/pre>\n<pre>        {<\/pre>\n<pre class=\"alt\">            graphics = <span class=\"kwrd\">new<\/span> GraphicsDeviceManager(<span class=\"kwrd\">this<\/span>);<\/pre>\n<pre>            Content.RootDirectory = <span class=\"str\">\"Content\"<\/span>;<\/pre>\n<pre class=\"alt\">            <span class=\"rem\">\/\/\u753b\u9762\u30b5\u30a4\u30ba\u3092640 X 480<\/span><\/pre>\n<pre>            <span class=\"kwrd\">this<\/span>.graphics.PreferredBackBufferWidth = 640;<\/pre>\n<pre class=\"alt\">            <span class=\"kwrd\">this<\/span>.graphics.PreferredBackBufferHeight = 480;<\/pre>\n<pre>        }<\/pre>\n<pre class=\"alt\"><\/pre>\n<pre>        <span class=\"preproc\">#region<\/span> Initialize<\/pre>\n<pre class=\"alt\">        <span class=\"kwrd\">protected<\/span> <span class=\"kwrd\">override<\/span> <span class=\"kwrd\">void<\/span> Initialize()<\/pre>\n<pre>        {<\/pre>\n<pre class=\"alt\">            <span class=\"kwrd\">base<\/span>.Initialize();<\/pre>\n<pre>            Kinect = Runtime.Kinects[0];    <span class=\"rem\">\/\/Kinect\u30bb\u30f3\u30b5\u30af\u30e9\u30b9\u306e\u521d\u671f\u5316<\/span><\/pre>\n<pre class=\"alt\">            <span class=\"rem\">\/\/ \u30c6\u30af\u30b9\u30c1\u30e3\u30fc\u3092\u30b3\u30f3\u30c6\u30f3\u30c4\u30d1\u30a4\u30d7\u30e9\u30a4\u30f3\u304b\u3089\u8aad\u307f\u8fbc\u3080<\/span><\/pre>\n<pre>            <span class=\"kwrd\">this<\/span>.texture_ZERO = <span class=\"kwrd\">this<\/span>.Content.Load&lt;Texture2D&gt;(<span class=\"str\">\"ZERO\"<\/span>);<\/pre>\n<pre class=\"alt\">            <span class=\"kwrd\">this<\/span>.texture_ONE = <span class=\"kwrd\">this<\/span>.Content.Load&lt;Texture2D&gt;(<span class=\"str\">\"ONE\"<\/span>);<\/pre>\n<pre><\/pre>\n<pre class=\"alt\">            <span class=\"kwrd\">try<\/span><\/pre>\n<pre>            {<\/pre>\n<pre class=\"alt\">                <span class=\"rem\">\/\/\u5965\u884c\u306e\u53d6\u5f97\u3001\u30c8\u30e9\u30c3\u30ad\u30f3\u30b0\u3001\u5b9f\u753b\u50cf<\/span><\/pre>\n<pre>                Kinect.Initialize(RuntimeOptions.UseDepthAndPlayerIndex |<\/pre>\n<pre class=\"alt\">                                RuntimeOptions.UseSkeletalTracking |<\/pre>\n<pre>                                RuntimeOptions.UseColor);<\/pre>\n<pre class=\"alt\">            }<\/pre>\n<pre>            <span class=\"kwrd\">catch<\/span> (InvalidOperationException)<\/pre>\n<pre class=\"alt\">            {<\/pre>\n<pre>                Console.WriteLine(<span class=\"str\">\"Runtime initialization failed.\"<\/span>);<\/pre>\n<pre class=\"alt\">                <span class=\"kwrd\">return<\/span>;<\/pre>\n<pre>            }<\/pre>\n<pre class=\"alt\"><\/pre>\n<pre>            <span class=\"kwrd\">try<\/span><\/pre>\n<pre class=\"alt\">            {<\/pre>\n<pre>                <span class=\"rem\">\/\/\u30c7\u30d7\u30b9\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u958b\u304f<\/span><\/pre>\n<pre class=\"alt\">                Kinect.DepthStream.Open(ImageStreamType.Depth,<\/pre>\n<pre>                                        2,<\/pre>\n<pre class=\"alt\">                                        ImageResolution.Resolution320x240,<\/pre>\n<pre>                                        ImageType.DepthAndPlayerIndex);<\/pre>\n<pre class=\"alt\">            }<\/pre>\n<pre>            <span class=\"kwrd\">catch<\/span> (InvalidOperationException)<\/pre>\n<pre class=\"alt\">            {<\/pre>\n<pre>                Console.WriteLine(<span class=\"str\">\"Failed to open stream. \"<\/span>);<\/pre>\n<pre class=\"alt\">                <span class=\"kwrd\">return<\/span>;<\/pre>\n<pre>            }<\/pre>\n<pre class=\"alt\"><\/pre>\n<pre>            <span class=\"rem\">\/\/\u30d3\u30c7\u30aa\u66f4\u65b0\u6bce\u306bKinect_DepthFrameReady\u3092\u547c\u3073\u51fa\u3059<\/span><\/pre>\n<pre class=\"alt\">            Kinect.DepthFrameReady += <span class=\"kwrd\">new<\/span> EventHandler&lt;ImageFrameReadyEventArgs&gt;(Kinect_DepthFrameReady);<\/pre>\n<pre>        }<\/pre>\n<pre class=\"alt\">        <span class=\"preproc\">#endregion<\/span><\/pre>\n<pre><\/pre>\n<pre class=\"alt\">        <span class=\"preproc\">#region<\/span> LoadContent<\/pre>\n<pre>        <span class=\"kwrd\">protected<\/span> <span class=\"kwrd\">override<\/span> <span class=\"kwrd\">void<\/span> LoadContent()<\/pre>\n<pre class=\"alt\">        {<\/pre>\n<pre>            spriteBatch = <span class=\"kwrd\">new<\/span> SpriteBatch(GraphicsDevice);<\/pre>\n<pre class=\"alt\">        }<\/pre>\n<pre>        <span class=\"preproc\">#endregion<\/span><\/pre>\n<pre class=\"alt\"><\/pre>\n<pre>        <span class=\"preproc\">#region<\/span> UnloadContent<\/pre>\n<pre class=\"alt\">        <span class=\"kwrd\">protected<\/span> <span class=\"kwrd\">override<\/span> <span class=\"kwrd\">void<\/span> UnloadContent()<\/pre>\n<pre>        {<\/pre>\n<pre class=\"alt\">        }<\/pre>\n<pre>        <span class=\"preproc\">#endregion<\/span><\/pre>\n<pre class=\"alt\"><\/pre>\n<pre>        <span class=\"preproc\">#region<\/span> Update<\/pre>\n<pre class=\"alt\">        <span class=\"kwrd\">protected<\/span> <span class=\"kwrd\">override<\/span> <span class=\"kwrd\">void<\/span> Update(GameTime gameTime)<\/pre>\n<pre>        {<\/pre>\n<pre class=\"alt\">            KeyboardState keyState = Keyboard.GetState();<\/pre>\n<pre>            <span class=\"kwrd\">if<\/span> (keyState.IsKeyDown(Keys.Escape)) <span class=\"kwrd\">this<\/span>.Exit();<\/pre>\n<pre class=\"alt\">            <span class=\"kwrd\">base<\/span>.Update(gameTime);<\/pre>\n<pre>        }<\/pre>\n<pre class=\"alt\">        <span class=\"preproc\">#endregion<\/span><\/pre>\n<pre><\/pre>\n<pre class=\"alt\">        <span class=\"preproc\">#region<\/span> Draw<\/pre>\n<pre>        <span class=\"kwrd\">protected<\/span> <span class=\"kwrd\">override<\/span> <span class=\"kwrd\">void<\/span> Draw(GameTime gameTime)<\/pre>\n<pre class=\"alt\">        {<\/pre>\n<pre>            GraphicsDevice.Clear(Color.CornflowerBlue);<\/pre>\n<pre class=\"alt\"><\/pre>\n<pre>            <span class=\"kwrd\">this<\/span>.spriteBatch.Begin();<\/pre>\n<pre class=\"alt\">            <span class=\"rem\">\/\/\u4eba\u304c\u5c45\u308b\u6642\u306fONE.png\u3092\u8868\u793a\u3059\u308b<\/span><\/pre>\n<pre>            <span class=\"kwrd\">if<\/span> (user_count &gt; 0)<\/pre>\n<pre class=\"alt\">            {<\/pre>\n<pre>                <span class=\"kwrd\">this<\/span>.spriteBatch.Draw(texture_ONE, <span class=\"kwrd\">new<\/span> Vector2(0, 0), <span class=\"kwrd\">null<\/span>,<\/pre>\n<pre class=\"alt\">                    Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.0f);<\/pre>\n<pre>            }<\/pre>\n<pre class=\"alt\">            <span class=\"kwrd\">else<\/span> <span class=\"rem\">\/\/\u4eba\u304c\u5c45\u306a\u3044\u6642\u306fZERO.jpg\u3092\u8868\u793a\u3059\u308b<\/span><\/pre>\n<pre>            {<\/pre>\n<pre class=\"alt\">                <span class=\"kwrd\">this<\/span>.spriteBatch.Draw(texture_ZERO, <span class=\"kwrd\">new<\/span> Vector2(0, 0), <span class=\"kwrd\">null<\/span>,<\/pre>\n<pre>                    Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.0f);<\/pre>\n<pre class=\"alt\">            }<\/pre>\n<pre><\/pre>\n<pre class=\"alt\">            <span class=\"rem\">\/\/\u5965\u884c\u753b\u50cfTexture\u306e\u63cf\u5199<\/span><\/pre>\n<pre>            <span class=\"kwrd\">if<\/span> (<span class=\"kwrd\">this<\/span>.texture_depth != <span class=\"kwrd\">null<\/span>)<\/pre>\n<pre class=\"alt\">            {<\/pre>\n<pre>                <span class=\"kwrd\">this<\/span>.spriteBatch.Draw(<span class=\"kwrd\">this<\/span>.texture_depth, <span class=\"kwrd\">new<\/span> Vector2(0, 360), <span class=\"kwrd\">null<\/span>,<\/pre>\n<pre class=\"alt\">                  Color.White, 0.0f, Vector2.Zero, 0.5f, SpriteEffects.None, 0.0f);<\/pre>\n<pre>            }<\/pre>\n<pre class=\"alt\">            <span class=\"kwrd\">this<\/span>.spriteBatch.End();<\/pre>\n<pre>            <span class=\"kwrd\">base<\/span>.Draw(gameTime);<\/pre>\n<pre class=\"alt\">        }<\/pre>\n<pre>        <span class=\"preproc\">#endregion<\/span><\/pre>\n<pre class=\"alt\"><\/pre>\n<pre>        <span class=\"preproc\">#region<\/span>\u3000\u5965\u884c\u304d\u753b\u50cf<\/pre>\n<pre class=\"alt\">        <span class=\"kwrd\">void<\/span> Kinect_DepthFrameReady(<span class=\"kwrd\">object<\/span> sender, ImageFrameReadyEventArgs e)<\/pre>\n<pre>        {<\/pre>\n<pre class=\"alt\">            <span class=\"kwrd\">lock<\/span> (<span class=\"kwrd\">this<\/span>)<\/pre>\n<pre>            {<\/pre>\n<pre class=\"alt\">                PlanarImage Image = e.ImageFrame.Image;<\/pre>\n<pre>                <span class=\"kwrd\">int<\/span> no = 0;<\/pre>\n<pre class=\"alt\"><\/pre>\n<pre>                <span class=\"rem\">\/\/\u5965\u884c\u304d\u753b\u50cf\u521d\u671f\u5316<\/span><\/pre>\n<pre class=\"alt\">                <span class=\"kwrd\">this<\/span>.depthColor = <span class=\"kwrd\">new<\/span> Color[Image.Height * 2 * Image.Width * 2];<\/pre>\n<pre>                <span class=\"kwrd\">this<\/span>.texture_depth = <span class=\"kwrd\">new<\/span> Texture2D(graphics.GraphicsDevice, Image.Width * 2, Image.Height * 2);<\/pre>\n<pre class=\"alt\"><\/pre>\n<pre>                <span class=\"rem\">\/\/-- \u30e6\u30fc\u30b6\u6570\u30ab\u30a6\u30f3\u30c8\u30b5\u30f3\u30d7\u30eb --\/\/<\/span><\/pre>\n<pre class=\"alt\">                <span class=\"kwrd\">for<\/span> (<span class=\"kwrd\">int<\/span> i = 0; i &lt; 7; i++) { user_index[i] = <span class=\"kwrd\">false<\/span>; } <span class=\"rem\">\/\/user_index\u5024\u30ea\u30bb\u30c3\u30c8<\/span><\/pre>\n<pre>                user_count = 0;<span class=\"rem\">\/\/\u30e6\u30fc\u30b6\u6570\u30ab\u30a6\u30f3\u30c8<\/span><\/pre>\n<pre class=\"alt\">                <span class=\"kwrd\">for<\/span> (<span class=\"kwrd\">int<\/span> y = 0; y &lt; Image.Height; ++y){ <span class=\"rem\">\/\/y\u8ef8<\/span><\/pre>\n<pre>                    <span class=\"kwrd\">for<\/span> (<span class=\"kwrd\">int<\/span> x = 0; x &lt; Image.Width; ++x, no += 2){ <span class=\"rem\">\/\/x\u8ef8<\/span><\/pre>\n<pre class=\"alt\">                        <span class=\"kwrd\">int<\/span> n = (y * Image.Width + x) * 2;<\/pre>\n<pre>                        <span class=\"kwrd\">int<\/span> realDepth = (Image.Bits[n + 1] &lt;&lt; 5) | (Image.Bits[n] &gt;&gt; 3);<\/pre>\n<pre class=\"alt\">                        <span class=\"kwrd\">byte<\/span> intensity = (<span class=\"kwrd\">byte<\/span>)((255 - (255 * realDepth \/ 0x0fff)) \/ 2);<\/pre>\n<pre>                        <span class=\"kwrd\">this<\/span>.depthColor[y * 640 + x] = <span class=\"kwrd\">new<\/span> Color(intensity, intensity, intensity);<\/pre>\n<pre class=\"alt\"><\/pre>\n<pre>                        <span class=\"kwrd\">int<\/span> player = Image.Bits[(y * 320 + x) * 2] &amp; 0x07;<span class=\"rem\">\/\/\u30d7\u30ec\u30a4\u30e4\u30fc\u30a4\u30f3\u30c7\u30c3\u30af\u30b9<\/span><\/pre>\n<pre class=\"alt\">                        <span class=\"kwrd\">for<\/span> (<span class=\"kwrd\">int<\/span> j = 1; j &lt; 7; j++)<\/pre>\n<pre>                        {<\/pre>\n<pre class=\"alt\">                            <span class=\"kwrd\">if<\/span> (player == j) {<\/pre>\n<pre>                                <span class=\"kwrd\">if<\/span> ( !user_index[j-1] ){<\/pre>\n<pre class=\"alt\">                                    user_index[j-1] = <span class=\"kwrd\">true<\/span>;<\/pre>\n<pre>                                    user_count++; <span class=\"rem\">\/\/\u30e6\u30fc\u30b6\u6570\u306b\u52a0\u7b97<\/span><\/pre>\n<pre class=\"alt\">                                }<\/pre>\n<pre>                            }<\/pre>\n<pre class=\"alt\">                        }<\/pre>\n<pre>                    }<\/pre>\n<pre class=\"alt\">                }<\/pre>\n<pre>                <span class=\"kwrd\">this<\/span>.texture_depth.SetData(<span class=\"kwrd\">this<\/span>.depthColor);    <span class=\"rem\">\/\/texture_depth\u306b\u30c7\u30fc\u30bf\u3092\u66f8\u304d\u8fbc\u3080<\/span><\/pre>\n<pre>            }<\/pre>\n<pre class=\"alt\">        }<\/pre>\n<pre>        <span class=\"preproc\">#endregion<\/span><\/pre>\n<pre class=\"alt\">    }<\/pre>\n<pre>}<\/pre>\n<\/div>\n<h3><\/h3>\n<h3>\u25a0\u5b9f\u884c\u7d50\u679c<\/h3>\n<p>\u30fbKinect\u306e\u524d\u306b\u4eba\u304c\u5c45\u306a\u3044\u6642\u306e\u753b\u9762\u8868\u793a<\/p>\n<p><a href=\"http:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture005.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1249\" title=\"capture005\" src=\"http:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture005-300x235.png\" alt=\"\" width=\"300\" height=\"235\" srcset=\"https:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture005-300x235.png 300w, https:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture005.png 646w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u30fbKinect\u306e\u524d\u306b\u4eba\u304c\u5c45\u308b\u6642\u306e\u753b\u9762\u8868\u793a<a href=\"http:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture007.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1250\" title=\"capture007\" src=\"http:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture007-300x235.png\" alt=\"\" width=\"300\" height=\"235\" srcset=\"https:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture007-300x235.png 300w, https:\/\/teruaki-tsubokura.com\/Lab\/wp-content\/uploads\/2011\/12\/capture007.png 646w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u3061\u3083\u3093\u3068\u753b\u50cf\u304c\u5207\u308a\u66ff\u308f\u3063\u3066\u3044\u307e\u3059\u306d\u3002<br \/>\n\u307e\u305f\u4eba\u304c\u5c45\u306a\u304f\u306a\u308b\u3068ZERO.png\u306b\u5207\u308a\u66ff\u308f\u308a\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<h3>\u25a0\u89e3\u8aac<\/h3>\n<p>\u4eca\u56de\u306f\u753b\u9762\u3092\u5207\u308a\u66ff\u3048\u308b\u70ba\u306e\u6700\u4f4e\u9650\u306e\u6a5f\u80fd\u4ee5\u5916\u306f\u7701\u3044\u305f\u306e\u3067\u3001\u5b9f\u753b\u50cf\u306e\u53d6\u5f97\u306f\u305b\u305a\u306b\u6df1\u5ea6\u30ab\u30e1\u30e9\u6620\u50cf\u306e\u307f\u53d6\u5f97\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u6df1\u5ea6\u30ab\u30e1\u30e9\u306e\u6620\u50cf\u306b\u306f\u3001\u753b\u50cf\u306e\u3059\u3079\u3066\u306e\u30d4\u30af\u30bb\u30eb\u306b\u6df1\u5ea6\u60c5\u5831\uff08\u8ddd\u96e2\uff09\u306b\u52a0\u3048\u3066\u3001\u30d7\u30ec\u30a4\u30e4\u30fc\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u60c5\u5831\u304c\u4fdd\u5b58\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u30d7\u30ec\u30a4\u30e4\u30fc\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306f 0~6 \u306e\u6570\u5024\u3067\u5272\u308a\u632f\u3089\u308c\u3066\u3044\u3066\u3001\u305d\u306e\u30d4\u30af\u30bb\u30eb\u306b\u4eba\u304c\u5c45\u306a\u3051\u308c\u3070\u300c0\u300d\u3001\u4eba\u304c\u5c45\u308c\u3070\u300c1~6\u300d\u306e\u5024\u304c\u5272\u308a\u5f53\u3066\u3089\u308c\u307e\u3059\u3002<br \/>\n\u305d\u3053\u3067player_index[0~5]\u306b\u753b\u9762\u5185\u306b\u30d7\u30ec\u30a4\u30e4\u30fc\u304c\u5c45\u308c\u3070true\u3001\u5c45\u306a\u3051\u308c\u3070false\u3092\u4fdd\u5b58\u3057\u3066\u3044\u304d\u3001\u4eba\u304c\u898b\u3064\u304b\u3063\u305f\u6570\u3092\u30ab\u30a6\u30f3\u30c8\u3057\u3066index_count\u306b\u4fdd\u5b58\u3057\u307e\u3059\u3002<br \/>\n<!-- code formatted by http:\/\/manoli.net\/csharpformat\/ --><\/p>\n<div class=\"csharpcode\">\n<pre class=\"alt\">                       <span class=\"kwrd\">for<\/span> (<span class=\"kwrd\">int<\/span> j = 1; j &lt; 7; j++)<\/pre>\n<pre>                        {<\/pre>\n<pre class=\"alt\">                            <span class=\"kwrd\">if<\/span> (player == j) {<\/pre>\n<pre>                                <span class=\"kwrd\">if<\/span> ( !user_index[j-1] ){<\/pre>\n<pre class=\"alt\">                                    user_index[j-1] = <span class=\"kwrd\">true<\/span>;<\/pre>\n<pre>                                    user_count++; <span class=\"rem\">\/\/\u30e6\u30fc\u30b6\u6570\u306b\u52a0\u7b97<\/span><\/pre>\n<pre class=\"alt\">                                }<\/pre>\n<pre>                            }<\/pre>\n<pre class=\"alt\">                        }<\/pre>\n<\/div>\n<p>\u305d\u3057\u3066draw()\u306e\u4e2d\u3067\u3001\u30ab\u30a6\u30f3\u30c8\u304c0\u306e\u6642\u306b\u306fZERO.png\u3092\u8868\u793a\u3057\u3001\u30ab\u30a6\u30f3\u30c8\u304c1\u4ee5\u4e0a\u306e\u6642\u306fONE.png\u3092\u8868\u793a\u3059\u308b\u3088\u3046\u306b\u5207\u308a\u66ff\u3048\u3066\u3044\u307e\u3059\u3002<br \/>\n<!-- code formatted by http:\/\/manoli.net\/csharpformat\/ --><\/p>\n<div class=\"csharpcode\">\n<pre class=\"alt\">            <span class=\"rem\">\/\/\u4eba\u304c\u5c45\u308b\u6642\u306fONE.png\u3092\u8868\u793a\u3059\u308b<\/span><\/pre>\n<pre>            <span class=\"kwrd\">if<\/span> (user_count &gt; 0)<\/pre>\n<pre class=\"alt\">            {<\/pre>\n<pre>                <span class=\"kwrd\">this<\/span>.spriteBatch.Draw(texture_ONE, <span class=\"kwrd\">new<\/span> Vector2(0, 0), <span class=\"kwrd\">null<\/span>,<\/pre>\n<pre class=\"alt\">                    Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.0f);<\/pre>\n<pre>            }<\/pre>\n<pre class=\"alt\">            <span class=\"kwrd\">else<\/span> <span class=\"rem\">\/\/\u4eba\u304c\u5c45\u306a\u3044\u6642\u306fZERO.jpg\u3092\u8868\u793a\u3059\u308b<\/span><\/pre>\n<pre>            {<\/pre>\n<pre class=\"alt\">                <span class=\"kwrd\">this<\/span>.spriteBatch.Draw(texture_ZERO, <span class=\"kwrd\">new<\/span> Vector2(0, 0), <span class=\"kwrd\">null<\/span>,<\/pre>\n<pre>                    Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.0f);<\/pre>\n<pre class=\"alt\">            }<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Kinect\u3092\u30c7\u30b8\u30bf\u30eb\u30b5\u30a4\u30cd\u30fc\u30b8\u306b\u5229\u7528\u3059\u308b\u30cf\u30c3\u30af\u306e\u7b2c\u4e00\u5f3e\u3067\u3059\u3002 Visual C# 2010 Express \u3068 XNA Game Studio 4.0\u3001\u305d\u3057\u3066Kinect for Windows SDK Beta2\u3092\u4f7f [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":1269,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[472],"tags":[540,495,475],"class_list":["post-1352","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-memo","tag-kinect","tag-kinect-for-windows-sdk","tag-xna"],"_links":{"self":[{"href":"https:\/\/teruaki-tsubokura.com\/Lab\/wp-json\/wp\/v2\/posts\/1352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/teruaki-tsubokura.com\/Lab\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/teruaki-tsubokura.com\/Lab\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/teruaki-tsubokura.com\/Lab\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/teruaki-tsubokura.com\/Lab\/wp-json\/wp\/v2\/comments?post=1352"}],"version-history":[{"count":7,"href":"https:\/\/teruaki-tsubokura.com\/Lab\/wp-json\/wp\/v2\/posts\/1352\/revisions"}],"predecessor-version":[{"id":1363,"href":"https:\/\/teruaki-tsubokura.com\/Lab\/wp-json\/wp\/v2\/posts\/1352\/revisions\/1363"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/teruaki-tsubokura.com\/Lab\/wp-json\/wp\/v2\/media\/1269"}],"wp:attachment":[{"href":"https:\/\/teruaki-tsubokura.com\/Lab\/wp-json\/wp\/v2\/media?parent=1352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/teruaki-tsubokura.com\/Lab\/wp-json\/wp\/v2\/categories?post=1352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/teruaki-tsubokura.com\/Lab\/wp-json\/wp\/v2\/tags?post=1352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}