我的“视差图”结果为黑色?

问题描述 投票:2回答:1

我正在使用emgucv 3.10,我想从立体图像中提取3D信息。因此,我拍摄了左右图像,然后得到了视差图。

但是我的视差图是黑色的?我该如何解决?您能帮我解决这个问题吗?

获得视差图像后,我想测量图像中点之间的真实距离吗?这可能吗 ? (如本视频YouTube: Measure distance with web cams from depth map using OpenCV full source code所示)

using System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;using System.Text;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using System.Diagnostics;
using Emgu.CV.UI;

namespaceEmguCv_Stereo_Image_Calismasi_02mayıs{
    public partial class Form1 : Form    {
        private Mat _sol;
        private Mat _sag;



        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            _sol = CvInvoke.Imread(@"imL.png", LoadImageType.Color);
            UMat solGri = new UMat();
            CvInvoke.CvtColor(_sol, solGri, ColorConversion.Bgr2Gray);
            _sag = CvInvoke.Imread(@"imR.png", LoadImageType.Color);
            UMat sagGri = new UMat();
            CvInvoke.CvtColor(_sag, sagGri, ColorConversion.Bgr2Gray);

            ımageBox1.Image = _sol;
            ımageBox2.Image = solGri;
            ımageBox3.Image = _sag;
            ımageBox4.Image = sagGri;


        }
        private int GetSliderValue(TrackBar Control)
        {
            if (Control.InvokeRequired)
            {
                try
                {
                    return (int)Control.Invoke(new Func<int>(() => GetSliderValue(Control)));
                }
                catch (Exception ex)
                {
                    return 0;
                }
            }
            else
            {
                return Control.Value;
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            Mat disparityMap = new Mat();
            _sol = CvInvoke.Imread(@"imL.png", LoadImageType.Color);
            UMat solGri = new UMat();
            CvInvoke.CvtColor(_sol, solGri, ColorConversion.Bgr2Gray);
            _sag = CvInvoke.Imread(@"imR.png", LoadImageType.Color);
            UMat sagGri = new UMat();
            CvInvoke.CvtColor(_sag, sagGri, ColorConversion.Bgr2Gray);

            // StereoSGBM sgbm = new StereoSGBM(1, 48, 11, 242, 605, -1, 63,10, 0, 32,0);
             //  sgbm.Compute(solGri, sagGri, disparityMap);


            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 Speckle = GetSliderValue(Speckle_Window);
            int SpeckleRange = GetSliderValue(specklerange);

            label3.Text = minDispatities.ToString();
            label14.Text = numDisparities.ToString();
            label15.Text = SAD.ToString();
            label16.Text = disp12MaxDiff.ToString();
            label17.Text = PreFilterCap.ToString();
            label18.Text = UniquenessRatio.ToString();
            label19.Text = Speckle.ToString();
            label20.Text = SpeckleRange.ToString();

            StereoSGBM sgbm = new StereoSGBM(
              minDispatities,
              numDisparities,
              SAD, 
              P1, 
              P2,
              disp12MaxDiff,
              PreFilterCap,
              UniquenessRatio,
              Speckle,
              SpeckleRange, 
              0
              );
            sgbm.Compute(solGri, sagGri, disparityMap);
            ımageBox5.Image = disparityMap;

        }
    }
}

enter image description hereenter image description hereenter image description here

c# opencv emgucv opencv3.0
1个回答
0
投票

将图像转换为8U

Mat show = new Mat();disparityMap.ConvertTo(show,DepthType.Cv8U);

© www.soinside.com 2019 - 2024. All rights reserved.