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(); }
void Start() { context = new Context(XML_FILE); depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator; if (depth == null) { Debug.LogError("Viewer must have a depth node!"); return; } imageGenerator = context.FindExistingNode(NodeType.Image) as ImageGenerator; if (imageGenerator == null) { Debug.LogError("Viewer must have an image generator!"); return; } userGenerator = new UserGenerator(context); skeletonCapability = new SkeletonCapability(userGenerator); poseDetectionCapability = new PoseDetectionCapability(userGenerator); calibPose = skeletonCapability.GetCalibrationPose(); userGenerator.NewUser += new UserGenerator.NewUserHandler(userGenerator_NewUser); userGenerator.LostUser += new UserGenerator.LostUserHandler(userGenerator_LostUser); poseDetectionCapability.PoseDetected += new PoseDetectionCapability.PoseDetectedHandler(poseDetectionCapability_PoseDetected); skeletonCapability.CalibrationEnd += new SkeletonCapability.CalibrationEndHandler(skeletonCapability_CalibrationEnd); skeletonCapability.SetSkeletonProfile(SkeletonProfile.All); userGenerator.StartGenerating(); MapOutputMode mapMode = depth.GetMapOutputMode(); GameObject o = new GameObject("User"); mainUser = o.transform; mainUser.position = new Vector3(0,0,0); mainUser.parent = transform; GameObject obj = Instantiate(o, new Vector3(0,0,0), Quaternion.identity) as GameObject; center = obj.transform; //center.parent = mainUser; obj.name = "Center"; createDefaultLineRenderer(center); obj = Instantiate(o, new Vector3(0,0,0), Quaternion.identity) as GameObject; leftArm = obj.transform; //leftArm.parent = mainUser; obj.name = "L Arm"; createDefaultLineRenderer(leftArm); obj = Instantiate(o, new Vector3(0,0,0), Quaternion.identity) as GameObject; rightArm = obj.transform; //rightArm.parent = mainUser; obj.name = "R Arm"; createDefaultLineRenderer(rightArm); obj = Instantiate(o, new Vector3(0,0,0), Quaternion.identity) as GameObject; leftLeg = obj.transform; //leftLeg.parent = mainUser; obj.name = "L Leg"; createDefaultLineRenderer(leftLeg); obj = Instantiate(o, new Vector3(0,0,0), Quaternion.identity) as GameObject; rightLeg = obj.transform; //rightLeg.parent = mainUser; obj.name = "R Leg"; createDefaultLineRenderer(rightLeg); }