Example #1
0
        private void ScanForCameras()
        {
            deviceInfo.Clear();
            devicesUIDs.Clear();

            PXCMSession.ImplDesc   desc1;
            PXCMCapture.DeviceInfo dinfo = null;

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

            for (int i = 0; ; i++)
            {
                if (session.QueryImpl(desc, i, out desc1) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    break;
                }
                PXCMCapture capture;
                if (session.CreateImpl <PXCMCapture>(desc1, out capture) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    continue;
                }
                for (int j = 0; ; j++)
                {
                    if (capture.QueryDeviceInfo(j, out dinfo) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        break;
                    }
                    deviceInfo.Add(dinfo);
                    devicesUIDs.Add(desc1.iuid);
                }
                capture.Dispose();
            }
        }
Example #2
0
 internal DataDesc(DataDescINT data)
 {
     devCaps    = data.devCaps;
     deviceInfo = data.deviceInfo;
     streams    = new StreamDescSet(data.streams);
     reserved   = new Int32[8];
 }
Example #3
0
 public DataDesc()
 {
     streams    = new StreamDescSet();
     devCaps    = new DeviceCap[DEVCAP_LIMIT];
     deviceInfo = new PXCMCapture.DeviceInfo();
     reserved   = new Int32[8];
 }
Example #4
0
        private pxcmStatus InitializeFace()
        {
            pxcmStatus result = pxcmStatus.PXCM_STATUS_NO_ERROR;

            // 顔検出を有効にする
            result = this.SenseManager.EnableFace();
            if (result < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                this.Message = "Face Stream Enabled Error.";
            }
            else
            {
                // 追加:表情検出を有効にする
                result = this.SenseManager.EnableEmotion();
                if (result < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    this.Message = "Face Stream Enabled Error.";
                }
                else
                {
                    // パイプラインを初期化する
                    result = this.SenseManager.Init();
                    if (result < pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        this.Message = "Initialize Error.";
                    }
                    else
                    {
                        // ミラー表示にする
                        this.SenseManager.QueryCaptureManager().QueryDevice().SetMirrorMode(
                            PXCMCapture.Device.MirrorMode.MIRROR_MODE_HORIZONTAL);

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

                        // 顔検出器の設定
                        var device = this.SenseManager.QueryCaptureManager().QueryDevice();
                        PXCMCapture.DeviceInfo info = null;
                        device.QueryDeviceInfo(out info);
                        if (info.model == PXCMCapture.DeviceModel.DEVICE_MODEL_IVCAM)
                        {
                            device.SetDepthConfidenceThreshold(1);
                            device.SetIVCAMFilterOption(6);
                            device.SetIVCAMMotionRangeTradeOff(21);
                        }

                        //顔検出モードをカラー画像モードに設定
                        var config = faceModule.CreateActiveConfiguration();
                        config.SetTrackingMode(PXCMFaceConfiguration.TrackingModeType.FACE_MODE_COLOR);
                        config.detection.isEnabled = true;
                        config.ApplyChanges();
                        config.Update();
                        this.FaceData = faceModule.CreateOutput();
                    }
                }
            }
            return(result);
        }
