コード例 #1
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;
            }
        }
コード例 #2
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;
            }
        }
コード例 #3
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");
            }
        }