摘要:OpenNI 程式解讀
挑了一個看起來最單純的範例程式
C:\Program Files\OpenNI\Samples\NiSimpleRead
執行起來只有一個Console一直跑出數值
#include <XnOpenNI.h>
C:\Program Files\OpenNI\Include\XnOpenNI.h
#include <XnLog.h>
C:\Program Files\OpenNI\Include\XnLog.h
#include <XnCppWrapper.h>
C:\Program Files\OpenNI\Include\XnCppWrapper.h
#include <XnFPSCalculator.h>
C:\Program Files\OpenNI\Include\XnFPSCalculator.h
using namespace xn;
c:\Program Files\OpenNI\Include\XnStatus.h
設定檔 C:\Program Files\OpenNI\Data\SamplesConfig.xml
<OpenNI>
<Licenses>
<!-- Add application-specific licenses here
<License vendor="vendor" key="key"/>
-->
</Licenses>
<Log writeToConsole="false" writeToFile="false">
<!-- 0 - Verbose, 1 - Info, 2 - Warning, 3 - Error (default) -->
<LogLevel value="3"/>
<Masks>
<Mask name="ALL" on="true"/>
</Masks>
<Dumps>
</Dumps>
</Log>
<ProductionNodes>
<!-- Uncomment following line, in order to run from a recording
<Recording file="sampleRec.oni" />
-->
<!-- Set global mirror -->
<GlobalMirror on="true"/>
<!-- Create a depth node and give it a name alias (useful if referenced ahead in this script) -->
<Node type="Depth" name="MyDepth">
<Query>
<!-- Uncomment to filter by vendor name, product name, etc.
<Vendor>MyVendor inc.</Vendor>
<Name>MyProduct</Name>
<MinVersion>1.2.3.4</MinVersion>
<Capabilities>
<Capability>Cropping</Capability>
</Capabilities>
-->
</Query>
<Configuration>
<!-- Uncomment to set requested mode
<MapOutputMode xRes="640" yRes="480" FPS="30"/>
-->
<!-- Uncomment to override global mirror
<Mirror on="false" />
-->
</Configuration>
</Node>
<!-- Create an image node. If it fails, continue anyway. -->
<Node type="Image" stopOnError="false" />
<!-- Uncomment nodes from here if you need them.
<Node type="Audio" />
<Node type="User" />
<Node type="Hands" />
<Node type="Gesture" />
<Node type="Scene" />
-->
</ProductionNodes>
</OpenNI>
讓我們把這個最簡單的程式SimpleRead加到OGRE中
這裏岔個題, 我的VS2010 一直遇到錯誤訊息,
c1xx : fatal error C1027: Inconsistent values for /Ym between creation and use of precompiled header
如果你知道這個東東要怎麼解決, 歡迎你的指教...
我產生了一個空的Ogre專案, 在場景中放入一個Sinbad人物,
因為OpenNI要等待資料進來, 我們的Render又不能等, 所以要另外開一個thread給OpenNI
boost::thread(&OpenRzNIApp::openNIThread,this);
這個thread要一直讀depth的圖
nRetVal = ONIContext.WaitOneUpdateAll(ONIDepth);
因為讀進來的值有點跳動, 我做了一點smooth, 然後把它Mapping到適當的值域
goodDepth = Rz::smoothToTarget(goodDepth,depthPoint,150.0f,evt.timeSinceLastFrame,10.0f);
float remap = Rz::LinearClampBoth(goodDepth,0,1900,0,800);
SinbadNode->setPosition(0,0,remap);
結果就像這樣
Sinbad會跟著我相對於攝影機移動而改變位置
![]() |
|