Example #5
0
        private void CheckSelection()
        {
            PXCMCapture.Device.StreamProfile dprofile = GetDepthConfiguration();
            //?DepthNone.Enabled = (cprofile.imageInfo.format != 0 || irprofile.imageInfo.format != 0);

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

            PXCMCapture.DeviceInfo dinfo2 = GetCheckedDevice();
            if (session.CreateImpl <PXCMCapture>(desc, out capture) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                using (capture)
                {
                    using (PXCMCapture.Device device = capture.CreateDevice(dinfo2.didx))
                    {
                        if (device != null)
                        {
                            PXCMCapture.Device.StreamProfileSet profile = new PXCMCapture.Device.StreamProfileSet();
                            PXCMCapture.Device.StreamProfileSet test    = new PXCMCapture.Device.StreamProfileSet();

                            /* Loop over all stream types and profiles and enable only compatible in menu */
                            for (int s = 0; s < PXCMCapture.STREAM_LIMIT; s++)
                            {
                                PXCMCapture.StreamType st = PXCMCapture.StreamTypeFromIndex(s);
                                if (((int)dinfo2.streams & (int)PXCMCapture.StreamType.STREAM_TYPE_COLOR) != 0)
                                {
                                    //?test[PXCMCapture.StreamType.STREAM_TYPE_COLOR] = cprofile;
                                    test[PXCMCapture.StreamType.STREAM_TYPE_DEPTH] = dprofile;
                                    //?test[PXCMCapture.StreamType.STREAM_TYPE_IR] = irprofile;
                                    int num = device.QueryStreamProfileSetNum(st);
                                    for (int p = 0; p < num; p++)
                                    {
                                        if (device.QueryStreamProfileSet(st, p, out profile) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                                        {
                                            break;
                                        }
                                        PXCMCapture.Device.StreamProfile sprofile = profile[st];
                                        ToolStripMenuItem sm1 = GetMenuItem(sprofile);
                                        if (sm1 != null)
                                        {
                                            test[st]    = sprofile;
                                            sm1.Enabled = device.IsStreamProfileSetValid(test);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #6
0
        private void Device_Item_Click(object sender, EventArgs e)
        {
            foreach (ToolStripMenuItem e1 in DeviceMenu.DropDownItems)
            {
                e1.Checked = (sender == e1);
            }
            PopulateColorMenus(sender as ToolStripMenuItem);
            PopulateDepthMenus(sender as ToolStripMenuItem);

            PXCMSession.ImplDesc   desc     = new PXCMSession.ImplDesc();
            PXCMCapture.DeviceInfo dev_info = devices[(sender as ToolStripMenuItem)];
        }
Example #7
0
 /**
  *  @brief	The functinon adds the specified device information to the DeviceInfo filter list.
  *  @param[in] name		The optional device friendly name.
  *  @param[in] did		The optional device symbolic name.
  *  @param[in] didx		The optional device index.
  */
 public void FilterByDeviceInfo(String name, String did, Int32 didx)
 {
     PXCMCapture.DeviceInfo dinfo = new PXCMCapture.DeviceInfo();
     if (name != null)
     {
         dinfo.name = name;
     }
     if (did != null)
     {
         dinfo.did = did;
     }
     dinfo.didx = didx;
     FilterByDeviceInfo(dinfo);
 }
Example #8
0
        private void PopulateDepthMenu(ToolStripMenuItem device_item)
        {
            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];
            current_device_iuid = desc.iuid;
            desc.cuids[0]       = PXCMCapture.CUID;

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

            PXCMCapture.DeviceInfo dinfo2 = GetCheckedDevice();
            if (session.CreateImpl <PXCMCapture>(desc, out capture) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                using (capture)
                {
                    using (PXCMCapture.Device device = capture.CreateDevice(dinfo2.didx))
                    {
                        if (device != null)
                        {
                            PXCMCapture.Device.StreamProfileSet profile = new PXCMCapture.Device.StreamProfileSet();
                            if (((int)dinfo2.streams & (int)PXCMCapture.StreamType.STREAM_TYPE_DEPTH) != 0)
                            {
                                int num = device.QueryStreamProfileSetNum(PXCMCapture.StreamType.STREAM_TYPE_DEPTH);
                                for (int p = 0; p < num; 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];
                                    ToolStripMenuItem sm1 = new ToolStripMenuItem(ProfileToString(sprofile), null, new EventHandler(Depth_Item_Click));
                                    profiles[sm1] = sprofile;
                                    DepthMenu.DropDownItems.Add(sm1);
                                }
                            }
                        }
                    }
                }
            }
            DepthNone           = new ToolStripMenuItem("None", null, new EventHandler(Depth_Item_Click));
            profiles[DepthNone] = new PXCMCapture.Device.StreamProfile();
            DepthMenu.DropDownItems.Add(DepthNone);
            (DepthMenu.DropDownItems[0] as ToolStripMenuItem).Checked = true;

            CheckSelection();
        }
Example #9
0
 public PXCMCapture.DeviceInfo GetCheckedDevice()
 {
     foreach (ToolStripMenuItem e in DeviceMenu.DropDownItems)
     {
         if (devices.ContainsKey(e))
         {
             if (e.Checked)
             {
                 PXCMCapture.DeviceInfo dev_info = devices[e];
                 userFacingCamera = (dev_info.orientation != PXCMCapture.DeviceOrientation.DEVICE_ORIENTATION_REAR_FACING);
                 if (!userFacingCamera && Landmarks.Checked)
                 {
                     Landmarks.Checked = false;
                 }
                 // Landmarks are only supported when using front facing cameras in this release
                 try { EnableLandmarks(userFacingCamera && Solid.Enabled); }
                 catch (Exception) { }
                 return(devices[e]);
             }
         }
     }
     return(new PXCMCapture.DeviceInfo());
 }
Example #10
0
        public void SimplePipeline()
        {
            bool             sts = true;
            PXCMSenseManager pp  = form.session.CreateSenseManager();

            if (pp == null)
            {
                throw new Exception("Failed to create sense manager");
            }
            disconnected = false;

            /* Set Source & Profile Index */
            PXCMCapture.DeviceInfo info = null;
            if (this.form.GetRecordState())
            {
                pp.captureManager.SetFileName(this.form.GetFileName(), true);
                form.PopulateDeviceMenu();
                if (this.form.Devices.TryGetValue(this.form.GetCheckedDevice(), out info))
                {
                    pp.captureManager.FilterByDeviceInfo(info);
                }
            }
            else if (this.form.GetPlaybackState())
            {
                pp.captureManager.SetFileName(this.form.GetFileName(), false);
            }
            else
            {
                if (this.form.Devices.TryGetValue(this.form.GetCheckedDevice(), out info))
                {
                    pp.captureManager.FilterByDeviceInfo(info);
                }
            }

            /* Set Module */
            pp.EnableEmotion(form.GetCheckedModule());

            /* Initialization */
            form.UpdateStatus("Init Started");

            PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler()
            {
                //GZ onModuleQueryProfile = OnModuleQueryProfile
            };

            if (pp.Init(handler) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                form.UpdateStatus("Streaming");
                this.timer = new FPSTimer(form);
                PXCMCaptureManager captureManager = pp.QueryCaptureManager();
                if (captureManager == null)
                {
                    throw new Exception("Failed to query capture manager");
                }
                PXCMCapture.Device device = captureManager.QueryDevice();

                if (device != null && !this.form.GetPlaybackState())
                {
                    device.SetDepthConfidenceThreshold(7);
                }
                //GZ device.SetProperty(PXCMCapture.Device.Property.PROPERTY_DEPTH_CONFIDENCE_THRESHOLD, 7);

                while (!form.stop)
                {
                    if (pp.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        break;
                    }
                    if (!DisplayDeviceConnection(!pp.IsConnected()))
                    {
                        /* Display Results */
                        PXCMEmotion ft = pp.QueryEmotion();

                        //GZ DisplayPicture(pp.QueryImageByType(PXCMImage.ImageType.IMAGE_TYPE_COLOR));
                        PXCMCapture.Sample sample = pp.QuerySample();

                        /* Start of modified code */
                        // Grab the first BMP in the folder, assume there is one for now
                        string   folder = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
                        string[] files  = Directory.GetFiles(folder, "*.bmp");
                        Bitmap   bitmap = new Bitmap(files[0]);
                        // Create a PXCMImage from the BMP
                        PXCMImage.ImageInfo iinfo = new PXCMImage.ImageInfo();
                        iinfo.width  = bitmap.Width;
                        iinfo.height = bitmap.Height;
                        iinfo.format = PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32;
                        PXCMImage           imageTEST = form.session.CreateImage(iinfo);
                        PXCMImage.ImageData idata;
                        imageTEST.AcquireAccess(PXCMImage.Access.ACCESS_WRITE, out idata);
                        BitmapData bdata = new BitmapData();
                        bdata.Scan0       = idata.planes[0];
                        bdata.Stride      = idata.pitches[0];
                        bdata.PixelFormat = PixelFormat.Format32bppRgb;
                        bdata.Width       = bitmap.Width;
                        bdata.Height      = bitmap.Height;
                        BitmapData bdata2 = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                                                            ImageLockMode.ReadOnly | ImageLockMode.UserInputBuffer,
                                                            PixelFormat.Format32bppRgb, bdata);
                        bitmap.UnlockBits(bdata2);
                        imageTEST.ReleaseAccess(idata);
                        // Save the BMP
                        Bitmap savebmp = idata.ToBitmap(0, bitmap.Width, bitmap.Height);
                        //savebmp.Save(@"O:\unix\projects\instr\production5\research\Francis\result.bmp");

                        // Put my own PXCMImage into the sample
                        PXCMCapture.Sample smp = new PXCMCapture.Sample();
                        smp.color = imageTEST;

                        // Get the video module from the emotion instance
                        PXCMVideoModule module = ft.QueryInstance <PXCMVideoModule>();
                        PXCMSyncPoint   sp;
                        // Process the sample
                        module.ProcessImageAsync(smp, out sp);
                        // Synchronize then get emotion data etc.
                        sp.Synchronize();
                        /* End of modified code */

                        DisplayPicture(sample.color);

                        DisplayLocation(ft);

                        form.UpdatePanel();
                    }
                    pp.ReleaseFrame();
                }
            }
            else
            {
                form.UpdateStatus("Init Failed");
                sts = false;
            }

            pp.Close();
            pp.Dispose();
            if (sts)
            {
                form.UpdateStatus("Stopped");
            }
        }
Example #11
0
        private void PopulateDepthMenus(ToolStripMenuItem device_item)
        {
            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;

            DepthMenu.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;
            }

            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();;
                    PXCMCapture.Device.StreamProfile    color_profile = GetColorConfiguration();
                    if (((int)dinfo2.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];

                            bool bFound = false;
                            int  i      = 0;
                            PXCMVideoModule.DataDesc inputs;
                            while ((m.QueryCaptureProfile(i++, out inputs) >= pxcmStatus.PXCM_STATUS_NO_ERROR))
                            {
                                if ((sprofile.imageInfo.height == inputs.streams.depth.sizeMax.height) &&
                                    (sprofile.imageInfo.width == inputs.streams.depth.sizeMax.width) &&
                                    (sprofile.frameRate.max == inputs.streams.depth.frameRate.max) &&
                                    (color_profile.frameRate.max == inputs.streams.depth.frameRate.max))
                                {
                                    bFound = true;
                                }
                            }
                            if (bFound)
                            {
                                if (sprofile.options != (PXCMCapture.Device.StreamOption) 0x20000) // do not show Depth Confidence
                                {
                                    ToolStripMenuItem sm1 = new ToolStripMenuItem(ProfileToString(sprofile), null, new EventHandler(Depth_Item_Click));
                                    profiles[sm1] = sprofile;
                                    DepthMenu.DropDownItems.Add(sm1);
                                }
                            }
                        }
                    }
                    device.Dispose();
                }
                capture.Dispose();
            }
            m.Dispose();
            pp.Dispose();

            if (DepthMenu.DropDownItems.Count > 0)
            {
                (DepthMenu.DropDownItems[DepthMenu.DropDownItems.Count - 1] as ToolStripMenuItem).Checked = true;
            }
        }
Example #12
0
        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;
            }
        }
Example #13
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="deviceInfo">The device info.</param>
 public DeviceDescriptionModel(PXCMCapture.DeviceInfo deviceInfo)
 {
     this.deviceInfo = deviceInfo;
 }
Example #14
0
 /**
  *  @brief	The functinon adds the specified DeviceInfo to the DeviceInfo filter list.
  *  @param[in] dinfo	The DeviceInfo structure to be added to the filter list, or NULL to clean up the filter list.
  */
 public void FilterByDeviceInfo(PXCMCapture.DeviceInfo dinfo)
 {
     PXCMCaptureManager_FilterByDeviceInfo(instance, dinfo);
 }
Example #15
0
 private static bool IsProfileSupported(PXCMCapture.Device.StreamProfileSet profileSet, PXCMCapture.DeviceInfo dinfo)
 {
     return
         ((profileSet.color.frameRate.min < 30) ||
          (dinfo != null && dinfo.model == PXCMCapture.DeviceModel.DEVICE_MODEL_DS4 &&
           (profileSet.color.imageInfo.width == 1920 || profileSet.color.frameRate.min > 30 || profileSet.color.imageInfo.format == PXCMImage.PixelFormat.PIXEL_FORMAT_YUY2)) ||
          (profileSet.color.options == PXCMCapture.Device.StreamOption.STREAM_OPTION_UNRECTIFIED));
 }
Example #16
0
        private pxcmStatus InitializeFace()
        {
            pxcmStatus result = pxcmStatus.PXCM_STATUS_NO_ERROR;

            // 顔検出を有効にする
            result = this.senseManager.EnableFace();
            if (result < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                MessageBox.Show("Face Stream Enabled Error.");
            }
            else
            {
                // 追加:表情検出を有効にする
                result = this.senseManager.EnableEmotion();
                if (result < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    MessageBox.Show("Face Stream Enabled Error.");
                }
                else
                {
                    //顔検出器を生成する
                    var faceModule = this.senseManager.QueryFace();

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

                    // パイプラインを初期化する
                    result = this.senseManager.Init();
                    if (result < pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        MessageBox.Show("Initialize Error.");
                    }
                    else
                    {
                        // ミラー表示にする
                        this.senseManager.QueryCaptureManager().QueryDevice().SetMirrorMode(
                            PXCMCapture.Device.MirrorMode.MIRROR_MODE_HORIZONTAL);

                        // 顔検出器の設定
                        var device = this.senseManager.QueryCaptureManager().QueryDevice();
                        PXCMCapture.DeviceInfo info = null;
                        device.QueryDeviceInfo(out info);
                        if (info.model == PXCMCapture.DeviceModel.DEVICE_MODEL_IVCAM)
                        {
                            device.SetDepthConfidenceThreshold(1);
                            device.SetIVCAMFilterOption(6);
                            device.SetIVCAMMotionRangeTradeOff(21);
                        }

                        config.detection.isEnabled = true;
                        //ここからは表出情報(Expression)の設定を参照してください
                        config.QueryExpressions().Enable();
                        config.QueryExpressions().EnableAllExpressions();
                        config.QueryExpressions().properties.maxTrackedFaces = EXPRESSION_MAXFACES;
                        config.ApplyChanges();
                        config.Update();
                        this.faceData = faceModule.CreateOutput();
                    }
                }
            }
            return(result);
        }
Example #17
0
        public void ShowStream()
        {
            bool sts = true;

            /* Create an instance of the PXCSenseManager interface */
            using (PXCMSenseManager pp = PXCMSenseManager.CreateInstance())
            {
                if (pp == null)
                {
                    form.UpdateStatus("Failed to create an SDK pipeline object");
                    return;
                }

                /* Set Input Source */
                PXCMCapture.DeviceInfo dinfo2 = form.GetCheckedDevice();
                if (form.IsModeLive() || form.IsModeRecorded())
                {
                    pp.captureManager.FilterByDeviceInfo(dinfo2);
                }

                /* Set Depth Resolution */
                PXCMCapture.Device.StreamProfile dinfo = form.GetDepthConfiguration();
                if (dinfo.imageInfo.format != 0)
                {
                    Single dfps = dinfo.frameRate.max;
                    pp.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, dinfo.imageInfo.width, dinfo.imageInfo.height, dfps);
                    //: enable also rgb and ir streams:
                    pp.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, dinfo.imageInfo.width, dinfo.imageInfo.height, dfps);
                    pp.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_IR, dinfo.imageInfo.width, dinfo.imageInfo.height, dfps);
                }

                /* Initialization */
                FPSTimer timer = new FPSTimer(form);
                form.UpdateStatus("Init Started");
                if (pp.Init() >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    /* Configure the camera to return a non-mirrored image */
                    pp.captureManager.device.SetMirrorMode(PXCMCapture.Device.MirrorMode.MIRROR_MODE_DISABLED);
                    appliedCameraSettings = CameraSettings.ReadFrom(pp.captureManager.device);
                    form.SetCameraSettings(appliedCameraSettings, CameraSettings.ReadPropInfo(pp.captureManager.device));

                    /* For UV Mapping & Projection only: Save certain properties */
                    using (Projection projection = new Projection(pp.session, pp.captureManager.device, dinfo.imageInfo))
                    {
                        form.UpdateStatus("Streaming");
                        int bitmap_width  = dinfo.imageInfo.width;
                        int bitmap_height = dinfo.imageInfo.height;
                        while (!form.GetStopState())
                        {
                            CameraSettings newCameraSettings = form.CameraSettings;
                            if (newCameraSettings.changed)
                            {//: apply new camera settings:
                                newCameraSettings.WriteTo(pp.captureManager.device, this.appliedCameraSettings);
                                this.appliedCameraSettings = newCameraSettings;
                            }

                            //: acquire frame:
                            if (pp.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                            {
                                break;
                            }

                            //: process frame:
                            GuiParams          guiParams = form.GetParams();
                            PXCMCapture.Sample sample    = pp.QuerySample();
                            projection.SearchForObject(sample, guiParams.processParams);
                            pp.ReleaseFrame();

                            byte[] bitmap_data = projection.GetPixelColors();
                            form.SetPicture(bitmap_width, bitmap_height, bitmap_data);
                            form.UpdatePicture();
                            timer.Tick("Streaming.");
                        }
                    }
                }
                else
                {
                    form.UpdateStatus("Init Failed");
                    sts = false;
                }

                pp.Close();
            }
            if (sts)
            {
                form.UpdateStatus("Stopped");
            }
        }
