gpt4 book ai didi

c# - 我的 'Disparity map'结果是黑色?

转载 作者:行者123 更新时间:2023-12-02 16:12:44 26 4
gpt4 key购买 nike

我正在使用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 here enter image description here
enter image description here

最佳答案

将图像转换为8U

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

关于c# - 我的 'Disparity map'结果是黑色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37060295/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com