private Image<Gray, short> GetDispMap(VideoSource.StereoFrameSequenceElement stereoFrame) { int numDisparities = GetSliderValue(Num_Disparities); int minDispatities = GetSliderValue(Min_Disparities); int SAD = GetSliderValue(SAD_Window); int P1 = 8 * 1 * SAD * SAD;//GetSliderValue(P1_Slider); int P2 = 32 * 1 * SAD * SAD;//GetSliderValue(P2_Slider); int disp12MaxDiff = GetSliderValue(Disp12MaxDiff); int PreFilterCap = GetSliderValue(pre_filter_cap); int UniquenessRatio = GetSliderValue(uniquenessRatio); int SpeckleWindow = GetSliderValue(Speckle_Window); int SpeckleRange = GetSliderValue(specklerange); using (var gpuSBM = new Emgu.CV.GPU.GpuStereoBM(numDisparities, SAD)) using (StereoSGBM stereoSolver = new StereoSGBM( minDisparity: minDispatities, numDisparities: numDisparities, blockSize: SAD, p1: P1, p2: P2, disp12MaxDiff: disp12MaxDiff, preFilterCap: PreFilterCap, uniquenessRatio: UniquenessRatio, speckleRange: SpeckleRange, speckleWindowSize: SpeckleWindow, mode: StereoSGBM.Mode.SGBM )) using (var leftImg = new Image<Gray, byte>(stereoFrame.LeftRawFrame)) using (var rightImg = new Image<Gray, byte>(stereoFrame.RightRawFrame)) using (var dispImg = new Image<Gray, short>(leftImg.Size)) using (var gpuLeftImg = new Emgu.CV.GPU.GpuImage<Gray, byte>(leftImg)) using (var gpuRightImg = new Emgu.CV.GPU.GpuImage<Gray, byte>(rightImg)) using (var gpuDispImg = new Emgu.CV.GPU.GpuImage<Gray, byte>(leftImg.Size)) { var dispMap = new Image<Gray, short>(leftImg.Size); //CPU //stereoSolver.FindStereoCorrespondence(leftImg, rightImg, dispImg); //dispMap = dispImg.Convert<Gray, short>(); // //GPU gpuSBM.FindStereoCorrespondence(gpuLeftImg, gpuRightImg, gpuDispImg, null); dispMap = gpuDispImg.ToImage().Convert<Gray, short>(); // return dispMap; } }
private MCvPoint3D32f[] Get3DFeatures(StereoCameraParams stereoParams, VideoSource.StereoFrameSequenceElement stereoFrame, out Image<Gray, short> disparityImg) { using (var gpuSBM = new Emgu.CV.GPU.GpuStereoBM(128, 19)) using (StereoSGBM stereoSolver = new StereoSGBM( minDisparity: 0, numDisparities: 32, blockSize: 0, p1: 0, p2: 0, disp12MaxDiff: 0, preFilterCap: 0, uniquenessRatio: 0, speckleRange: 0, speckleWindowSize: 0, mode: StereoSGBM.Mode.HH )) using (var leftImg = new Image<Gray, byte>(stereoFrame.LeftRawFrame)) using (var rightImg = new Image<Gray, byte>(stereoFrame.RightRawFrame)) using (var dispImg = new Image<Gray, short>(leftImg.Size)) using (var gpuLeftImg = new Emgu.CV.GPU.GpuImage<Gray, byte>(leftImg)) using (var gpuRightImg = new Emgu.CV.GPU.GpuImage<Gray, byte>(rightImg)) using (var gpuDispImg = new Emgu.CV.GPU.GpuImage<Gray, byte>(leftImg.Size)) { var dispMap = new Image<Gray, short>(leftImg.Size); //CPU //stereoSolver.FindStereoCorrespondence(leftImg, rightImg, dispImg); //dispMap = dispImg.Convert<Gray, short>(); // //GPU gpuSBM.FindStereoCorrespondence(gpuLeftImg, gpuRightImg, gpuDispImg, null); dispMap = gpuDispImg.ToImage().Convert<Gray, short>(); // var points = PointCollection.ReprojectImageTo3D(dispMap, stereoParams.Q); disparityImg = dispMap; return points; } }