Example #18
0
        private void PopulateColorDepthMenus(ToolStripMenuItem device_item)
        {
            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];
            current_device_iuid = desc.iuid;
            desc.cuids[0]       = PXCMCapture.CUID;

            profiles.Clear();
            foreach (ToolStripMenuItem menu in streamMenus)
            {
                if (menu != null)
                {
                    menu.DropDownItems.Clear();
                }
            }

            PXCMCapture capture;

            PXCMCapture.DeviceInfo dinfo2 = GetCheckedDevice();
            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();

                    for (int s = 0; s < PXCMCapture.STREAM_LIMIT; s++)
                    {
                        PXCMCapture.StreamType st = PXCMCapture.StreamTypeFromIndex(s);
                        if (((int)dinfo2.streams & (int)st) != 0 && streamMenus[s] != null)
                        {
                            streamMenus[s].Visible   = true;
                            streamButtons[s].Visible = true;
                            streamPanels[s].Visible  = true;

                            int num = device.QueryStreamProfileSetNum(st);
                            for (int p = 0; p < num; p++)
                            {
                                if (device.QueryStreamProfileSet(st, p, out profile) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                                {
                                    break;
                                }
                                PXCMCapture.Device.StreamProfile sprofile = profile[st];
                                ToolStripMenuItem sm1 = new ToolStripMenuItem(ProfileToString(sprofile), null, new EventHandler(Stream_Item_Click));
                                profiles[sm1] = sprofile;
                                streamMenus[s].DropDownItems.Add(sm1);

                                if (sm1.Text.Contains(default_config[s]))
                                {
                                    default_menu[s] = p;
                                    Debug.WriteLine(s + " : " + p + " : " + ProfileToString(sprofile));
                                }
                            }
                        }
                        else if (((int)dinfo2.streams & (int)st) == 0 && streamMenus[s] != null)
                        {
                            streamMenus[s].Visible   = false;
                            streamButtons[s].Visible = false;
                            streamPanels[s].Visible  = false;
                        }
                    }

                    device.Dispose();
                }
                capture.Dispose();
            }
            for (int i = 0; i < PXCMCapture.STREAM_LIMIT; i++)
            {
                ToolStripMenuItem menu = streamMenus[i];
                if (menu != null)
                {
                    streamNone[i]           = new ToolStripMenuItem("None", null, new EventHandler(Stream_Item_Click));
                    profiles[streamNone[i]] = new PXCMCapture.Device.StreamProfile();
                    menu.DropDownItems.Add(streamNone[i]);
                    if (default_menu[i] != 0)
                    {
                        (menu.DropDownItems[default_menu[i]] as ToolStripMenuItem).Checked = true;
                    }
                    else
                    {
                        streamNone[i].Checked = true;
                    }
                }
            }

            CheckSelection();
        }
