public FrameSet WaitForFrames(uint timeout_ms = 5000, FramesReleaser releaser = null) { object error; var ptr = NativeMethods.rs2_pipeline_wait_for_frames(m_instance.Handle, timeout_ms, out error); return(FramesReleaser.ScopedReturn(releaser, new FrameSet(ptr))); }
public FrameSet WaitForFrames(FramesReleaser releaser = null) { object error; var ptr = NativeMethods.rs2_wait_for_frame(m_instance.Handle, 5000, out error); return(FramesReleaser.ScopedReturn(releaser, new FrameSet(ptr))); }
public VideoFrame Colorize(VideoFrame original, FramesReleaser releaser = null) { object error; NativeMethods.rs2_frame_add_ref(original.m_instance.Handle, out error); NativeMethods.rs2_process_frame(m_instance.Handle, original.m_instance.Handle, out error); return(FramesReleaser.ScopedReturn(releaser, queue.WaitForFrame() as VideoFrame)); }
public FrameSet Process(FrameSet original, FramesReleaser releaser = null) { object error; NativeMethods.rs2_frame_add_ref(original.m_instance.Handle, out error); NativeMethods.rs2_process_frame(m_instance.Handle, original.m_instance.Handle, out error); return(FramesReleaser.ScopedReturn(releaser, queue.WaitForFrames() as FrameSet)); }
public Points Calculate(Frame original, FramesReleaser releaser = null) { object error; NativeMethods.rs2_frame_add_ref(original.m_instance.Handle, out error); NativeMethods.rs2_process_frame(m_instance.Handle, original.m_instance.Handle, out error); return(FramesReleaser.ScopedReturn(releaser, queue.WaitForFrame() as Points)); }
public bool PollForFrame(out Frame frame, FramesReleaser releaser = null) { object error; if (NativeMethods.rs2_poll_for_frame(m_instance.Handle, out frame, out error) > 0) { frame = FramesReleaser.ScopedReturn(releaser, FrameSet.CreateFrame(frame.m_instance.Handle)); return(true); } return(false); }
public static FrameSet FromFrame(Frame composite, FramesReleaser releaser = null) { object error; if (NativeMethods.rs2_is_frame_extendable_to(composite.m_instance.Handle, Extension.CompositeFrame, out error) > 0) { NativeMethods.rs2_frame_add_ref(composite.m_instance.Handle, out error); return(FramesReleaser.ScopedReturn(releaser, new FrameSet(composite.m_instance.Handle))); } throw new Exception("The frame is a not composite frame"); }
public bool PollForFrames(out FrameSet result, FramesReleaser releaser = null) { object error; FrameSet fs; if (NativeMethods.rs2_pipeline_poll_for_frames(m_instance.Handle, out fs, out error) > 0) { result = FramesReleaser.ScopedReturn(releaser, fs); return(true); } result = null; return(false); }
public FrameSet AllocateCompositeFrame(FramesReleaser releaser, params Frame[] frames) { object error; var frame_refs = frames.Select(x => x.m_instance.Handle).ToArray(); foreach (var fref in frame_refs) { NativeMethods.rs2_frame_add_ref(fref, out error); } var frame_ref = NativeMethods.rs2_allocate_composite_frame(m_instance.Handle, frame_refs, frames.Count(), out error); return(FramesReleaser.ScopedReturn(releaser, new FrameSet(frame_ref))); }
public bool PollForFrames(out FrameSet result, FramesReleaser releaser = null) { object error; Frame f; if (NativeMethods.rs2_poll_for_frame(queue.m_instance.Handle, out f, out error) > 0) { result = FramesReleaser.ScopedReturn(releaser, new FrameSet(f.m_instance.Handle)); f.Dispose(); return(true); } result = null; return(false); }
/** * NOTES * Curently it records immediately after linking the program with LabStreamLayer. * There might be a better solution, but we don't want to increase the number of button presses for the protoccol. It is probably better to record more than to forget pressing * the record button before an experiment. * * **/ // Code Taken Directly from the LibRealSense 2 Examples -- Captures and Displays Depth and RGB Camera. private void startRecordingProcess() { try { pipeline = new Pipeline(); colorizer = new Colorizer(); var cfg = new Config(); cfg.EnableStream(Stream.Depth, 640, 480, Format.Z16, 30); cfg.EnableStream(Stream.Color, 640, 480, Format.Bgr8, 30); //cfg.EnableRecordToFile(fileRecording); // This is now taken care of by FFMPEG pipeline.Start(cfg); applyRecordingConfig(); processBlock = new CustomProcessingBlock((f, src) => { using (var releaser = new FramesReleaser()) { var frames = FrameSet.FromFrame(f, releaser); VideoFrame depth = FramesReleaser.ScopedReturn(releaser, frames.DepthFrame); VideoFrame color = FramesReleaser.ScopedReturn(releaser, frames.ColorFrame); var res = src.AllocateCompositeFrame(releaser, depth, color); src.FramesReady(res); } }); processBlock.Start(f => { using (var releaser = new FramesReleaser()) { var frames = FrameSet.FromFrame(f, releaser); var depth_frame = FramesReleaser.ScopedReturn(releaser, frames.DepthFrame); var color_frame = FramesReleaser.ScopedReturn(releaser, frames.ColorFrame); var colorized_depth = colorizer.Colorize(depth_frame); UploadImage(imgDepth, colorized_depth); UploadImage(imgColor, color_frame); // Record FFMPEG Bitmap bmpColor = new Bitmap(color_frame.Width, color_frame.Height, color_frame.Stride, System.Drawing.Imaging.PixelFormat.Format24bppRgb, color_frame.Data); vidWriter_Color.WriteVideoFrame(bmpColor); Bitmap bmpDepth = new Bitmap(colorized_depth.Width, colorized_depth.Height, colorized_depth.Stride, System.Drawing.Imaging.PixelFormat.Format24bppRgb, colorized_depth.Data); vidWriter_Depth.WriteVideoFrame(bmpDepth); if (lslOutlet != null) { // Do LSL Streaming Here sample[0] = "" + colorized_depth.Number + "_" + colorized_depth.Timestamp; sample[1] = "" + color_frame.Number + "_" + color_frame.Timestamp; lslOutlet.push_sample(sample, liblsl.local_clock()); } } }); var token = tokenSource.Token; var t = Task.Factory.StartNew(() => { // Main Loop -- while (!token.IsCancellationRequested) { using (var frames = pipeline.WaitForFrames()) { processBlock.ProcessFrames(frames); } } }, token); } catch (Exception ex) { MessageBox.Show(ex.Message); Application.Current.Shutdown(); } }
public ProcessingWindow() { try { var cfg = new Config(); cfg.EnableStream(Stream.Depth, 640, 480); cfg.EnableStream(Stream.Color, Format.Rgb8); pipeline.Start(cfg); // Create custom processing block // For demonstration purposes it will: // a. Get a frameset // b. Break it down to frames // c. Run post-processing on the depth frame // d. Combine the result back into a frameset // Processing blocks are inherently thread-safe and play well with // other API primitives such as frame-queues, // and can be used to encapsulate advanced operations. // All invokations are, however, synchronious so the high-level threading model // is up to the developer block = new CustomProcessingBlock((f, src) => { // We create a FrameReleaser object that would track // all newly allocated .NET frames, and ensure deterministic finalization // at the end of scope. using (var releaser = new FramesReleaser()) { var frames = FrameSet.FromFrame(f, releaser); VideoFrame depth = FramesReleaser.ScopedReturn(releaser, frames.DepthFrame); VideoFrame color = FramesReleaser.ScopedReturn(releaser, frames.ColorFrame); // Apply depth post-processing depth = decimate.ApplyFilter(depth, releaser); depth = spatial.ApplyFilter(depth, releaser); depth = temp.ApplyFilter(depth, releaser); // Combine the frames into a single result var res = src.AllocateCompositeFrame(releaser, depth, color); // Send it to the next processing stage src.FramesReady(res); } }); // Register to results of processing via a callback: block.Start(f => { using (var releaser = new FramesReleaser()) { // Align, colorize and upload frames for rendering var frames = FrameSet.FromFrame(f, releaser); // Align both frames to the viewport of color camera frames = align.Process(frames, releaser); var depth_frame = FramesReleaser.ScopedReturn(releaser, frames.DepthFrame); var color_frame = FramesReleaser.ScopedReturn(releaser, frames.ColorFrame); UploadImage(imgDepth, colorizer.Colorize(depth_frame, releaser)); UploadImage(imgColor, color_frame); } }); var token = tokenSource.Token; var t = Task.Factory.StartNew(() => { while (!token.IsCancellationRequested) { using (var frames = pipeline.WaitForFrames()) { // Invoke custom processing block block.ProcessFrames(frames); } } }, token); } catch (Exception ex) { MessageBox.Show(ex.Message); Application.Current.Shutdown(); } InitializeComponent(); }