我正在尝试使用EMGUCV实时进行网络摄像头缝合。类似于这个设置在YouTube上。问题是我没有得到一个拼接的视频只有图像。
这是我的代码`
public Form1()
{
InitializeComponent();
capture1 = new Emgu.CV.Capture(0);
this.capture1.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 1920.0f);
this.capture1.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, 1080.0f);
capture2 = new Emgu.CV.Capture(1);
this.capture2.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 1920.0f);
this.capture2.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, 1080.0f);
}
private void button1_Click(object sender, EventArgs e)
{
#region if capture is not created, create it now
if (capture1 == null)
{
try
{
capture1 = new Emgu.CV.Capture(0);
capture2 = new Emgu.CV.Capture(1);
}
catch (NullReferenceException excpt)
{
MessageBox.Show(excpt.Message);
}
}
#endregion
if (capture1 != null)
{
if (captureInProgress)
{ //if camera is getting frames then stop the capture and set button Text
// "Start" for resuming capture
button1.Text = "Start!"; //
Application.Idle -= ProcessFrame;
}
else
{
//if camera is NOT getting frames then start the capture and set button
// Text to "Stop" for pausing capture
button1.Text = "Stop";
Application.Idle += ProcessFrame;
}
captureInProgress = !captureInProgress;
}
}
private void ProcessFrame(object sender, EventArgs arg)
{
Image<Bgr, Byte> ImageFrame = capture1.QueryFrame();
camimageBox.Image = ImageFrame; //line 2
Image<Bgr, Byte> ImageFrame2 = capture2.QueryFrame();
imageBox1.Image = ImageFrame2;
}
private void ReleaseData()
{
if (capture1 != null)
capture1.Dispose();
}
private void button2_Click(object sender, EventArgs e)
{
Image<Bgr, byte>[] frames2 = new Image<Bgr, byte>[2];
//List<Image<Bgr, Byte>> frames2 = new List<Image<Bgr, byte>>();
frames2[0] = capture1.QueryFrame();
frames2[1] = capture2.QueryFrame();
camimageBox.Image = frames2[0];
imageBox1.Image = frames2[1];
try
{
using (Stitcher stitcher = new Stitcher(true))
//using (Stitcher stitcher = new Stitcher(true))
{
Image<Bgr, Byte> result = stitcher.Stitch(frames2);
imageBox2.Image = result;
}
}
finally
{
foreach (Image<Bgr, Byte> img in frames2)
{
img.Dispose();
}
}
}
}
我使用的是 Nvidia NVS 450 GPU。我能够将各个摄像机作为单独的流读取。我想知道我是否可以使用 EMGUCV 将这些流组合在一起以生成一个流(更像是虚拟网络中的 2 个网络摄像头)。
我将不胜感激任何帮助。请注意我的英语!
您需要在 2 个图像帧上找到相应的点(如果相机位置是单独控制的,则 SURF 类型的算法,或者您可以使用棋盘图案并找到相应的角,如果相机具有固定的相对位置和角度),然后使用这些点的坐标来计算单应性矩阵。当你有一个矩阵时,你可以使用它作为"WarpPerspective"函数的参数。它会扭曲您的图像,以便可以从第二个摄像头将其放在框架上。
希望有帮助。