/// <summary> /// 開啟RealSense相機並進行取像 /// </summary> internal void Open(out Image <Bgr, byte> ColorImg, out Image <Rgb, byte> DepthImg, out Image <Rgb, byte> FilteredImg, out VideoFrame color, out DepthFrame depth, out Frame filtered) { DepthImg = null; ColorImg = null; FilteredImg = null; color = null; depth = null; filtered = null; if (CamState != CameraState.Opened) { PipelineProfile = Camera.Start(cfg); // 以cfg設定並開始串流 vsp = PipelineProfile.GetStream <VideoStreamProfile>(Intel.RealSense.Stream.Depth); // 取得內部參數 intrinsics = vsp.GetIntrinsics(); sp = PipelineProfile.GetStream(Intel.RealSense.Stream.Color); // 取得外部參數 extrinsics = vsp.GetExtrinsicsTo(sp); CamState = CameraState.Opened; // 更新相機狀態 } else { try { FrameSet frames = Camera.WaitForFrames(); depth = frames.DepthFrame.DisposeWith(frames); color = frames.ColorFrame.DisposeWith(frames); filtered = depth; if (depth != null) { //Thres_Filter.Options[Option.MinDistance].Value = float.Parse(form1.textBox2.Text); //Thres_Filter.Options[Option.MaxDistance].Value = float.Parse(form1.textBox1.Text); //filtered = Thres_Filter.Process(filtered); //Spa_Filter.Options[Option.FilterMagnitude].Value = 1; //Spa_Filter.Options[Option.FilterSmoothAlpha].Value = 0.6f; //Spa_Filter.Options[Option.FilterSmoothDelta].Value = 8; //filtered = Spa_Filter.Process(filtered); Temp_Filter.Options[Option.FilterSmoothAlpha].Value = 0.5f; Temp_Filter.Options[Option.FilterSmoothDelta].Value = 20; Temp_Filter.Options[Option.HolesFill].Value = 2; filtered = Temp_Filter.Process(filtered); depColor = colorizer.Colorize(depth); filteredColor = colorizer.Colorize(filtered); ColorImg = new Image <Bgr, byte>(color.Width, color.Height, color.Stride, color.Data); DepthImg = new Image <Rgb, byte>(depColor.Width, depColor.Height, depColor.Stride, depColor.Data); FilteredImg = new Image <Rgb, byte>(filteredColor.Width, filteredColor.Height, filteredColor.Stride, filteredColor.Data); } } catch (Exception ex) { throw ex; } } }
public override Frame Process(Frame frame, FrameSource frameSource) { if (_pb == null) { Init(); } UpdateOptions(); return(_pb.Process(frame)); }