Example #19
0
        private void CheckSelection()
        {
            if (!ModePlayback.Checked)
            {
                PXCMCapture.Device.StreamProfileSet allProfile = new PXCMCapture.Device.StreamProfileSet();
                for (int s = 0; s < PXCMCapture.STREAM_LIMIT; s++)
                {
                    PXCMCapture.StreamType st = PXCMCapture.StreamTypeFromIndex(s);
                    allProfile[st] = GetStreamConfiguration(st);
                }

                PXCMSession.ImplDesc desc = new PXCMSession.ImplDesc();
                desc.group    = PXCMSession.ImplGroup.IMPL_GROUP_SENSOR;
                desc.subgroup = PXCMSession.ImplSubgroup.IMPL_SUBGROUP_VIDEO_CAPTURE;
                desc.iuid     = current_device_iuid;
                desc.cuids[0] = PXCMCapture.CUID;
                PXCMCapture            capture;
                PXCMCapture.DeviceInfo dinfo2 = GetCheckedDevice();
                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();
                        PXCMCapture.Device.StreamProfileSet test    = new PXCMCapture.Device.StreamProfileSet();

                        /* Loop over all stream types and profiles and enable only compatible in menu */
                        for (int s = 0; s < PXCMCapture.STREAM_LIMIT; s++)
                        {
                            PXCMCapture.StreamType st = PXCMCapture.StreamTypeFromIndex(s);
                            if (((int)dinfo2.streams & (int)st) != 0)
                            {
                                for (int s1 = 0; s1 < PXCMCapture.STREAM_LIMIT; s1++)
                                {
                                    test[PXCMCapture.StreamTypeFromIndex(s1)] = allProfile[PXCMCapture.StreamTypeFromIndex(s1)];
                                }
                                int num = device.QueryStreamProfileSetNum(st);
                                for (int p = 0; p < num; p++)
                                {
                                    if (device.QueryStreamProfileSet(st, p, out profile) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                                    {
                                        break;
                                    }
                                    PXCMCapture.Device.StreamProfile sprofile = profile[st];
                                    ToolStripMenuItem sm1 = GetMenuItem(st, sprofile);
                                    if (sm1 != null)
                                    {
                                        test[st]    = sprofile;
                                        sm1.Enabled = device.IsStreamProfileSetValid(test);
                                    }
                                }
                            }
                        }
                        Start.Enabled = device.IsStreamProfileSetValid(allProfile);
                        device.Dispose();
                    }
                    capture.Dispose();
                }
            }

            int sumEnabled = 0;

            for (int s = 0; s < PXCMCapture.STREAM_LIMIT; s++)
            {
                if (streamButtons[s] != null && streamNone[s] != null)
                {
                    streamButtons[s].Enabled = !streamNone[s].Checked;
                    sumEnabled += streamButtons[s].Enabled?1:0;
                }
            }
            PIP.Enabled    = (sumEnabled >= 2);
            Mirror.Enabled = !ModePlayback.Checked;

            PXCMCapture.StreamType selectedStream = GetSelectedStream();
            if (selectedStream != PXCMCapture.StreamType.STREAM_TYPE_ANY && !streamButtons[PXCMCapture.StreamTypeToIndex(selectedStream)].Enabled)
            {
                PXCMCapture.StreamType st = GetUnselectedStream();
                streamButtons[PXCMCapture.StreamTypeToIndex(st)].Checked = true;
                streaming.ColorPanel = st;
            }

            //if (PIP.Enabled && streaming.DepthPanel == PXCMCapture.StreamType.STREAM_TYPE_ANY)
            //{
            //    streaming.DepthPanel = GetUnselectedStream();
            //}
        }
        public void StreamColorDepth(String scanType) /* Stream Color and Depth Synchronously or Asynchronously */
        {
            bool sts = true;

            PXCM3DScan.Configuration scan_config = new PXCM3DScan.Configuration();
            String statusString;

            /* Create an instance of the PXCSenseManager interface */
            PXCMSenseManager pp = PXCMSenseManager.CreateInstance();

            if (pp == null)
            {
                form.UpdateStatus("Failed to create sense manager");
                return;
            }
            if (pp.captureManager == null)
            {
                form.UpdateStatus("Capture manager does not exist");
                return;
            }
            if (!form.IsModeLive())
            {
                pp.captureManager.SetFileName(form.GetFileName(), form.IsModeRecord());
            }

            /* Set Input Source */
            PXCMCapture.DeviceInfo dinfo2 = form.GetCheckedDevice();
            if (form.IsModeLive() || form.IsModeRecord())
            {
                pp.captureManager.FilterByDeviceInfo(dinfo2);
            }

            if (form.IsModeRecord())
            {
                // Delay recording frames until the scan starts
                pp.captureManager.SetPause(true);
            }
            else if (!form.IsModeLive())
            {
                // Disable real-time mode if we are playing back a file
                // to ensure that frames are not skipped.
                pp.captureManager.SetRealtime(false);
            }

            /* Set Color & Depth Resolution */
            PXCMCapture.Device.StreamProfile cinfo = form.GetColorConfiguration();
            if (cinfo.imageInfo.format != 0)
            {
                Single cfps = cinfo.frameRate.max;
                pp.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, cinfo.imageInfo.width, cinfo.imageInfo.height, cfps);
            }

            PXCMCapture.Device.StreamProfile dinfo = form.GetDepthConfiguration();
            if (dinfo.imageInfo.format != 0)
            {
                Single dfps = dinfo.frameRate.max;
                pp.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, dinfo.imageInfo.width, dinfo.imageInfo.height, dfps);
            }

            /* Initialization */
            FPSTimer timer = new FPSTimer(form);

            if (form.IsModeLive())
            {
                form.UpdateStatus("Initializing...");
            }
            /* Enable the 3D Scan video module */
            pxcmStatus result = pp.Enable3DScan();

            if (result != pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                pp.Close();
                pp.Dispose();
                form.UpdateStatus("Enable3DScan() returned " + result);
                return;
            }

            /* Initialize the camera system */
            result = pp.Init();
            form.UpdateStatus("");
            device = pp.captureManager.device;
            if (result >= pxcmStatus.PXCM_STATUS_NO_ERROR && device != null)
            {
                bool bAutoExpAndWBChanged     = false;
                bool bAutoExposureEnabled     = true;
                bool bAutoWhiteBalanceEnabled = true;

                /* Setup the scanning configuration */
                if (scanType == "Object")
                {
                    scan_config.mode = PXCM3DScan.ScanningMode.OBJECT_ON_PLANAR_SURFACE_DETECTION;
                }
                else if (scanType == "Face")
                {
                    scan_config.mode = PXCM3DScan.ScanningMode.FACE;
                }
                else if (scanType == "Body")
                {
                    scan_config.mode = PXCM3DScan.ScanningMode.BODY;
                }
                else if (scanType == "Head")
                {
                    scan_config.mode = PXCM3DScan.ScanningMode.HEAD;
                }
                else if (scanType == "Full")
                {
                    scan_config.mode = PXCM3DScan.ScanningMode.VARIABLE;
                }

                /* Select the Targeting Options */
                scan_config.options = PXCM3DScan.ReconstructionOption.NONE;
                if (form.isSolidificationSelected())
                {
                    scan_config.options
                        |= (PXCM3DScan.ReconstructionOption.SOLIDIFICATION);
                }
                if (form.isTextureSelected())
                {
                    scan_config.options
                        |= (PXCM3DScan.ReconstructionOption.TEXTURE);
                }
                if (form.isLandmarksSelected())
                {
                    scan_config.options
                        |= (PXCM3DScan.ReconstructionOption.LANDMARKS);
                }
                //scan_config.useMarker = form.isUseMarkerChecked();

                scan_config.flopPreviewImage = form.isFlopPreviewImageSelected();

                /* Try to initialize the scanning system */
                PXCM3DScan scan = pp.Query3DScan();
                sts = false;
                if (scan == null)
                {
                    form.UpdateStatus("3DScan module not found.");
                }
                else
                {
                    result = scan.SetConfiguration(scan_config);
                    if (result < pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        scan.Dispose();

                        // Show the configuration related error code
                        switch (result)
                        {
                        case pxcmStatus.PXCM_STATUS_FEATURE_UNSUPPORTED:
                            form.UpdateStatus("Configuration not supported.");
                            break;

                        case pxcmStatus.PXCM_STATUS_ITEM_UNAVAILABLE:
                            form.UpdateStatus("Face module not found.");
                            break;

                        default:
                            form.UpdateStatus("SetConfiguration returned an error.");
                            break;
                        }
                    }
                    else
                    {
                        sts = true;
                    }
                }

                // Conditionally finish the initialization and enter the main loop
                if (sts == true)
                {
                    // Subscribe to recieve range and tracking alerts
                    scan.Subscribe(OnAlert);

                    Projection projection = new Projection(
                        pp.session, device, dinfo.imageInfo);

                    Boolean bScanning        = false;
                    Boolean bPlaybackStarted = false;
                    form.Invoke(new Action(() => form.SetButtonState(sample3dscan.cs.MainForm.ButtonState.Ce_SSd)));

                    while (form.reconstruct_requested || !form.GetStopState())
                    {
                        if (form.GetScanRequested()) /* one time latch */
                        {
                            form.Invoke(new Action(() => form.SetScanRequested(false)));

                            // Delay recording frames until the start of the scan is requested
                            if (form.IsModeRecord())
                            {
                                pp.captureManager.SetPause(false);
                            }

                            // If the max tri/vert controls are enabled,
                            // use the set values. Otherwise, disabled decimation
                            // by setting the values to zero.

                            /*
                             * scan_config.maxTriangles = form.getMaxTrianglesEnabledChecked()
                             *  ? form.getMaxTriangles() : 0;
                             * scan_config.maxVertices = form.getMaxVerticesEnabledChecked()
                             *  ? form.getMaxVertices() : 0;
                             */
                            // Request that the scan starts as soon as possible
                            scan_config.startScan = true;
                            scan.SetConfiguration(scan_config);

                            /* Update the status bar to help users understand what the detector is looking for */
                            if (form.IsModeLive())
                            {
                                if (scan_config.mode == PXCM3DScan.ScanningMode.OBJECT_ON_PLANAR_SURFACE_DETECTION)
                                {
                                    form.UpdateStatus("Object not detected. Place object on flat surface in center of view.");
                                }
                            }
                        }
                        else if (form.reconstruct_requested)
                        {
                            sts = SaveMesh(scan);
                        }

                        /* Get preview image from the 3D Scan video module */
                        if (!form.GetStopState())
                        {
                            /* Wait until a frame is ready: Synchronized or Asynchronous */
                            if (pp.AcquireFrame() < pxcmStatus.PXCM_STATUS_NO_ERROR)
                            {
                                projection.Dispose();
                                if (!form.IsModeLive())
                                {
                                    form.Invoke(new Action(() => form.EndScan()));
                                    sts = SaveMesh(scan);
                                }
                                break;
                            }

                            /* Get preview image from the 3D Scan video module */
                            PXCMImage preview_image = scan.AcquirePreviewImage();
                            pp.ReleaseFrame();

                            /* Display Image and Status */
                            if (preview_image != null)
                            {
                                form.SetBitmap(preview_image);

                                if (scan.IsScanning())
                                {
                                    statusString = "Scanning";
                                    timer.Tick(statusString + " ");
                                    if (bScanning == false) // Lazy initializer
                                    {
                                        bScanning = true;   // One way latch

                                        // Once the scanning process starts, we want to enable the Reconstruct button
                                        form.Invoke(new Action(() => form.SetButtonState(sample3dscan.cs.MainForm.ButtonState.Ce_ESe)));

                                        // Object, head and body scanning with a rear facing camera involves walking
                                        // around the target, which effectivly exposes the camera to the full
                                        // environment, similar to a panorama. To avoid undesirable color
                                        // inconsistencies (realted to the response of the auto-exposure/wb changes),
                                        // it usually works best to disable them.
                                        // Note that these property changes are restored (below).
                                        if (device.deviceInfo.orientation
                                            == PXCMCapture.DeviceOrientation.DEVICE_ORIENTATION_REAR_FACING &&
                                            scan_config.mode != PXCM3DScan.ScanningMode.FACE &&
                                            form.IsModeLive())
                                        {
                                            bAutoExpAndWBChanged = true;
                                            bAutoExposureEnabled = device.QueryColorAutoExposure();
                                            device.SetColorAutoExposure(false);
                                            bAutoWhiteBalanceEnabled = device.QueryColorAutoWhiteBalance();
                                            device.SetColorAutoWhiteBalance(false);
                                        }
                                    }
                                }
                                else
                                {
                                    if (!form.IsModeLive() && !form.IsModeRecord()) // In playback mode, automatically request the scan
                                    {
                                        if (bPlaybackStarted == false)              // Lazy initializer
                                        {
                                            bPlaybackStarted    = true;             // One way latch
                                            form.scan_requested = true;
                                            form.Invoke(new Action(() => form.StartScanning(false)));
                                            form.Invoke(new Action(() => form.SetButtonState(sample3dscan.cs.MainForm.ButtonState.Ce_ESe)));
                                        }
                                    }
                                    else
                                    {
                                        if (!form.GetStopState())
                                        {
                                            if (isScanReady(form.landmarksChecked()))
                                            {
                                                form.Invoke(new Action(() => form.EnableReconstruction(true)));
                                            }
                                            else
                                            {
                                                form.Invoke(new Action(() => form.EnableReconstruction(false)));
                                            }
                                        }
                                    }
                                }
                                preview_image.Dispose();
                            }
                        }
                    }
                    projection.Dispose();
                    scan.Dispose();
                }
                // Restore the default camera properties
                if (bAutoExpAndWBChanged)
                {
                    device.SetColorAutoExposure(bAutoExposureEnabled);
                    device.SetColorAutoWhiteBalance(bAutoWhiteBalanceEnabled);
                }

                device.Dispose();
                device = null;
            }
            else
            {
                try { form.UpdateStatus(result + ""); }
                catch { }
                sts = false;
            }

            if (sts)
            {
                try { form.UpdateStatus(""); }
                catch { }
            }

            pp.Close();
            pp.Dispose();

            try { form.Invoke(new Action(() => form.ResetStop())); }
            catch { }
        }
