コード例 #1
0
ファイル: MainForm.cs プロジェクト: cignoir/KinecTh
        /// <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();
        }