sdk架构示意图:php
C#中须要用的动态连接库文件:css
位于文件夹:$(RSSDK_DIR)/bin/x64 或 $(RSSDK_DIR)/bin/win32 中html
C++/C#层次体系(M表示托管Managed)。全模块化。java
PXC[M]Session继承自PXC[M]Base,包含I/O模块、算法模块和其余接口执行模块。首先要经过静态函数CreateInstance建立session实例,而后经过该实例建立其余模块的实例。node
public class PXCMSession : PXCMBase { ... public static PXCMSession CreateInstance(); public PXCMSenseManager CreateSenseManager(); ... }
PXC[M]SenseManager组织一个多模态管道(包括I/O设备和多个算法模块),控制管道的开始、中止、暂停、继续等等。CreateInstance建立SenseManager实例nginx
public class PXCMSenseManager : PXCMBase { ... public static PXCMSenseManager CreateInstance(); ... }
在内部,PXC[M]SenseManager经过PXC[M]CaptureManager来选择I/O设备和色彩/深度/声音流。git
初始化管道时在PXC[M]SenseManager中取得PXC[M]CaptureManager的实例,能够用来强制设备搜索,以及设置录制和回放。而后取得PXC[M]Capture接口,可用来操做物理摄像头,如枚举设备/流,及查询流配置和设备属性。github
管道运行过程当中,能够经过PXC[M]Image接口,来获取I/O设备中就绪的samples,即图像缓存。web
管道中能够包含算法模块,如PXC[M]HandModule手部追踪,PXC[M]FaceModule面部追踪,利用这些模块进行相应的设置和算法数据查询。ajax
PXC[M]AudioSource接口获取声音。特定的语音特征直接在模块接口中,如PXC[M]SpeechRecognition
An SDK session is the context that holds these modules. 应用程序中能够建立一个或多个sdk sessions,每一个session维护本身单独的I/O和算法模块context。模块的生命周期由session的使用决定。PXCMSession在其它模块建立前建立,在其它模块销毁后销毁。session必须是第一个建立,最后一个销毁。
C#托管实例内部指向C++非托管实例。
PXC[M]SenseManager是这种案例的主要接口:
(1)有一个或多个算法模块;
(2)一个摄像头;(多个摄像头的话能够创建多个实例)
(3)摄像头为算法模块提供数据;
理论上,应用程序能够同时独立地处理每一个图像捕获和算法运行通道,每一个通道都被赋予了一个模块ID:
PXC[M]SenseManager典型的使用流程:
建立实例PXCMSenseManager sm=PXCMSenseManager.CreateInstance();
配置组件。EnableXXX函数来激活模块sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR,0,0);
控制运行流程,获取结果。根据线程模型,使用消息环或者事件回调传递数据。
sm.Init(); for (;;) { pxcmStatus sts=sm.AcquireFrame(true); //AcquireFrame函数等待帧数据就绪 if (sts<pxcmStatus.PXCM_STATUS_NO_ERROR) break; PXCMCapture.Sample sample; sample=sm.QuerySample(); //QuerySample获取图像 .... // process image sm.ReleaseFrame(); //继续下一帧 } sm.Close();
pxcmStatus OnNewSample(int mid, PXCMCapture.Sample sample) { // return NO ERROR to continue, // or any ERROR to exit the loop return pxcmStatus.PXCM_STATUS_NO_ERROR; } void MainRoutine(PXCMSession session) { ... // Initialize my event handler PXCMSenseManager::Handler handler= new PXCMSenseManager.Handler(); handler.onNewSample=OnNewSample; // Stream depth samples sm.Init(handler); sm.StreamFrames(true); sm.Close(); ... }
释放实例。完整过程:
PXCMSenseManager sm=PXCMSenseManager.CreateInstance(); sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR,0,0,0); sm.Init(); while (sm.AcquireFrame(true)>=pxcmStatus.PXCM_STATUS_NO_ERROR) { PXCMCapture.Sample sample=sm.QuerySample(); .... // process image sm.ReleaseFrame(); } sm.Dispose();
generated by haroopad