Example #21
0
 internal static extern void PXCMCaptureManager_FilterByDeviceInfo(IntPtr cutil, PXCMCapture.DeviceInfo dinfo);
Example #22
0
        private void ScanForProfiles(int deviceIndex)
        {
            PXCMSession.ImplDesc desc = new PXCMSession.ImplDesc();
            desc.group    = PXCMSession.ImplGroup.IMPL_GROUP_SENSOR;
            desc.subgroup = PXCMSession.ImplSubgroup.IMPL_SUBGROUP_VIDEO_CAPTURE;
            desc.iuid     = devicesUIDs[deviceIndex];
            int current_device_iuid = desc.iuid;

            desc.cuids[0] = PXCMCapture.CUID;

            profiles.Clear();

            List <string> colorStrings = new List <string>();
            List <string> depthStrings = new List <string>();
            PXCMCapture   capture;

            PXCMCapture.DeviceInfo dinfo2 = deviceInfo[deviceIndex];
            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();

                    for (int s = 0; s < PXCMCapture.STREAM_LIMIT; s++)
                    {
                        PXCMCapture.StreamType st = PXCMCapture.StreamTypeFromIndex(s);
                        if (((int)dinfo2.streams & (int)st) != 0)
                        {
                            int num = device.QueryStreamProfileSetNum(st);
                            for (int p = 0; p < num; p++)
                            {
                                if (device.QueryStreamProfileSet(st, p, out profile) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                                {
                                    break;
                                }
                                PXCMCapture.Device.StreamProfile sprofile = profile[st];
                                string profileText = ProfileToString(sprofile);
                                try
                                {
                                    profiles.Add(profileText, sprofile);
                                }
                                catch
                                {
                                }
                                switch (st)
                                {
                                case PXCMCapture.StreamType.STREAM_TYPE_COLOR:
                                    colorStrings.Add(profileText);
                                    break;

                                case PXCMCapture.StreamType.STREAM_TYPE_DEPTH:
                                    depthStrings.Add(profileText);
                                    break;
                                }
                            }
                        }
                    }

                    device.Dispose();
                }
                capture.Dispose();
            }
            colorProfiles = new ListParamDesc <string>(colorStrings)
            {
                Description  = "Color Profiles",
                ReadableWhen = ParamDesc.ConnectionStates.Connected,
            };
            depthProfiles = new ListParamDesc <string>(depthStrings)
            {
                Description  = "Depth Profiles",
                ReadableWhen = ParamDesc.ConnectionStates.Connected,
            };
        }
