Example #1
0
        private string ProfileToString(PXCMCapture.Device.StreamProfile pinfo)
        {
            string line = "Unknown ";

            if (Enum.IsDefined(typeof(PXCMImage.PixelFormat), pinfo.imageInfo.format))
            {
                line = pinfo.imageInfo.format.ToString().Substring(13) + " " + pinfo.imageInfo.width + "x" + pinfo.imageInfo.height + "x";
            }
            else
            {
                line += pinfo.imageInfo.width + "x" + pinfo.imageInfo.height + "x";
            }
            if (pinfo.frameRate.min != pinfo.frameRate.max)
            {
                line += (float)pinfo.frameRate.min + "-" +
                        (float)pinfo.frameRate.max;
            }
            else
            {
                float fps = (pinfo.frameRate.min != 0)?pinfo.frameRate.min:pinfo.frameRate.max;
                line += fps;
            }
            line += StreamOptionToString(pinfo.options);
            return(line);
        }
Example #2
0
        /// <summary>
        /// Device-specific implementation of Connect.
        /// Connects the camera.
        /// </summary>
        /// <remarks>This method is implicitely called by <see cref="Camera.Connect"/> inside a camera lock.</remarks>
        /// <seealso cref="Camera.Connect"/>
        protected override void ConnectImpl()
        {
            if (deviceInfo.Count == 0)
            {
                ScanForCameras();
            }

            if (deviceInfo.Count == 0)
            {
                log.Error(Name + "No device found.");
                return;
            }

            int deviceIndex = 0;

            ScanForProfiles(deviceIndex);

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

            if (pp == null)
            {
                log.Error(Name + "Failed to create an SDK pipeline object");
                return;
            }

            pp.captureManager.FilterByDeviceInfo(deviceInfo[deviceIndex]);

            //TODO: change this to work with properties
            currentColorProfile = "YUY2 1920x1080x30";
            currentDepthProfile = "DEPTH 640x480x60";
            currentIRProfile    = "Y8 640x480x60";

            PXCMCapture.Device.StreamProfileSet currentProfileSet = new PXCMCapture.Device.StreamProfileSet();
            currentProfileSet[PXCMCapture.StreamType.STREAM_TYPE_COLOR] = profiles[currentColorProfile];
            currentProfileSet[PXCMCapture.StreamType.STREAM_TYPE_DEPTH] = profiles[currentDepthProfile];
            currentProfileSet[PXCMCapture.StreamType.STREAM_TYPE_IR]    = profiles[currentIRProfile];

            /* Set Color & Depth Resolution */
            for (int s = 0; s < PXCMCapture.STREAM_LIMIT; s++)
            {
                PXCMCapture.StreamType           st   = PXCMCapture.StreamTypeFromIndex(s);
                PXCMCapture.Device.StreamProfile info = currentProfileSet[st];
                if (info.imageInfo.format != 0)
                {
                    Single fps = info.frameRate.max;
                    pp.EnableStream(st, info.imageInfo.width, info.imageInfo.height, fps);
                }
            }
            if (pp.Init() >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
            }
            else
            {
                log.Error(Name + "An error occured.");
            }
            ActivateChannel(ChannelNames.Intensity);
            ActivateChannel(ChannelNames.ZImage);
        }
Example #3
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 #4
0
 private ToolStripMenuItem GetMenuItem(PXCMCapture.Device.StreamProfile profile)
 {
     foreach (ToolStripMenuItem key1 in profiles.Keys)
     {
         PXCMCapture.Device.StreamProfile profile1 = profiles[key1];
         if (ProfileToString(profile1) == ProfileToString(profile))
         {
             return(key1);
         }
     }
     return(null);
 }
Example #5
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 #6
0
        private ToolStripMenuItem GetMenuItem(PXCMCapture.StreamType st, PXCMCapture.Device.StreamProfile profile)
        {
            ToolStripMenuItem parent = streamMenus[PXCMCapture.StreamTypeToIndex(st)];

            if (parent == null)
            {
                return(null);
            }
            foreach (ToolStripMenuItem key1 in parent.DropDownItems)
            {
                PXCMCapture.Device.StreamProfile profile1 = profiles[key1];
                if (ProfileToString(profile1) == ProfileToString(profile))
                {
                    return(key1);
                }
            }
            return(null);
        }
Example #7
0
        private string ProfileToString(PXCMCapture.Device.StreamProfile pinfo)
        {
            string line = pinfo.imageInfo.format.ToString().Substring(13) + " " + pinfo.imageInfo.width + "x" + pinfo.imageInfo.height + " ";

            if (pinfo.frameRate.min != pinfo.frameRate.max)
            {
                line += (float)pinfo.frameRate.min + "-" +
                        (float)pinfo.frameRate.max;
            }
            else
            {
                float fps = (pinfo.frameRate.min != 0) ? pinfo.frameRate.min : pinfo.frameRate.max;
                line += fps;
            }
            if (pinfo.options.HasFlag(PXCMCapture.Device.StreamOption.STREAM_OPTION_UNRECTIFIED))
            {
                line += " RAW";
            }
            return(line);
        }
