/// <summary>
        /// Initializes the camera and returns true on success, false otherwise.
        /// </summary>
        /// <returns>Initialization successful (true) or failed (false)</returns>
        private bool InitializeCamera()
        {
            /* UtilMPipeline works best for synchronous color and depth streaming */
            _pp = new UtilMPipeline();

            /* Set Input Source */
            _pp.capture.SetFilter("DepthSense Device 325V2");

            /* Set Color & Depth Resolution */
            var cinfo = GetConfiguration(PXCMImage.ColorFormat.COLOR_FORMAT_RGB32);
            _pp.EnableImage(PXCMImage.ColorFormat.COLOR_FORMAT_RGB32, cinfo.imageInfo.width, cinfo.imageInfo.height);
            _pp.capture.SetFilter(ref cinfo); // only needed to set FPS

            var dinfo2 = GetConfiguration(PXCMImage.ColorFormat.COLOR_FORMAT_DEPTH);
            _pp.EnableImage(PXCMImage.ColorFormat.COLOR_FORMAT_DEPTH, dinfo2.imageInfo.width, dinfo2.imageInfo.height);
            _pp.capture.SetFilter(ref dinfo2); // only needed to set FPS

            /* Initialization */
            if (!_pp.Init())
            {
                LogFormat("Could not initialize Senz3D hardware");
                HasErrorState = true;
                return false;
            }

            var capture = _pp.capture;
            _device = capture.device;
            _device.SetProperty(PXCMCapture.Device.Property.PROPERTY_DEPTH_CONFIDENCE_THRESHOLD, DepthConfidenceThreshold);
            _device.QueryProperty(PXCMCapture.Device.Property.PROPERTY_DEPTH_LOW_CONFIDENCE_VALUE, out EmguExtensions.LowConfidence);
            _device.QueryProperty(PXCMCapture.Device.Property.PROPERTY_DEPTH_SATURATION_VALUE, out EmguExtensions.Saturation);

            return true;
        }