Example #23
0
        public void SimplePipeline()
        {
            bool             sts = true;
            PXCMSenseManager pp  = form.session.CreateSenseManager();

            if (pp == null)
            {
                throw new Exception("Failed to create sense manager");
            }
            disconnected = false;

            /* Set Source & Profile Index */
            PXCMCapture.DeviceInfo info = null;
            if (this.form.GetRecordState())
            {
                pp.captureManager.SetFileName(this.form.GetFileName(), true);
                form.PopulateDeviceMenu();
                if (this.form.Devices.TryGetValue(this.form.GetCheckedDevice(), out info))
                {
                    pp.captureManager.FilterByDeviceInfo(info);
                }
            }
            else if (this.form.GetPlaybackState())
            {
                pp.captureManager.SetFileName(this.form.GetFileName(), false);
            }
            else
            {
                if (this.form.Devices.TryGetValue(this.form.GetCheckedDevice(), out info))
                {
                    pp.captureManager.FilterByDeviceInfo(info);
                }
            }

            /* Set Module */
            pp.EnableEmotion(form.GetCheckedModule());

            /* Initialization */
            form.UpdateStatus("Init Started");

            PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler()
            {
                //GZ onModuleQueryProfile = OnModuleQueryProfile
            };

            if (pp.Init(handler) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                form.UpdateStatus("Streaming");
                this.timer = new FPSTimer(form);
                PXCMCaptureManager captureManager = pp.QueryCaptureManager();
                if (captureManager == null)
                {
                    throw new Exception("Failed to query capture manager");
                }
                PXCMCapture.Device device = captureManager.QueryDevice();

                if (device != null && !this.form.GetPlaybackState())
                {
                    device.SetDepthConfidenceThreshold(7);
                }
                //GZ device.SetProperty(PXCMCapture.Device.Property.PROPERTY_DEPTH_CONFIDENCE_THRESHOLD, 7);

                while (!form.stop)
                {
                    if (pp.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        break;
                    }
                    if (!DisplayDeviceConnection(!pp.IsConnected()))
                    {
                        /* Display Results */
                        PXCMEmotion ft = pp.QueryEmotion();
                        if (ft == null)
                        {
                            pp.ReleaseFrame();
                            continue;
                        }



                        //GZ DisplayPicture(pp.QueryImageByType(PXCMImage.ImageType.IMAGE_TYPE_COLOR));
                        PXCMCapture.Sample sample = pp.QueryEmotionSample();
                        if (sample == null)
                        {
                            pp.ReleaseFrame();
                            continue;
                        }

                        DisplayPicture(sample.color);

                        DisplayLocation(ft);

                        form.UpdatePanel();
                    }
                    pp.ReleaseFrame();
                }
            }
            else
            {
                form.UpdateStatus("Init Failed");
                sts = false;
            }

            pp.Close();
            pp.Dispose();
            if (sts)
            {
                form.UpdateStatus("Stopped");
            }
        }