我正在使用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;
}
}
}
答案 0 :(得分:0)
将图像转换为8U
Mat show = new Mat(); disparityMap.ConvertTo(show,DepthType.Cv8U);