Ejemplo n.º 1
0
        public void EnableStreamsFromSelection()
        {
            /* Set Color & Depth Resolution and enable streams */
            if (StreamProfileSet != null)
            {
                /* Optional: Filter the data based on the request */
                manager.SenseManager.CaptureManager.FilterByStreamProfiles(StreamProfileSet);

                /* Enable raw data streaming for specific stream types */

                // Set frame Rate, Height and With for all Sterams
                for (int s = 0; s < RS.Capture.STREAM_LIMIT; s++)
                {
                    RS.StreamType    st   = RS.Capture.StreamTypeFromIndex(s);
                    RS.StreamProfile info = StreamProfileSet[st];
                    if (info.imageInfo.format != 0)
                    {
                        /* For simple request, you can also use sm.EnableStream(...) */
                        RS.DataDesc desc = new RS.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;
                        desc.receivePartialSample       = true;
                        RS.SampleReader sampleReader = RS.SampleReader.Activate(manager.SenseManager);
                        sampleReader.EnableStreams(desc);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public T GetProfile <T>() where T : StreamProfile
        {
            object error;
            var    ptr = NativeMethods.rs2_get_frame_stream_profile(m_instance.Handle, out error);

            return(StreamProfile.Create <T>(ptr));
        }
Ejemplo n.º 3
0
        // Get names for Drop down Menu
        private string ProfileToString(RS.StreamProfile streamProfile)
        {
            string line = "Unknown ";

            if (Enum.IsDefined(typeof(RS.PixelFormat), streamProfile.imageInfo.format))
            {
                line = streamProfile.imageInfo.format.ToString().Substring(13) + " " + streamProfile.imageInfo.width + "x" + streamProfile.imageInfo.height + "x";
            }
            else
            {
                line += streamProfile.imageInfo.width + "x" + streamProfile.imageInfo.height + "x";
            }
            if (streamProfile.frameRate.min != streamProfile.frameRate.max)
            {
                line += (float)streamProfile.frameRate.min + "-" +
                        (float)streamProfile.frameRate.max;
            }
            else
            {
                float fps = (streamProfile.frameRate.min != 0) ? streamProfile.frameRate.min : streamProfile.frameRate.max;
                line += fps;
            }
            line += StreamOptionToString(streamProfile.options);
            return(line);
        }
Ejemplo n.º 4
0
        public MotionStreamProfile AddMotionStream(SoftwareMotionStream profile)
        {
            object error;
            var    ptr = NativeMethods.rs2_software_sensor_add_motion_stream(Handle, profile, out error);

            return(StreamProfile.Create <MotionStreamProfile>(ptr));
        }
Ejemplo n.º 5
0
        private void PopulateProfiles(RS.DeviceInfo dinfo)
        {
            RS.SenseManager pp     = RS.SenseManager.CreateInstance();
            RS.Device       device = pp.CaptureManager.Device;
            if (device == null)
            {
                pp.Dispose();
            }
            RS.StreamProfileSet profile = new RS.StreamProfileSet();

            for (int s = 0; s < RS.Capture.STREAM_LIMIT; s++)
            {
                RS.StreamType st = RS.Capture.StreamTypeFromIndex(s);
                if (((int)dinfo.streams & (int)st) != 0)
                {
                    int num = device.QueryStreamProfileSetNum(st);
                    for (int p = 0; p < num; p++)
                    {
                        if (device.QueryStreamProfileSet(st, p, out profile) < RS.Status.STATUS_NO_ERROR)
                        {
                            break;
                        }
                        RS.StreamProfile sprofile = profile[st];
                        string           profNime = ProfileToString(sprofile);
                        profiles[profile] = sprofile;
                        cb_Profile.Items.Add(profNime);
                    }
                }
                else if (((int)dinfo.streams & (int)st) == 0)
                {
                }
            }
        }
Ejemplo n.º 6
0
        public PoseStreamProfile AddMotionStream(SoftwarePoseStream profile)
        {
            object error;
            var    ptr = NativeMethods.rs2_software_sensor_add_pose_stream(m_instance, profile, out error);

            return(StreamProfile.Create <PoseStreamProfile>(ptr));
        }
Ejemplo n.º 7
0
        public VideoFrame AllocateVideoFrame(StreamProfile profile, Frame original, int bpp, int width, int height, int stride, Extension extension = Extension.VideoFrame)
        {
            object error;
            var    fref = NativeMethods.rs2_allocate_synthetic_video_frame(m_instance.Handle, profile.m_instance.Handle, original.m_instance.Handle, bpp, width, height, stride, extension, out error);

            return(new VideoFrame(fref));
        }
Ejemplo n.º 8
0
        public VideoStreamProfile AddVideoStream(SoftwareVideoStream profile)
        {
            object error;
            var    ptr = NativeMethods.rs2_software_sensor_add_video_stream(m_instance, profile, out error);

            return(StreamProfile.Create <VideoStreamProfile>(ptr));
        }
Ejemplo n.º 9
0
        public T AllocateMotionFrame <T>(StreamProfile profile, Frame original, Extension extension = Extension.VideoFrame)
            where T : Frame
        {
            object error;
            var    fref = NativeMethods.rs2_allocate_synthetic_motion_frame(m_instance.Handle, profile.Handle, original.Handle, extension, out error);

            return(Frame.Create <T>(fref));
        }
Ejemplo n.º 10
0
        public Extrinsics GetExtrinsicsTo(StreamProfile other)
        {
            object     error;
            Extrinsics extrinsics;

            NativeMethods.rs2_get_extrinsics(m_instance.Handle, other.m_instance.Handle, out extrinsics, out error);
            return(extrinsics);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Clone current profile and change the type, index and format to input parameters
        /// </summary>
        /// <param name="type">will change the stream type from the cloned profile.</param>
        /// <param name="index">will change the stream index from the cloned profile.</param>
        /// <param name="format">will change the stream format from the cloned profile.</param>
        /// <param name="width">will change the width of the profile.</param>
        /// <param name="height">will change the height of the profile.</param>
        /// <param name="intr">will change the intrinsics of the profile.</param>
        /// <returns>the cloned stream profile.</returns>
        public StreamProfile Clone(Stream type, int index, Format format, int width, int height, Intrinsics intr)
        {
            object error;
            var    ptr = NativeMethods.rs2_clone_video_stream_profile(Handle, type, index, format, width, height, intr, out error);
            var    p   = StreamProfile.Create <VideoStreamProfile>(ptr);

            p.clone = new Base.DeleterHandle(ptr, StreamProfileReleaser);
            return(p);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Clone the current profile and change the type, index and format to input parameters
        /// </summary>
        /// <param name="type">will change the stream type from the cloned profile.</param>
        /// <param name="index">will change the stream index from the cloned profile.</param>
        /// <param name="format">will change the stream format from the cloned profile.</param>
        /// <returns>the cloned stream profile.</returns>
        public StreamProfile Clone(Stream type, int index, Format format)
        {
            object error;
            var    ptr = NativeMethods.rs2_clone_stream_profile(Handle, type, index, format, out error);
            var    p   = StreamProfile.Create(ptr);

            p.clone = new DeleterHandle(ptr, StreamProfileReleaser);
            return(p);
        }
Ejemplo n.º 13
0
 public T GetStream <T>(Stream s, int index = -1) where T : StreamProfile
 {
     using (var streams = Streams)
     {
         object error;
         int    count = streams.Count;
         for (int i = 0; i < count; i++)
         {
             var ptr = NativeMethods.rs2_get_stream_profile(streams.m_instance, i, out error);
             var t   = StreamProfile.Create <T>(ptr);
             if (t.Stream == s && (index == -1 || t.Index == index))
             {
                 return(t);
             }
             t.Dispose();
         }
         return(null);
     }
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Return the selected stream profile, which are enabled in this profile.
        /// </summary>
        /// <typeparam name="T"><see cref="StreamProfile"/> type or subclass</typeparam>
        /// <param name="s">Stream type of the desired profile</param>
        /// <param name="index">Stream index of the desired profile. -1 for any matching.</param>
        /// <returns>The first matching stream profile</returns>
        /// <exception cref="ArgumentException">Thrown when the <see cref="PipelineProfile"/> does not contain the request stream</exception>
        public T GetStream <T>(Stream s, int index = -1)
            where T : StreamProfile
        {
            object error;

            using (var streams = new StreamProfileList(NativeMethods.rs2_pipeline_profile_get_streams(Handle, out error)))
            {
                int count = streams.Count;
                for (int i = 0; i < count; i++)
                {
                    var ptr = NativeMethods.rs2_get_stream_profile(streams.Handle, i, out error);
                    var t   = StreamProfile.Create <T>(ptr);
                    if (t.Stream == s && (index == -1 || t.Index == index))
                    {
                        return(t);
                    }

                    t.Dispose();
                }

                throw new ArgumentException("Profile does not contain the requested stream", nameof(s));
            }
        }
Ejemplo n.º 15
0
        public void StreamColorDepth() /* Stream Color and Depth Synchronously or Asynchronously */
        {
            try
            {
                bool sts = true;

                /* Create an instance of the RS.SenseManager interface */
                RS.SenseManager sm = RS.SenseManager.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 < RS.Capture.STREAM_LIMIT; s++)
                    {
                        RS.StreamType    st   = RS.Capture.StreamTypeFromIndex(s);
                        RS.StreamProfile info = StreamProfileSet[st];
                        if (info.imageInfo.format != 0)
                        {
                            /* For simple request, you can also use sm.EnableStream(...) */
                            RS.DataDesc desc = new RS.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;
                            desc.receivePartialSample       = true;
                            RS.SampleReader sampleReader = RS.SampleReader.Activate(sm);
                            sampleReader.EnableStreams(desc);
                        }
                    }
                }

                /* Initialization */


                SetStatus("Init Started");
                if (sm.Init() >= RS.Status.STATUS_NO_ERROR)
                {
                    /* Reset all properties */
                    sm.CaptureManager.Device.ResetProperties(RS.StreamType.STREAM_TYPE_ANY);

                    /* Set mirror mode */
                    RS.MirrorMode mirror = Mirror ? RS.MirrorMode.MIRROR_MODE_HORIZONTAL : RS.MirrorMode.MIRROR_MODE_DISABLED;
                    sm.CaptureManager.Device.MirrorMode = mirror;

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

                        /* Display images */
                        RS.Sample sample = sm.Sample;

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

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

                        /* Optional: Set Mirror State */
                        mirror = Mirror ? RS.MirrorMode.MIRROR_MODE_HORIZONTAL : RS.MirrorMode.MIRROR_MODE_DISABLED;
                        if (mirror != sm.CaptureManager.Device.MirrorMode)
                        {
                            sm.CaptureManager.Device.MirrorMode = mirror;
                        }

                        /* Optional: Show performance tick */



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

                sm.Dispose();
                if (sts)
                {
                    SetStatus("Stopped");
                }
            }
            catch (Exception e)
            {
                SetStatus(e.GetType().ToString());
            }
        }
Ejemplo n.º 16
0
        // Get entries for color Streams
        private void PopulateColorDepthMenus(ToolStripMenuItem device_item)
        {
            RS.ImplDesc desc = new RS.ImplDesc();
            desc.group          = RS.ImplGroup.IMPL_GROUP_SENSOR;
            desc.subgroup       = RS.ImplSubgroup.IMPL_SUBGROUP_VIDEO_CAPTURE;
            desc.iuid           = devices_iuid[device_item];
            current_device_iuid = desc.iuid;
            desc.cuids[0]       = RS.Capture.CUID;

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

            RS.Capture    capture;
            RS.DeviceInfo dinfo2 = GetCheckedDevice();
            if (manager.Session.CreateImpl <RS.Capture>(desc, out capture) >= RS.Status.STATUS_NO_ERROR)
            {
                RS.Device device = capture.CreateDevice(dinfo2.didx);
                if (device != null)
                {
                    RS.StreamProfileSet streamProfileSet = new RS.StreamProfileSet();

                    for (int s = 0; s < RS.Capture.STREAM_LIMIT; s++)
                    {
                        RS.StreamType streamType = RS.Capture.StreamTypeFromIndex(s);
                        if (((int)dinfo2.streams & (int)streamType) != 0 && streamMenue[s] != null)
                        {
                            streamMenue[s].Visible   = true;
                            streamButtons[s].Visible = true;
                            int num = device.QueryStreamProfileSetNum(streamType);
                            for (int p = 0; p < num; p++)
                            {
                                if (device.QueryStreamProfileSet(streamType, p, out streamProfileSet) < RS.Status.STATUS_NO_ERROR)
                                {
                                    break;
                                }
                                RS.StreamProfile  streamProfile = streamProfileSet[streamType];
                                ToolStripMenuItem sm1           = new ToolStripMenuItem(ProfileToString(streamProfile), null, new EventHandler(Stream_Item_Click));
                                profiles[sm1] = streamProfile;
                                streamMenue[s].DropDownItems.Add(sm1);
                            }
                        }
                        else if (((int)dinfo2.streams & (int)streamType) == 0 && streamMenue[s] != null)
                        {
                            streamMenue[s].Visible   = false;
                            streamButtons[s].Visible = false;
                        }
                    }

                    device.Dispose();
                }
                capture.Dispose();
            }
            for (int i = 0; i < RS.Capture.STREAM_LIMIT; i++)
            {
                ToolStripMenuItem menu = streamMenue[i];
                if (menu != null)
                {
                    streamString[i]           = new ToolStripMenuItem("None", null, new EventHandler(Stream_Item_Click));
                    profiles[streamString[i]] = new RS.StreamProfile();
                    menu.DropDownItems.Add(streamString[i]);
                    if (menu == colorMenu)
                    {
                        (menu.DropDownItems[0] as ToolStripMenuItem).Checked = true;
                    }
                    else
                    {
                        streamString[i].Checked = true;
                    }
                }
            }

            CheckSelection();
        }
Ejemplo n.º 17
0
        /// <summary>
        /// open subdevice for exclusive access, by commiting to a configuration
        /// </summary>
        /// <param name="profile"></param>
        public void Open(StreamProfile profile)
        {
            object error;

            NativeMethods.rs2_open(m_instance, profile.m_instance.Handle, out error);
        }
Ejemplo n.º 18
0
        public void RegisterExtrinsicsTo(StreamProfile other, Extrinsics extrinsics)
        {
            object error;

            NativeMethods.rs2_register_extrinsics(Handle, other.Handle, extrinsics, out error);
        }