Open a new project or existing project to use Openni
In the Visual Studio menu, open the Project menu and select Project Properties.
In the C + + TAB, under General, select Attach include directory, add $ (openni2_include) (32-bit operating system), or Add ("$ (openni2_include64)" (64-bit operating system). The environment variable points to the Include folder under local Openni. (Default is C:\Program files\openni2\include or C:\ProgramFilesx86) \openni2\include)
on the Connector tab, under General, select additional Library directory, add $ (openni2_lib) (32-bit operating system), or add "$ (openni2_lib64)" 64-bit operating system).
the environment variable points to the Lib folder under local Openni. (Default is C:\ProgramFiles\OpenNI2\Lib or C:\ProgramFiles (x86) \openni2\lib) on the Connector tab, under Input, select additional dependencies to add OpenNI2.lib
Make sure that the Include and Library directories that you attach are added to your Release and debug configurations.
Copy all files from the Openni ' s redist directory (See Change the variable "$ (openni2_redist)" or "$ (openni2_redist64)") to your working directory. (the default is C:\ProgramFiles\OpenNI2\Redist or C:\ProgramFiles (x86) \openni2\redist). Note that when you run at the command line, the working directory is the directory that the executable can discover. Where you run from the default directory of Visual Studio is where the project files (. vcproj,.vcxproj) can be found.
Key Tips:
Versions of 1.OPENNI2 and VS2010 must be consistent, both 32-bit or 64-bit
2.redist Catalog must think clearly how to fill in ...
#include <iostream>#include"OpenNI.h"intMainintargcChar**argv) { //initializing the Openni environmentopenni::openni::initialize (); //declaring and turning on device devices, I'm using Kinect. Openni::D evice devanydevice; Devanydevice.open (Openni::any_device); //Create and open a deep data streamOpenni::videostream streamdepth; Streamdepth.create (Devanydevice, openni::sensor_depth); Streamdepth.start (); //Create and open the color image data stream similarlyOpenni::videostream Streamcolor; Streamcolor.create (Devanydevice, Openni::sensor_color); Streamcolor.start (); //cycle through data stream information and save in VideoframerefOpenni::videoframeref framedepth; Openni::videoframeref FrameColor; for(inti =0; I < +; ++i) {//Read Data streamStreamdepth.readframe (&framedepth); Streamcolor.readframe (&FrameColor); //Get Data Array ConstOpenni::D epthpixel*pdepth= (ConstOpenni::D epthpixel*) Framedepth.getdata (); Constopenni::rgb888pixel*Pcolor= (Constopenni::rgb888pixel*) Framecolor.getdata (); //display depth information and corresponding color R, G, b values intIDX = Framedepth.getwidth () * (Framedepth.getheight () +1) /2; Std::cout<< Pdepth[idx] <<"( "<< (int) PCOLOR[IDX].R <<","<< (int) PCOLOR[IDX].G <<","<< (int) pcolor[idx].b <<")"<<Std::endl; } //Turn off Data flowStreamdepth.destroy (); Streamcolor.destroy (); //turn off the deviceDevanydevice.close (); //finally close OpenniOpenni::openni::shutdown (); return 0;}
Win8 vs2010 OPENNI2 Configuration