Exemple #2
0
        private void DoRendering()
        {
            _isRunning = true;

            /* UtilMPipeline works best for synchronous color and depth streaming */
            _pp = new UtilMPipeline();

            /* Set Input Source */
            _pp.capture.SetFilter("DepthSense Device 325V2");

            /* Set Color & Depth Resolution */
            PXCMCapture.VideoStream.ProfileInfo cinfo = GetConfiguration(PXCMImage.ColorFormat.COLOR_FORMAT_RGB32);
            _pp.EnableImage(PXCMImage.ColorFormat.COLOR_FORMAT_RGB32, cinfo.imageInfo.width, cinfo.imageInfo.height);
            _pp.capture.SetFilter(ref cinfo); // only needed to set FPS

            PXCMCapture.VideoStream.ProfileInfo dinfo2 = GetConfiguration(PXCMImage.ColorFormat.COLOR_FORMAT_DEPTH);
            _pp.EnableImage(PXCMImage.ColorFormat.COLOR_FORMAT_DEPTH, dinfo2.imageInfo.width, dinfo2.imageInfo.height);
            _pp.capture.SetFilter(ref dinfo2); // only needed to set FPS

            /* Initialization */
            if (!_pp.Init())
            {
                LogFormat("Could not initialize Senz3D hardware");
                HasErrorState = true;
                return;
            }

            var capture = _pp.capture;
            _device = capture.device;
            _device.SetProperty(PXCMCapture.Device.Property.PROPERTY_DEPTH_CONFIDENCE_THRESHOLD, DepthConfidenceThreshold);
            _device.QueryProperty(PXCMCapture.Device.Property.PROPERTY_DEPTH_LOW_CONFIDENCE_VALUE, out EmguExtensions.LowConfidence);
            _device.QueryProperty(PXCMCapture.Device.Property.PROPERTY_DEPTH_SATURATION_VALUE, out EmguExtensions.Saturation);

            while (_isRunning)
            {
                /* If raw depth is needed, disable smoothing */
                _pp.capture.device.SetProperty(PXCMCapture.Device.Property.PROPERTY_DEPTH_SMOOTHING, DepthSmoothing ? 1 : 0);

                /* Wait until a frame is ready */
                if (!_pp.AcquireFrame(true)) break;
                if (_pp.IsDisconnected()) break;

                /* Get RGB color image */
                Stopwatch sw = Stopwatch.StartNew();
                var color = _pp.QueryImage(PXCMImage.ImageType.IMAGE_TYPE_COLOR);
                var colorBitmap = Senz3DUtils.GetRgb32Pixels(color);
                var colorImage = new Image<Rgb, byte>(colorBitmap);
                var colorImageCopy = colorImage.Copy();
                ColorImageFrameTime = sw.ElapsedMilliseconds;

                /* Get depth image */
                sw.Restart();
                var depth = _pp.QueryImage(PXCMImage.ImageType.IMAGE_TYPE_DEPTH);
                var depthImageAndConfidence = Senz3DUtils.GetHighPrecisionDepthImage(depth, MinDepthValue, MaxDepthValue);
                var depthImage = (Image<Gray, float>)depthImageAndConfidence[0];
                var depthImageCopy = depthImage.Copy();
                var confidenceMapImage = (Image<Rgb, Byte>)depthImageAndConfidence[1];
                var confidenceMapImageCopy = confidenceMapImage.Copy();
                DepthImageFrameTime = sw.ElapsedMilliseconds;
                ConfidenceMapImageFrameTime = 0;

                bool getRgbInDepthROI = false;
                /* if rgbInDepthROI is undefined get uvmap and rgbofdepth and rgbInDepthROI */
                if (_rgbInDepthROI.Left == 0 && _rgbInDepthROI.Right == 0 && _rgbInDepthROI.Width == 0 &&
                    _rgbInDepthROI.Height == 0)
                {
                    getRgbInDepthROI = true;
                }

                /* Get UV map */
                Image<Rgb, float> uvMapImage, uvMapImageCopy;
                if (UvMapChecked || getRgbInDepthROI)
                {
                    sw.Restart();
                    uvMapImage = Senz3DUtils.GetDepthUvMap(depth);
                    uvMapImageCopy = uvMapImage.Copy();
                    UVMapImageFrameTime = sw.ElapsedMilliseconds;
                }
                else
                {
                    uvMapImage = null;
                    uvMapImageCopy = null;
                    UVMapImageFrameTime = -1;
                }

                /* Get RgbOfDepth */
                Image<Rgb, byte> rgbOfDepthImage, rgbOfDepthImageCopy;
                if ((RgbOfDepthChecked && uvMapImage != null) || getRgbInDepthROI)
                {
                    sw.Restart();
                    if (getRgbInDepthROI)
                    {
                        rgbOfDepthImage = Senz3DUtils.GetRgbOfDepthPixels(depthImage, colorImage, uvMapImage, true, ref _rgbInDepthROI);
                        Stage(new ROI(this, "rgbInDepthROI")
                        {
                            RoiRectangle = _rgbInDepthROI
                        });
                        Push();

                        LogFormat("Identified rgbInDepthROI as {0}", _rgbInDepthROI);
                    }
                    else
                    {
                        rgbOfDepthImage = Senz3DUtils.GetRgbOfDepthPixels(depthImage, colorImage, uvMapImage);
                    }

                    rgbOfDepthImageCopy = rgbOfDepthImage.Copy();
                    RgbOfDepthImageFrameTime = sw.ElapsedMilliseconds;
                }
                else
                {
                    rgbOfDepthImage = null;
                    rgbOfDepthImageCopy = null;
                    RgbOfDepthImageFrameTime = -1;
                }

                /* Get DepthOfRGB */
                Image<Gray, float> depthOfRgbImage, depthOfRgbImageCopy;
                if (DepthOfRgbChecked && uvMapImage != null)
                {
                    sw.Restart();
                    depthOfRgbImage = Senz3DUtils.GetDepthOfRGBPixels(depthImage, colorImage, uvMapImage);
                    depthOfRgbImageCopy = depthOfRgbImage.Copy();
                    DepthOfRgbImageFrameTime = sw.ElapsedMilliseconds;
                }
                else
                {
                    depthOfRgbImage = null;
                    depthOfRgbImageCopy = null;
                    DepthOfRgbImageFrameTime = -1;
                }

                _pp.ReleaseFrame();

                if (IsRenderContent)
                {
                    Task.Factory.StartNew(() =>
                    {
                        var bitmap = colorImageCopy.ToBitmapSource(true);
                        colorImageCopy.Dispose();
                        return bitmap;
                    }).ContinueWith(s => ColorImageSource = s.Result);

                    Task.Factory.StartNew(() =>
                    {
                        var bitmap = depthImageCopy.ToGradientBitmapSource(true, EmguExtensions.LowConfidence, EmguExtensions.Saturation);
                        depthImageCopy.Dispose();
                        return bitmap;
                    }).ContinueWith(s => DepthImageSource = s.Result);

                    Task.Factory.StartNew(() =>
                    {
                        var bitmap = confidenceMapImageCopy.ToBitmapSource(true);
                        confidenceMapImageCopy.Dispose();
                        return bitmap;
                    }).ContinueWith(s => ConfidenceMapImageSource = s.Result);

                    /* draw uvmap */
                    if (uvMapImage != null)
                        Task.Factory.StartNew(() =>
                            {
                                var bitmap = uvMapImageCopy.ToBitmapSource(true);
                                uvMapImageCopy.Dispose();
                                return bitmap;
                            }).ContinueWith(s => UVMapImageSource = s.Result);

                    /* draw rgbofdepth */
                    if (rgbOfDepthImage != null)
                    {
                        Task.Factory.StartNew(() =>
                        {
                            var bitmap = rgbOfDepthImageCopy.ToBitmapSource(true);
                            rgbOfDepthImageCopy.Dispose();
                            return bitmap;
                        }).ContinueWith(s => RgbOfDepthImageSource = s.Result);
                    }

                    /* draw depthofrgb */
                    if (depthOfRgbImage != null)
                        Task.Factory.StartNew(() =>
                        {
                            var bitmap = depthOfRgbImageCopy.ToGradientBitmapSource(true, EmguExtensions.LowConfidence, EmguExtensions.Saturation);
                            depthOfRgbImageCopy.Dispose();
                            return bitmap;
                        }).ContinueWith(s => DepthOfRgbImageSource = s.Result);
                }

                var dc = new DataContainer(++_frameId, DateTime.Now)
                    {
                        new RgbImageData(this, "color", colorImage),
                        new GrayFloatImage(this, "depth", depthImage),
                        new RgbImageData(this, "confidence", confidenceMapImage),
                    };

                if (uvMapImage != null) dc.Add(new RgbFloatImage(this, "uvmap", uvMapImage));
                if (rgbOfDepthImage != null) dc.Add(new RgbImageData(this, "rgbofdepth", rgbOfDepthImage));
                if (depthOfRgbImage != null) dc.Add(new GrayFloatImage(this, "depthofrgb", depthOfRgbImage));
                Publish(dc);
            }

            _pp.Close();
            _pp.Dispose();
        }
        private void PopulateColorMenus(ToolStripMenuItem device_item)
        {
            OperatingSystem os_version = Environment.OSVersion;

            PXCMSession.ImplDesc desc = new PXCMSession.ImplDesc();
            desc.group    = PXCMSession.ImplGroup.IMPL_GROUP_SENSOR;
            desc.subgroup = PXCMSession.ImplSubgroup.IMPL_SUBGROUP_VIDEO_CAPTURE;
            desc.iuid     = devices_iuid[device_item];
            desc.cuids[0] = PXCMCapture.CUID;

            profiles.Clear();
            ColorMenu.DropDownItems.Clear();
            PXCMCapture capture;

            PXCMCapture.DeviceInfo dinfo2 = GetCheckedDevice();

            PXCMSenseManager pp = session.CreateSenseManager();

            if (pp == null)
            {
                return;
            }
            if (pp.Enable3DScan() < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                return;
            }
            PXCM3DScan s = pp.Query3DScan();

            if (s == null)
            {
                return;
            }
            PXCMVideoModule m = s.QueryInstance <PXCMVideoModule>();

            if (m == null)
            {
                return;
            }

            int count = 0;

            if (session.CreateImpl <PXCMCapture>(desc, out capture) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                PXCMCapture.Device device = capture.CreateDevice(dinfo2.didx);
                if (device != null)
                {
                    PXCMCapture.Device.StreamProfileSet profile = new PXCMCapture.Device.StreamProfileSet();;
                    if (dinfo2.streams.HasFlag(PXCMCapture.StreamType.STREAM_TYPE_COLOR))
                    {
                        for (int p = 0; ; p++)
                        {
                            if (device.QueryStreamProfileSet(PXCMCapture.StreamType.STREAM_TYPE_COLOR, p, out profile) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                            {
                                break;
                            }
                            PXCMCapture.Device.StreamProfile sprofile = profile[PXCMCapture.StreamType.STREAM_TYPE_COLOR];

                            // Only populate profiles which are supported by the module
                            bool bFound = false;
                            int  i      = 0;
                            PXCMVideoModule.DataDesc inputs;
                            PXCMImage.PixelFormat    format = PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32;
                            if (dinfo2.orientation != PXCMCapture.DeviceOrientation.DEVICE_ORIENTATION_REAR_FACING)
                            {
                                format = PXCMImage.PixelFormat.PIXEL_FORMAT_RGB24;
                            }
                            while ((m.QueryCaptureProfile(i++, out inputs) >= pxcmStatus.PXCM_STATUS_NO_ERROR))
                            {
                                if ((sprofile.imageInfo.height == inputs.streams.color.sizeMax.height) &&
                                    (sprofile.imageInfo.width == inputs.streams.color.sizeMax.width) &&
                                    (sprofile.frameRate.max == inputs.streams.color.frameRate.max) &&
                                    (sprofile.imageInfo.format == format) &&
                                    (0 == (sprofile.options & PXCMCapture.Device.StreamOption.STREAM_OPTION_UNRECTIFIED)))
                                {
                                    bFound = true;
                                    if (dinfo2.orientation != PXCMCapture.DeviceOrientation.DEVICE_ORIENTATION_REAR_FACING)
                                    {   // Hide rear facing resolutions when the front facing camera is connected...
                                        if (sprofile.imageInfo.width == 640)
                                        {
                                            bFound = false;
                                        }
                                    }
                                    // On Windows 7, filter non-functional 30 fps modes
                                    if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 1)
                                    {
                                        if (sprofile.frameRate.max == 30)
                                        {
                                            bFound = false;
                                        }
                                    }
                                }
                            }
                            if (bFound)
                            {
                                ToolStripMenuItem sm1 = new ToolStripMenuItem(ProfileToString(sprofile), null, new EventHandler(Color_Item_Click));
                                profiles[sm1] = sprofile;
                                ColorMenu.DropDownItems.Add(sm1);
                                count++;
                            }
                        }
                    }
                    device.Dispose();
                }
                capture.Dispose();
            }
            m.Dispose();
            pp.Dispose();
            if (count > 0)
            {
                (ColorMenu.DropDownItems[ColorMenu.DropDownItems.Count - 1] as ToolStripMenuItem).Checked = true;
            }
        }
        private bool PopulateDeviceFromFileMenu()
        {
            devices.Clear();
            devices_iuid.Clear();

            PXCMSession.ImplDesc desc = new PXCMSession.ImplDesc();
            desc.group    = PXCMSession.ImplGroup.IMPL_GROUP_SENSOR;
            desc.subgroup = PXCMSession.ImplSubgroup.IMPL_SUBGROUP_VIDEO_CAPTURE;

            PXCMSession.ImplDesc   desc1;
            PXCMCapture.Device     device = null;
            PXCMCapture.DeviceInfo dinfo;
            PXCMSenseManager       pp = PXCMSenseManager.CreateInstance();

            if (pp == null)
            {
                UpdateStatus("Init Failed");
                return(false);
            }
            if (pp.captureManager == null)
            {
                pp.Dispose();
                UpdateStatus("Init Failed");
                return(false);
            }
            try
            {
                if (session.QueryImpl(desc, 0, out desc1) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    throw null;
                }
                if (pp.captureManager.SetFileName(filename, false) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    throw null;
                }
                if (pp.captureManager.LocateStreams() < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    throw null;
                }
                device = pp.captureManager.QueryDevice();
                if (device != null)
                {
                    device.QueryDeviceInfo(out dinfo);
                }
                else
                {
                    pp.Dispose();
                    UpdateStatus("Init Failed");
                    return(false);
                }
            }
            catch
            {
                pp.Dispose();
                UpdateStatus("Init Failed");
                return(false);
            }
            DeviceMenu.DropDownItems.Clear();
            ToolStripMenuItem sm1 = new ToolStripMenuItem(dinfo.name, null, new EventHandler(Device_Item_Click));

            devices[sm1]      = dinfo;
            devices_iuid[sm1] = desc1.iuid;
            DeviceMenu.DropDownItems.Add(sm1);

            sm1         = new ToolStripMenuItem("Playback from the file : ", null);
            sm1.Enabled = false;
            DeviceMenu.DropDownItems.Add(sm1);
            sm1         = new ToolStripMenuItem(filename, null);
            sm1.Enabled = false;
            DeviceMenu.DropDownItems.Add(sm1);
            if (DeviceMenu.DropDownItems.Count > 0)
            {
                (DeviceMenu.DropDownItems[0] as ToolStripMenuItem).Checked = true;
            }

            // populate color depth menu from the file
            profiles.Clear();
            ColorMenu.DropDownItems.Clear();
            DepthMenu.DropDownItems.Clear();

            PXCMCapture.Device.StreamProfileSet profile = new PXCMCapture.Device.StreamProfileSet();
            if (dinfo.streams.HasFlag(PXCMCapture.StreamType.STREAM_TYPE_COLOR))
            {
                for (int p = 0; ; p++)
                {
                    if (device.QueryStreamProfileSet(PXCMCapture.StreamType.STREAM_TYPE_COLOR, p, out profile) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        break;
                    }
                    PXCMCapture.Device.StreamProfile sprofile = profile[PXCMCapture.StreamType.STREAM_TYPE_COLOR];
                    sm1           = new ToolStripMenuItem(ProfileToString(sprofile), null, new EventHandler(Color_Item_Click));
                    profiles[sm1] = sprofile;
                    ColorMenu.DropDownItems.Add(sm1);
                }
            }

            if (((int)dinfo.streams & (int)PXCMCapture.StreamType.STREAM_TYPE_DEPTH) != 0)
            {
                for (int p = 0; ; p++)
                {
                    if (device.QueryStreamProfileSet(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, p, out profile) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        break;
                    }
                    PXCMCapture.Device.StreamProfile sprofile = profile[PXCMCapture.StreamType.STREAM_TYPE_DEPTH];
                    if (sprofile.options != (PXCMCapture.Device.StreamOption) 0x20000) // do not show Depth Confidence
                    {
                        sm1           = new ToolStripMenuItem(ProfileToString(sprofile), null, new EventHandler(Depth_Item_Click));
                        profiles[sm1] = sprofile;
                        DepthMenu.DropDownItems.Add(sm1);
                    }
                }
            }

            GetCheckedDevice();

            pp.Close();
            pp.Dispose();
            return(true);
        }
        private void InitializeFace()
        {
            // 顔検出を有効にする
            var sts = senceManager.EnableFace();

            if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                throw new Exception("顔検出の有効化に失敗しました");
            }

            //顔検出器を生成する
            var faceModule = senceManager.QueryFace();

            //顔検出のプロパティを取得
            PXCMFaceConfiguration config = faceModule.CreateActiveConfiguration();

            config.SetTrackingMode(PXCMFaceConfiguration.TrackingModeType.FACE_MODE_COLOR_PLUS_DEPTH);


            config.ApplyChanges();

            // パイプラインを初期化する
            pxcmStatus ret = senceManager.Init();

            if (ret < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                throw new Exception("初期化に失敗しました");
            }

            // デバイス情報の取得
            PXCMCapture.Device device = senceManager.QueryCaptureManager().QueryDevice();
            if (device == null)
            {
                throw new Exception("deviceの生成に失敗しました");
            }


            // ミラー表示にする
            device.SetMirrorMode(PXCMCapture.Device.MirrorMode.MIRROR_MODE_HORIZONTAL);

            PXCMCapture.DeviceInfo deviceInfo;
            device.QueryDeviceInfo(out deviceInfo);
            if (deviceInfo.model == PXCMCapture.DeviceModel.DEVICE_MODEL_IVCAM)
            {
                device.SetDepthConfidenceThreshold(1);
                device.SetIVCAMFilterOption(6);
                device.SetIVCAMMotionRangeTradeOff(21);
            }


            config.detection.isEnabled       = true;
            config.detection.maxTrackedFaces = DETECTION_MAXFACES;
            //config.pose.isEnabled = true;
            //config.landmarks.isEnabled = true;
            //config.QueryExpressions().Enable();
            //config.QueryExpressions().EnableAllExpressions();
            //config.QueryRecognition().Enable();
            //config.QueryExpressions().properties.maxTrackedFaces = 2;
            config.ApplyChanges();

            faceData = faceModule.CreateOutput();
        }
