public DepthMapBuilder(ICommandBus commandBus) { _commandBus = commandBus; _emitDelay = TimeSpan.FromMilliseconds(1000.0 / DEPTH_MAP_PER_SECONDS); _stereoMatcher = StereoBM.Create(); _stereoMatcher.MinDisparity = 4; _stereoMatcher.NumDisparities = 128; _stereoMatcher.BlockSize = 21; _stereoMatcher.SpeckleRange = 16; _stereoMatcher.SpeckleWindowSize = 45; }
//窗体初始化 private void DisparityMeasure_Load(object sender, EventArgs e) { //初始化BM、SGBM类对象 bmMatch = StereoBM.Create(); sgbmMatch = StereoSGBM.Create(sgbm_minDisparity, sgbm_numofDisparities, sgbm_blockSize, sgbm_P1, sgbm_P2, sgbm_disp12MaxDiff, sgbm_preFilterCap, sgbm_uniquenessRatio, sgbm_speckleWindowSize, sgbm_speckleRange, sgbm_Mode); //初始化定时器 //dmTimer = new System.Threading.Timer(disparitymeTime, null, -1, 50); timer_disparityMeasure.Enabled = true; timer_disparityMeasure.Stop(); //计算有效视差区 //初始化BM参数 this.ucTrackBar_preFilterSize.Value = bm_preFilterSize; this.textBox_preFilterSize.Text = bm_preFilterSize.ToString(); this.ucTrackBar_preFilterCap.Value = bm_preFilterCap; this.textBox_preFilterCap.Text = bm_preFilterCap.ToString(); this.ucTrackBar_SADWinSize.Value = bm_SADWinSize; this.textBox_SADWinSize.Text = bm_SADWinSize.ToString(); this.ucTrackBar_minDIsparity.Value = bm_minDisparity; this.textBox_minDisparity.Text = bm_minDisparity.ToString(); //16倍倍数关系 this.ucTrackBar_numOfDis.Value = bm_numOfDisparities / 16; this.textBox_numOfDis.Text = bm_numOfDisparities.ToString(); this.ucTrackBar_uniquenessRatio.Value = bm_uniquenessRatio; this.textBox_uniquenessRatio.Text = bm_uniquenessRatio.ToString(); this.ucTrackBar_textureThre.Value = bm_textureThreshold; this.textBox_textureThreshold.Text = bm_textureThreshold.ToString(); this.ucTrackBar_speckleWinSize.Value = bm_speckleWinSize; this.textBox_speckleWinSize.Text = bm_speckleWinSize.ToString(); this.ucTrackBar_speckleRange.Value = bm_speckleRange; this.textBox_speckleRange.Text = bm_speckleRange.ToString(); this.ucTrackBar_disp12MaxDiff.Value = bm_disp12MaxDiff; this.textBox_disp12MaxDiff.Text = bm_disp12MaxDiff.ToString(); //初始化SGBM参数 this.numericUpDown_preFilterCap.Value = sgbm_preFilterCap; this.numericUpDown_sadWinSize.Value = sgbm_blockSize; this.numericUpDown_minDisparity.Value = sgbm_minDisparity; this.numericUpDown_numOfDisparities.Value = sgbm_numofDisparities; this.numericUpDown_p1.Value = sgbm_P1; this.numericUpDown_p2.Value = sgbm_P2; this.numericUpDown_uniquenessRatio.Value = sgbm_uniquenessRatio; this.numericUpDown_disp12MaxDiff.Value = sgbm_disp12MaxDiff; this.numericUpDown_speckleWinSize.Value = sgbm_speckleWindowSize; this.numericUpDown_speckcleRange.Value = sgbm_speckleRange; }
public void SimpleCompute() { var left = Image("tsukuba_left.png", ImreadModes.GrayScale); var right = Image("tsukuba_right.png", ImreadModes.GrayScale); var sbm = StereoBM.Create(); var disparity = new Mat(); sbm.Compute(left, right, disparity); /* * double min, max; * Cv2.MinMaxLoc(disparity, out min, out max); * * var disparityU8 = new Mat(); * disparity.ConvertTo(disparityU8, MatType.CV_8UC1, 255 / (max - min), -255 * min / (max - min)); * Window.ShowImages(disparityU8); * //*/ }
public void SimpleCompute() { var left = Image("tsukuba_left.png", ImreadModes.Grayscale); var right = Image("tsukuba_right.png", ImreadModes.Grayscale); var sbm = StereoBM.Create(); var disparity = new Mat(); sbm.Compute(left, right, disparity); if (Debugger.IsAttached) { Cv2.MinMaxLoc(disparity, out double min, out double max); var disparityU8 = new Mat(); disparity.ConvertTo(disparityU8, MatType.CV_8UC1, 255 / (max - min), -255 * min / (max - min)); Window.ShowImages(disparityU8); } }