Example #8
0
        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);
        }
Example #9
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();
            //}
        }
Example #10
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 #11
0
        public void StreamColorDepth() /* Stream Color and Depth Synchronously or Asynchronously */
        {
            try
            {
                bool sts = true;

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

                if (sm == null)
                {
                    SetStatus("Failed to create an SDK pipeline object");
                    return;
                }

                /* Optional: if playback or recoridng */
                if ((Playback || Record) && File != null)
                {
                    sm.captureManager.SetFileName(File, Record);
                }

                /* Optional: Set Input Source */
                if (!Playback && DeviceInfo != null)
                {
                    sm.captureManager.FilterByDeviceInfo(DeviceInfo);
                }

                /* Set Color & Depth Resolution and enable streams */
                if (StreamProfileSet != null)
                {
                    /* Optional: Filter the data based on the request */
                    sm.captureManager.FilterByStreamProfiles(StreamProfileSet);

                    /* Enable raw data streaming for specific stream types */
                    for (int s = 0; s < PXCMCapture.STREAM_LIMIT; s++)
                    {
                        PXCMCapture.StreamType           st   = PXCMCapture.StreamTypeFromIndex(s);
                        PXCMCapture.Device.StreamProfile info = StreamProfileSet[st];
                        if (info.imageInfo.format != 0)
                        {
                            /* For simple request, you can also use sm.EnableStream(...) */
                            PXCMVideoModule.DataDesc desc = new PXCMVideoModule.DataDesc();
                            desc.streams[st].frameRate.min  = desc.streams[st].frameRate.max = info.frameRate.max;
                            desc.streams[st].sizeMin.height = desc.streams[st].sizeMax.height = info.imageInfo.height;
                            desc.streams[st].sizeMin.width  = desc.streams[st].sizeMax.width = info.imageInfo.width;
                            desc.streams[st].options        = info.options;
                            sm.EnableStreams(desc);
                        }
                    }
                }

                /* Initialization */
                Timer timer = new Timer();
                timer.UpdateStatus += UpdateStatus;

                SetStatus("Init Started");
                if (sm.Init() >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    /* Reset all properties */
                    sm.captureManager.device.ResetProperties(PXCMCapture.StreamType.STREAM_TYPE_ANY);

                    /* Set mirror mode */
                    PXCMCapture.Device.MirrorMode mirror = Mirror ? PXCMCapture.Device.MirrorMode.MIRROR_MODE_HORIZONTAL : PXCMCapture.Device.MirrorMode.MIRROR_MODE_DISABLED;
                    sm.captureManager.device.SetMirrorMode(mirror);

                    SetStatus("Streaming");
                    while (!Stop)
                    {
                        /* Wait until a frame is ready: Synchronized or Asynchronous */
                        if (sm.AcquireFrame(Synced).IsError())
                        {
                            break;
                        }

                        /* Display images */
                        PXCMCapture.Sample sample = sm.QuerySample();

                        /* Render streams */
                        EventHandler <RenderFrameEventArgs> render = RenderFrame;
                        PXCMImage image = null;
                        if (ColorPanel != PXCMCapture.StreamType.STREAM_TYPE_ANY && render != null)
                        {
                            image = sample[ColorPanel];
                            render(this, new RenderFrameEventArgs(0, image));
                        }

                        if (DepthPanel != PXCMCapture.StreamType.STREAM_TYPE_ANY && render != null)
                        {
                            render(this, new RenderFrameEventArgs(1, sample[DepthPanel]));
                        }

                        if (IRPanel != PXCMCapture.StreamType.STREAM_TYPE_ANY && render != null)
                        {
                            render(this, new RenderFrameEventArgs(2, sample[IRPanel]));
                        }

                        if (IRLeftPanel != PXCMCapture.StreamType.STREAM_TYPE_ANY && render != null)
                        {
                            render(this, new RenderFrameEventArgs(3, sample[IRLeftPanel]));
                        }

                        if (IRRightPanel != PXCMCapture.StreamType.STREAM_TYPE_ANY && render != null)
                        {
                            render(this, new RenderFrameEventArgs(4, sample[IRRightPanel]));
                        }

                        /* Optional: Set Mirror State */
                        mirror = Mirror ? PXCMCapture.Device.MirrorMode.MIRROR_MODE_HORIZONTAL : PXCMCapture.Device.MirrorMode.MIRROR_MODE_DISABLED;
                        if (mirror != sm.captureManager.device.QueryMirrorMode())
                        {
                            sm.captureManager.device.SetMirrorMode(mirror);
                        }

                        /* Optional: Show performance tick */
                        if (image != null)
                        {
                            timer.Tick(PXCMImage.PixelFormatToString(image.info.format) + " " + image.info.width + "x" + image.info.height);
                        }

                        sm.ReleaseFrame();
                    }
                }
                else
                {
                    SetStatus("Init Failed");
                    sts = false;
                }

                sm.Dispose();
                if (sts)
                {
                    SetStatus("Stopped");
                }
            }
            catch (Exception e) {
                SetStatus(e.GetType().ToString());
            }
        }
        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();
        }
        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.DeviceInfo dinfo;
            PXCMSenseManager pp = PXCMSenseManager.CreateInstance();
            if (pp == null)
            {
                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.QueryCaptureManager().LocateStreams() < pxcmStatus.PXCM_STATUS_NO_ERROR)
                    throw null;
                pp.QueryCaptureManager().QueryDevice().QueryDeviceInfo(out dinfo);
            }
            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 depth menu from the file
            profiles.Clear();
            DepthMenu.DropDownItems.Clear();
            PXCMCapture.Device device = pp.QueryCaptureManager().QueryDevice(); 
            
            PXCMCapture.Device.StreamProfileSet profile = new PXCMCapture.Device.StreamProfileSet(); 
            if (((int)dinfo.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];
                    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();
            pp.Close();
            pp.Dispose();

            StatusLabel.Text = "Ok";
            return true;
        }
