private NuiSource() { context = new Context("openni.xml"); // Initialise generators imageGenerator = this.context.FindExistingNode(NodeType.Image) as ImageGenerator; depthGenerator = this.context.FindExistingNode(NodeType.Depth) as DepthGenerator; imageMetadata = new ImageMetaData(); var imageMapMode = imageGenerator.GetMapOutputMode(); depthMetadata = new DepthMetaData(); var depthMapMode = depthGenerator.GetMapOutputMode(); depthHistogram = new int[depthGenerator.GetDeviceMaxDepth()]; // Initialise bitmaps cameraImage = new WriteableBitmap((int)imageMapMode.nXRes, (int)imageMapMode.nYRes, 96, 96, PixelFormats.Rgb24, null); depthImage = new WriteableBitmap((int)depthMapMode.nXRes, (int)depthMapMode.nYRes, 96, 96, PixelFormats.Rgb24, null); // Initialise background thread var cameraThread = new Thread(this.CameraThread) { IsBackground = true }; cameraThread.Start(); var userGenerator = new UserGenerator(context); userGenerator.NewUser += this.UserGenerator_NewUser; userGenerator.LostUser += this.UserGenerator_LostUser; }
public void Initialize() { context = new Context(@"..\..\..\data\openniconfig.xml"); depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator; rgb = context.FindExistingNode(NodeType.Image) as ImageGenerator; if (depth == null) throw new Exception(@"Error in Data\openniconfig.xml. No depth node found."); if (rgb == null) throw new Exception(@"Error in Data\openniconfig.xml. No rgb node found."); MapOutputMode mapMode = depth.GetMapOutputMode(); // Initialize member variables depthHistogram = new int[depth.GetDeviceMaxDepth()]; // initialize rgb array xn.ImageMetaData rgbMD = rgb.GetMetaData(); rgbData = new byte[rgbMD.XRes * rgbMD.YRes * 3]; rgbWidth = rgbMD.XRes; rgbHeight = rgbMD.YRes; xn.DepthMetaData depthMD = depth.GetMetaData(); depthData = new ushort[depthMD.XRes * depthMD.YRes]; oldDepthData = new ushort[depthMD.XRes * depthMD.YRes]; histogramImage = new byte[depthMD.XRes * depthMD.YRes * 3]; depthWidth = depthMD.XRes; depthHeight = depthMD.YRes; depthOffsetX = depthMD.XOffset; depthOffsetY = depthMD.YOffset; DispatcherTimer dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 30); dispatcherTimer.Start(); }
/// <summary> /// OpenNIスレッドの起動 /// /// </summary> private void StartOpenNI() { try { context = new Context(Application.StartupPath + Settings.OPENNI_CONFIG); } catch(GeneralException ge){ Console.WriteLine(ge.Message); this.Close(); return; } depthGenerator = context.FindExistingNode(NodeType.Depth) as DepthGenerator; if (this.depthGenerator == null) { throw new Exception("Viewer must have a depth node!"); } userGenerator = new UserGenerator(context); userGenerator.NewUser += new UserGenerator.NewUserHandler(userGenerator_NewUser); userGenerator.LostUser += new UserGenerator.LostUserHandler(userGenerator_LostUser); userGenerator.StartGenerating(); imageGenerator = context.FindExistingNode(NodeType.Image) as ImageGenerator; imageGenerator.StartGenerating(); poseDetectionCapability = new PoseDetectionCapability(userGenerator); poseDetectionCapability.PoseDetected += new PoseDetectionCapability.PoseDetectedHandler(poseDetectionCapability_PoseDetected); skeletonCapability = new SkeletonCapability(userGenerator); skeletonCapability.CalibrationEnd += new SkeletonCapability.CalibrationEndHandler(skeletonCapability_CalibrationEnd); skeletonCapability.SetSkeletonProfile(SkeletonProfile.All); depthGenerator.GetAlternativeViewPointCap().SetViewPoint(imageGenerator); histogram = new int[depthGenerator.GetDeviceMaxDepth()]; // 出力モード //this.mapMode = depthGenerator.GetMapOutputMode(); this.mapMode = imageGenerator.GetMapOutputMode(); bitmap = new Bitmap((int)mapMode.nXRes, (int)mapMode.nYRes/*, System.Drawing.Imaging.PixelFormat.Format24bppRgb*/); shouldRun = true; openNiThread = new Thread(ReaderThread); openNiThread.Start(); }