Exemple #6
0
        public void SimplePipeline()
        {
            PXCMSenseManager pp = m_form.Session.CreateSenseManager();

            if (pp == null)
            {
                throw new Exception("PXCMSenseManager null");
            }

            PXCMCaptureManager captureMgr = pp.captureManager;

            if (captureMgr == null)
            {
                throw new Exception("PXCMCaptureManager null");
            }

            var selectedRes = m_form.GetCheckedColorResolution();

            if (selectedRes != null)
            {
                // Set active camera
                PXCMCapture.DeviceInfo deviceInfo;
                m_form.Devices.TryGetValue(m_form.GetCheckedDevice(), out deviceInfo);
                captureMgr.FilterByDeviceInfo(m_form.GetCheckedDeviceInfo());

                // activate filter only live/record mode , no need in playback mode
                var set = new PXCMCapture.Device.StreamProfileSet
                {
                    color =
                    {
                        frameRate = selectedRes.Item2,
                        imageInfo =
                        {
                            format = selectedRes.Item1.format,
                            height = selectedRes.Item1.height,
                            width  = selectedRes.Item1.width
                        }
                    }
                };
            }

            // Set Module
            pp.EnableFace();
            PXCMFaceModule faceModule = pp.QueryFace();

            if (faceModule == null)
            {
                Debug.Assert(faceModule != null);
                return;
            }

            PXCMFaceConfiguration moduleConfiguration = faceModule.CreateActiveConfiguration();

            if (moduleConfiguration == null)
            {
                Debug.Assert(moduleConfiguration != null);
                return;
            }

            var checkedProfile = m_form.GetCheckedProfile();
            var mode           = m_form.FaceModesMap.First(x => x.Value == checkedProfile).Key;

            moduleConfiguration.SetTrackingMode(mode);

            moduleConfiguration.strategy = PXCMFaceConfiguration.TrackingStrategyType.STRATEGY_RIGHT_TO_LEFT;

            PXCMFaceConfiguration.ExpressionsConfiguration econfiguration = moduleConfiguration.QueryExpressions();
            if (econfiguration == null)
            {
                throw new Exception("ExpressionsConfiguration null");
            }
            econfiguration.properties.maxTrackedFaces = 4; //Expressionの最大認識量

            econfiguration.EnableAllExpressions();
            //if (m_form.IsExpressionsEnabled())
            //{
            econfiguration.Enable(); //Expressionsの強制有効化
            //}
            moduleConfiguration.EnableAllAlerts();
            moduleConfiguration.SubscribeAlert(FaceAlertHandler);

            pxcmStatus applyChangesStatus = moduleConfiguration.ApplyChanges();

            m_form.UpdateStatus("Init Started", MainForm.Label.StatusLabel);
            m_form.UpdateStatus("カメラ起動中", MainForm.Label.ReportLabel);

            if (applyChangesStatus < pxcmStatus.PXCM_STATUS_NO_ERROR || pp.Init() < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                m_form.UpdateStatus("Init Failed", MainForm.Label.StatusLabel);
                m_form.UpdateStatus("設定エラー:メニューから適切な設定をしてください。", MainForm.Label.ReportLabel);
            }
            else
            {
                using (PXCMFaceData moduleOutput = faceModule.CreateOutput())
                {
                    Debug.Assert(moduleOutput != null);
                    PXCMCapture.Device.StreamProfileSet profiles;
                    PXCMCapture.Device device = captureMgr.QueryDevice();

                    if (device == null)
                    {
                        m_form.UpdateStatus("カメラを接続してください。", MainForm.Label.ReportLabel);
                        throw new Exception("device null");
                    }

                    device.QueryStreamProfileSet(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 0, out profiles);
                    CheckForDepthStream(profiles, faceModule);

                    m_form.UpdateStatus("Streaming", MainForm.Label.StatusLabel);
                    m_timer = new FPSTimer(m_form);

                    while (!m_form.Stopped)
                    {
                        if (pp.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                        {
                            break;
                        }
                        var isConnected = pp.IsConnected();
                        DisplayDeviceConnection(isConnected);
                        if (isConnected)
                        {
                            var sample = pp.QueryFaceSample();
                            if (sample == null)
                            {
                                pp.ReleaseFrame();
                                continue;
                            }
                            switch (mode)
                            {
                            case PXCMFaceConfiguration.TrackingModeType.FACE_MODE_IR:
                                if (sample.ir != null)
                                {
                                    DisplayPicture(sample.ir);
                                }
                                break;

                            default:
                                DisplayPicture(sample.color);
                                break;
                            }

                            moduleOutput.Update();
                            PXCMFaceConfiguration.RecognitionConfiguration recognition = moduleConfiguration.QueryRecognition();
                            if (recognition == null)
                            {
                                pp.ReleaseFrame();
                                continue;
                            }

                            m_form.DrawGraphics(moduleOutput);
                            m_form.UpdatePanel();
                        }
                        pp.ReleaseFrame();
                    }
                }

                //             moduleConfiguration.UnsubscribeAlert(FaceAlertHandler);
                //             moduleConfiguration.ApplyChanges();
                m_form.UpdateStatus("Stopped", MainForm.Label.StatusLabel);
            }
            moduleConfiguration.Dispose();
            pp.Close();
            pp.Dispose();
        }