void Start() { rgbTexture = new Texture2D (640, 480, TextureFormat.RGB24, false); rgbMaterial.mainTextureScale = new Vector2 (0.62f, 0.93f); // fixes weird scaling problem rgbMaterial.mainTexture = rgbTexture; 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; } depth.GetAlternativeViewPointCap ().SetViewPoint (imageGenerator); imageGenerator.StartGenerating (); }
void Start() { texture = new Texture2D (640, 480, TextureFormat.RGB24, false); rgbMaterial.mainTextureScale = new Vector2 (0.62f, 0.93f); // fixes weird scaling problem rgbMaterial.mainTexture = texture; 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; } depth.GetAlternativeViewPointCap ().SetViewPoint (imageGenerator); //handsGenerator = context.FindExistingNode(NodeType.Hands) as HandsGenerator; //if (handsGenerator == null) { // Debug.LogError("Viewer must have a hands generator!"); // return; //} //handsGenerator.GetAlternativeViewPointCap().SetViewPoint(imageGenerator); //gestureGenerator = context.FindExistingNode (NodeType.Gesture) as GestureGenerator; //if (gestureGenerator == null) { // Debug.LogError ("Viewer must have a gesture node!"); //} //gestureGenerator.GetAlternativeViewPointCap().SetViewPoint(imageGenerator); 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 (); imageGenerator.StartGenerating (); //handsGenerator.HandCreate += new HandsGenerator.HandCreateHandler (hands_HandCreate); //handsGenerator.HandUpdate += new HandsGenerator.HandUpdateHandler (hands_HandUpdate); //handsGenerator.HandDestroy += new HandsGenerator.HandDestroyHandler (hands_HandDestroy); //gestureGenerator.AddGesture ("Wave"); //gestureGenerator.GestureRecognized += new GestureGenerator.GestureRecognizedHandler (gestures_GestureRecognized); //gestureGenerator.StartGenerating(); if (drawSkeleton) { 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); } }
/// <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(); }