【问题标题】:Realtime Webcam video stitching with EmguCV使用 EmguCV 进行实时网络摄像头视频拼接
【发布时间】:2012-06-17 22:33:57
【问题描述】:

我正在尝试使用 EMGUCV 实时进行网络摄像头缝合。类似的东西 this setup on 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 个网络摄像头)。

我将不胜感激任何帮助。请注意我的英语!

【问题讨论】:

    标签: c# webcam emgucv image-stitching


    【解决方案1】:

    您好,您需要在 2 个图像帧上找到对应的点(如果相机位置是单独控制的,则为 SURF 类型的算法,或者如果相机具有固定的相对位置和角度,您可以使用棋盘图案并找到相应的角),然后使用那些坐标点计算单应矩阵。当您有一个矩阵时,您可以将其用作“WarpPerspective”函数的参数。它会扭曲您的图像,以便可以将其放在第二个相机的框架上。

    希望对您有所帮助。

    【讨论】:

    • 你好 OscylO 谢谢。这么晚才回复很抱歉。我忙于其他事情。我会检查你写的东西,如果没问题就给你反馈
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-21
    • 1970-01-01
    • 2016-10-23
    • 1970-01-01
    • 1970-01-01
    • 2013-07-09
    • 2017-04-27
    相关资源
    最近更新 更多