Monday, 7 March 2011

Kinect

Binary code, requires C++ but will attempt to implement this ASAP (tomorrow)

01 // Headers
02 #include "stdafx.h"
03 // Include OpenNI
04 #include
05 // Include NITE
06 #include "XnVNite.h"
07
08 // This macro checks the return code that all OpenNI calls make
09 // and throws an error if the return code is an error. Use this
10 // after all calls to OpenNI objects. Great for debugging.
11 #define CHECK_RC(rc, what) \
12 if (rc != XN_STATUS_OK) \
13 { \
14 printf("%s failed: %s\n", what, xnGetStatusString(rc)); \
15 return rc; \
16 }
17
18 int _tmain(int argc, _TCHAR* argv[])
19 {
20 //
21 // Variables
22
23 // Keep track of the return code of all OpenNI calls
24 XnStatus nRetVal = XN_STATUS_OK;
25 // context is the object that holds most of the things related to OpenNI
26 xn::Context context;
27 // The DepthGenerator generates a depth map that we can then use to do
28 // cool stuff with. Other interesting generators are gesture generators
29 // and hand generators.
30 xn::DepthGenerator depth;
31
32 //
33 // Initialization
34
35 // Initialize context object
36 nRetVal = context.Init();
37 CHECK_RC(nRetVal, "Initialize context");
38 // Create the depth object
39 nRetVal = depth.Create(context);
40 CHECK_RC(nRetVal, "Create Depth");
41
42 // Tell the context object to start generating data
43 nRetVal = context.StartGeneratingAll();
44 CHECK_RC(nRetVal, "Start Generating All Data");
45
46 // We wish to print the middle pixel's depth, get the index
47 // of the middle pixel.
48 XnUInt32 nMiddleIndex = XN_QQVGA_X_RES * XN_QVGA_Y_RES/ 2 +
49 XN_QVGA_X_RES/2;
50
51 // Main loop
52 while (true)
53 {
54 // Wait for new data to be available
55 nRetVal = context.WaitOneUpdateAll(depth);
56 CHECK_RC(nRetVal, "Updating depth");
57 // Get the new depth map
58 const XnDepthPixel* pDepthMap = depth.GetDepthMap();
59 // Print out the value of the middle pixel
60 printf("Middle pixel is %u millimeters away\n", pDepthMap[nMiddleIndex]);
61 }
62
63 // Clean-up
64 context.Shutdown();
65 return 0;
66 }

No comments:

Post a Comment