Kinect 2014 9 19 IS Report No. 2014092901 Report Medical Information System Laboratory
Abstract Kinect for Windows 2012 2 RGB Kinect for Windows v2 2014 7 Kinect for Windows v2
1............................ 2 2............................ 3 2.1............................ 3 2.2............................ 3 3............................ 5 3.1.......................... 5 3.2............................ 5 3.3 Body............................ 6 3.4........................... 7 A........................... 8 A.1.......................... 8 A.2....................... 11
1 Kinect Microsoft Xbox 360 RGB 3 Kinect Xbox 360 2012 2 Windows PC Kinect for Windows( Kinect v1) Kinect v1 Kinect 1) 2014 7 RGB kinect for Windows v2( Kinect v2) kinect v2 2
2 2.1 Kinect v2 Table. 2.1 Table. 2.1 OS Windows 8 CPU Visual Studio 2012 USB3.0 Dual-Core 2.66GHz GPU DirectX 11.0 RAM 2.0GBytes Kinect v1 Windows 7 Kinect v2 Windows 8 Visual Studio 2012 Kinect v1 USB2.0 Kinect v2 USB3.0 2.2 Kinect v2 Microsoft Kinect for Windows SDK SDK 1. SDK(Kinect for Windows SDK 2.0 Public Preview) Fig. 2.1 http://www.microsoft.com/en-us/download/details.aspx?id=43661 Fig. 2.1 SDK ( ) 2. SDK Fig. 2.2 3
2.2 2 Fig. 2.2 ( ) 3. Kinect v2 PC PC Gesture Builder Kinect Studio v2.0 SDK Browser v2.0 (Kinect for Windows) 4. SDK Browser v2.0 (Kinect for Windows) Fig. 2.3 RUN SDK Browser v2.0 (Kinect for Windows) Color Depth Body Fig. 2.3 SDK Browser v2.0 (Kinect for Windows) ( ) 4
3 3.1 Kinect v2 Visual Studio 2013 Visual C# WPF Microsoft.Kinect Fig. 3.1 Kinect v2 using Microsoft.Kinect https://github.com/kaorun55/kinect-for-windows-sdk-v2.0-samples (a) WPF Fig. 3.1 ( ) (b) 3.2 28 CameraMode.color color Depth Infrared CameraMode.Color RGB Bitmap Fig. 3.2(a) CameraMode.Depth Bitmap Kinect v2 TOF(Time Of Flight) Fig. 3.2(b) CameraMode.Infrared Bitmap Fig. 3.2(c) 5
3.3Body 3 (a) (b) (c) Fig. 3.2 ( ) 3.3 Body Body Kinect 6 joint( ) joint Fig. 3.3(a) 25 joint joint joint 3 2 2 (1 Color 2 Depth/Infrared) CoordinateMapper 1920 1080 4/10 768 432 image joint 2 pointx pointy 4/10 Fig. 3.3(b) Body 1 ColorSpacePoint colorpoint = sensor.coordinatemapper.mapcamerapointtocolorspace( jointposition); 2 DepthSpacePoint depthpoint = sensor.coordinatemapper.mapcamerapointtodepthspace( jointposition); (a) joint Fig. 3.3 joint ( ) (b) Body 6
3.4 3 3.4 TextBox joint Elbow Left Hand Left 2 MainWindow.xaml 1 MainWindow.xaml.cs body 2 p1 Elbow Left 2 p2 Hand Left 2 TextBox Fig. 3.4 1 CameraSpacePoint jointposition = joint.position; 2 3 if (i == 0) 4 { // 3D space point 5 jointposition = body.joints[jointtype.elbowleft].position; 6 } 7 if (i == 1) 8 { // 3D space point 9 jointposition = body.joints[jointtype.handleft].position; 10 } 11 12 // 2D space point 13 System.Windows.Point point = new System.Windows.Point(); 14 15 if ( mode == CameraMode.Color) 16 { 17 ColorSpacePoint colorpoint = sensor.coordinatemapper.mapcamerapointtocolorspace( jointposition); 18 19 point.x = float.isinfinity(colorpoint.x)? 0 : colorpoint.x; 20 point.y = float.isinfinity(colorpoint.y)? 0 : colorpoint.y; 21 22 if (i == 0) 23 { 24 p1 = point; 25 } 26 if (i == 1) 27 { 28 p2 = point; 29 } 30 } Fig. 3.4 ( ) 7
A A.1 MainWindow.xaml 1 <Window x:class=" v2.mainwindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 Title="MainWindow" Height="550" Width="730" 5 Loaded="Window_Loaded" Closed="Window_Closed"> 6 7 <Grid> 8 <Image Name="camera" Width="768" Height="432" /> 9 <Canvas Name="canvas" Width="768" Height="432" /> 10 <Button x:name="_screenshotbutton" Content="ScreenShot" Margin="0,480,620,0" Click="_ScreenshotButton_Click" /> 11 <Label x:name="label1" Content="" HorizontalAlignment="Left" Margin=" 107,487,0,0" VerticalAlignment="Top" Width="147"/> 12 </Grid> 13 </Window> MainWindow.xaml.cs 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 using System.Windows; 7 using System.Windows.Controls; 8 using System.Windows.Data; 9 using System.Windows.Documents; 10 using System.Windows.Input; 11 using System.Windows.Media; 12 using System.Windows.Media.Imaging; 13 using System.Windows.Navigation; 14 using System.Windows.Shapes; 15 using Microsoft.Kinect; 16 17 namespace v2 18 { 19 /// <summary> 20 /// MainWindow.xaml 21 /// </summary> 22 public partial class MainWindow : Window 23 { 24 KinectSensor sensor; 25 MultiSourceFrameReader reader; 26 IList<Body> bodies; 27 28 CameraMode mode = CameraMode.Color; 29 30 public MainWindow() 31 { 32 InitializeComponent(); 33 } 34 35 private void Window Loaded(object sender, RoutedEventArgs e) 36 { 8
A.1 A 37 sensor = KinectSensor.GetDefault(); 38 39 if ( sensor!= null) 40 { 41 sensor.open(); 42 43 reader = sensor.openmultisourceframereader(framesourcetypes.color FrameSourceTypes.Depth FrameSourceTypes.Infrared FrameSourceTypes. Body); 44 reader.multisourceframearrived += Reader MultiSourceFrameArrived; 45 } 46 } 47 48 private void Window Closed(object sender, EventArgs e) 49 { 50 if ( reader!= null) 51 { 52 reader.dispose(); 53 } 54 55 if ( bodies!= null) 56 { 57 if ( bodies.count() > 0) 58 { 59 foreach (var body in bodies) 60 { 61 // body.dispose(); 62 } 63 } 64 } 65 66 if ( sensor!= null) 67 { 68 sensor.close(); 69 } 70 } 71 72 void Reader MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e) 73 { 74 var reference = e.framereference.acquireframe(); 75 76 // Color 77 using (var frame = reference.colorframereference.acquireframe()) 78 { 79 if (frame!= null) 80 { 81 if ( mode == CameraMode.Color) 82 { 83 camera.source = frame.tobitmap(); 84 } 85 } 86 } 87 88 // Depth 89 using (var frame = reference.depthframereference.acquireframe()) 90 { 91 if (frame!= null) 92 { 93 if ( mode == CameraMode.Depth) 94 { 95 camera.source = frame.tobitmap(); 96 } 97 } 98 } 99 100 // Infrared 9
A.1 A 101 using (var frame = reference.infraredframereference.acquireframe()) 102 { 103 if (frame!= null) 104 { 105 if ( mode == CameraMode.Infrared) 106 { 107 camera.source = frame.tobitmap(); 108 } 109 } 110 } 111 112 // Body 113 using (var frame = reference.bodyframereference.acquireframe()) 114 { 115 if (frame!= null) 116 { 117 canvas.children.clear(); 118 119 bodies = new Body[frame.BodyFrameSource.BodyCount]; 120 121 frame.getandrefreshbodydata( bodies); 122 123 foreach (var body in bodies) 124 { 125 if (body.istracked) 126 { 127 // COORDINATE MAPPING 128 foreach (Joint joint in body.joints.values) 129 { 130 if (joint.trackingstate == TrackingState.Tracked) 131 { 132 // 3D space point 133 CameraSpacePoint jointposition = joint.position; 134 135 // 2D space point 136 System.Windows.Point point = new System.Windows.Point(); 137 138 if ( mode == CameraMode.Color) 139 { 140 ColorSpacePoint colorpoint = sensor.coordinatemapper. MapCameraPointToColorSpace(jointPosition); 141 142 point.x = float.isinfinity(colorpoint.x)? 0 : colorpoint.x; 143 point.y = float.isinfinity(colorpoint.y)? 0 : colorpoint.y; 144 } 145 else if ( mode == CameraMode.Depth mode == CameraMode.Infrared) // Change the Image and Canvas dimensions to 512x424 146 { 147 DepthSpacePoint depthpoint = sensor.coordinatemapper. MapCameraPointToDepthSpace(jointPosition); 148 149 point.x = float.isinfinity(depthpoint.x)? 0 : depthpoint. X; 150 point.y = float.isinfinity(depthpoint.y)? 0 : depthpoint. Y; 151 } 152 153 // Draw 154 Ellipse ellipse = new Ellipse 155 { 156 Fill = System.Windows.Media.Brushes.Red, 157 Width = 15, 158 Height = 15 159 }; 160 161 Canvas.SetLeft(ellipse, point.x 4 / 10 ellipse.width / 2); 10
A.2 A 162 Canvas.SetTop(ellipse, point.y 4 / 10 ellipse.height / 2); 163 164 canvas.children.add(ellipse); 165 } 166 } 167 } 168 169 } 170 } 171 } 172 } 173 174 /// <summary> 175 /// 176 /// </summary> 177 int count = 0; 178 private void ScreenshotButton Click(object sender, RoutedEventArgs e) 179 { 180 count++; 181 string name = "capture" + count + ".bmp"; 182 Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, 183 Screen.PrimaryScreen.Bounds.Height); 184 //Graphics 185 Graphics g = Graphics.FromImage(bmp); 186 // 187 g.copyfromscreen(new System.Drawing.Point(0, 0), new System.Drawing.Point(0, 0), bmp.size); 188 // 189 bmp.save(name); 190 g.dispose(); 191 label1.content = "save " + name; 192 } 193 } 194 195 enum CameraMode 196 { 197 Color, 198 Depth, 199 Infrared 200 } 201 } A.2 1 1 <Window x:class=" v2.mainwindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 Title="MainWindow" Height="550" Width="730" 5 Loaded="Window_Loaded" Closed="Window_Closed"> 6 7 <Grid> 8 <Image Name="camera" Width="768" Height="432" /> 9 <Canvas Name="canvas" Width="768" Height="432" /> 10 <Button x:name="_screenshotbutton" Content="ScreenShot" Margin="0,480,620,0" Click="_ScreenshotButton_Click" /> 11 <Label x:name="label1" Content="" HorizontalAlignment="Left" Margin=" 107,487,0,0" VerticalAlignment="Top" Width="147"/> 12 <TextBox x:name="text1" Content="" HorizontalAlignment="Left" Height="40" TextWrapping="Wrap" Margin="10,4,0,0" VerticalAlignment="Top" Width="117" FontSize="28" /> 13 </Grid> 14 </Window> 2 11
A.2 A 1 // COORDINATE MAPPING 2 foreach (Joint joint in body.joints.values) 3 { 4 if (joint.trackingstate == TrackingState.Tracked) 5 { 6 for (int i = 0; i < 2; i++) 7 { 8 CameraSpacePoint jointposition = joint.position; 9 10 if (i == 0) 11 { 12 // 3D space point 13 jointposition = body.joints[jointtype.elbowleft].position; 14 } 15 if (i == 1) 16 { 17 // 3D space point 18 jointposition = body.joints[jointtype.handleft].position; 19 } 20 21 // 2D space point 22 System.Windows.Point point = new System.Windows.Point(); 23 24 if ( mode == CameraMode.Color) 25 { 26 ColorSpacePoint colorpoint = sensor.coordinatemapper.mapcamerapointtocolorspace( jointposition); 27 28 point.x = float.isinfinity(colorpoint.x)? 0 : colorpoint.x; 29 point.y = float.isinfinity(colorpoint.y)? 0 : colorpoint.y; 30 31 if (i == 0) 32 { 33 p1 = point; 34 } 35 if (i == 1) 36 { 37 p2 = point; 38 } 39 } 40 else if ( mode == CameraMode.Depth mode == CameraMode.Infrared) // Change the Image and Canvas dimensions to 512x424 41 { 42 DepthSpacePoint depthpoint = sensor.coordinatemapper. MapCameraPointToDepthSpace(jointPosition); 43 44 point.x = float.isinfinity(depthpoint.x)? 0 : depthpoint.x; 45 point.y = float.isinfinity(depthpoint.y)? 0 : depthpoint.y; 46 } 47 48 // Draw 49 Ellipse ellipse = new Ellipse 50 { 51 Fill = System.Windows.Media.Brushes.Red, 52 Width = 15, 53 Height = 15 54 }; 55 56 Canvas.SetLeft(ellipse, point.x 4 / 10 ellipse.width / 2); 57 Canvas.SetTop(ellipse, point.y 4 / 10 ellipse.height / 2); 58 59 canvas.children.add(ellipse); 60 } 61 62 double v1 = Math.Sqrt(0 + 10 10); 12
A.2 A 63 double v2 = Math.Sqrt((p2.X p1.x) (p2.x p1.x) + (p2.y p1.y) (p2.y p1.y )); 64 double v3 = (10 (p2.x p1.x) + 0 (p2.y p1.y)); 65 66 double degree = (Math.Acos(v3 / v1 / v2)) 180 / Math.PI; 67 double deg = (180 degree); 68 69 if (p1.y >p2.y) 70 { 71 Text1.Text = ("+ " + deg.tostring("f1")); 72 } 73 74 else if (p1.y <p2.y) 75 { 76 Text1.Text = ("- " + deg.tostring("f1")); 77 } 78 else if (p1.y == p2.y) 79 { 80 Text1.Text = (" 0"); 81 } 82 } 83 } 13
1),,. Kinect for windows sdk c#., No. 1, 2012. 14