Example #14
0
        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.DeviceInfo dinfo;
            PXCMSenseManager       pp = PXCMSenseManager.CreateInstance();

            if (pp == null)
            {
                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.QueryCaptureManager().LocateStreams() < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    throw null;
                }
                pp.QueryCaptureManager().QueryDevice().QueryDeviceInfo(out dinfo);
            }
            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 depth menu from the file
            profiles.Clear();
            DepthMenu.DropDownItems.Clear();
            PXCMCapture.Device device = pp.QueryCaptureManager().QueryDevice();

            PXCMCapture.Device.StreamProfileSet profile = new PXCMCapture.Device.StreamProfileSet();
            if (((int)dinfo.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];
                    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();
            pp.Close();
            pp.Dispose();

            StatusLabel.Text = "Ok";
            return(true);
        }
Example #15
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 #16
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 #17
0
        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.DeviceInfo dinfo;
            PXCMSenseManager       pp = PXCMSenseManager.CreateInstance();

            if (pp == null)
            {
                SetStatus("Init Failed");
                return(false);
            }
            try
            {
                if (session.QueryImpl(desc, 0, out desc1) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    throw null;
                }
                if (pp.captureManager.SetFileName(streaming.File, false) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    throw null;
                }
                if (pp.captureManager.LocateStreams() < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    throw null;
                }
                pp.captureManager.device.QueryDeviceInfo(out dinfo);
            }
            catch
            {
                pp.Dispose();
                SetStatus("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(streaming.File, null);
            sm1.Enabled = false;
            DeviceMenu.DropDownItems.Add(sm1);
            if (DeviceMenu.DropDownItems.Count > 0)
            {
                (DeviceMenu.DropDownItems[0] as ToolStripMenuItem).Checked = true;
            }

            /* populate profile menus from the file */
            profiles.Clear();
            foreach (ToolStripMenuItem menu in streamMenus)
            {
                if (menu != null)
                {
                    menu.DropDownItems.Clear();
                }
            }

            PXCMCapture.Device device = pp.captureManager.device;
            if (device == null)
            {
                pp.Dispose();
                SetStatus("Init Failed");
                return(false);
            }

            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)dinfo.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];
                        sm1           = new ToolStripMenuItem(ProfileToString(sprofile), null, new EventHandler(Stream_Item_Click));
                        profiles[sm1] = sprofile;
                        streamMenus[s].DropDownItems.Add(sm1);
                        Debug.WriteLine("1: " + ProfileToString(sprofile));
                    }
                }
                else if (((int)dinfo.streams & (int)st) == 0 && streamMenus[s] != null)
                {
                    streamMenus[s].Visible   = false;
                    streamButtons[s].Visible = false;
                    streamPanels[s].Visible  = false;
                }
            }

            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]);
                    (menu.DropDownItems[0] as ToolStripMenuItem).Checked = true;
                }
            }
            Start.Enabled = true;

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

            StatusLabel.Text = "Ok";
            return(true);
        }
        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 #19
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 #20
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 #21
0
        internal PXCMCapture.Device.StreamProfile getProfile(PXCMCapture.StreamType st, string mode)
        {
            if(SenseSession.StreamProfiles.ContainsKey(st))
            {
                if(SenseSession.StreamProfiles[st].ContainsKey(mode))
                {
                    return SenseSession.StreamProfiles[st][mode];
                }
            }

            //default
            PXCMCapture.Device.StreamProfile profileInfo = new PXCMCapture.Device.StreamProfile();
            profileInfo.frameRate.max = 0;
            profileInfo.frameRate.min = 0;
            profileInfo.imageInfo.height = 0;
            profileInfo.imageInfo.width = 0;

            return profileInfo;
        }