流相机ip emgucv

时间:2016-08-16 04:09:11

标签: c# emgucv

你好,当我运行此代码到c#与emgucv在一个图片框中看到一个实时的ip摄像头它显示一个错误 在这一部分:

Mat frame = new Mat();
_capture.Retrieve(frame, 0);
captureImageBox.Image = frame;

错误提及

  

无法在emgu.cv.imag中转换类型emgu.cv.mat ...

我需要更改哪些代码才能正确运行....

功能

  • Visual studio 2015
  • emgucv v3.1 x64

    public partial class Form1 : Form
    {
    private Capture _capture = null;
    private bool _captureInProgress;
    public Form1()
    {
        InitializeComponent();
        CvInvoke.UseOpenCL = false;
        try
        {
            _capture = new Capture("http://webcam.st-malo.com/axis-cgi/mjpg/video.cgi?");
            _capture.ImageGrabbed += ProcessFrame;
        }
        catch (NullReferenceException excpt)
        {
            MessageBox.Show(excpt.Message);
        }
    }
    
    private void ProcessFrame(object sender, EventArgs arg)
    {
        Mat frame = new Mat();
        _capture.Retrieve(frame, 0);
    
        captureImageBox.Image = frame;
    
    }
    
    private void captureButton_Click(object sender, EventArgs e)
    {
        if (_capture != null)
        {
            if (_captureInProgress)
            {  //stop the capture
                captureButton.Text = "Start Capture";
                _capture.Pause();
            }
            else
            {
                //start the capture
                captureButton.Text = "Stop";
                _capture.Start();
            }
    
            _captureInProgress = !_captureInProgress;
        }
    }
    

    }

1 个答案:

答案 0 :(得分:0)

尝试将Mat解析为图像 使用这个

Mat frame = new Mat();
_capture.Retrieve(frame, 0);

captureImageBox.Image = frame.ToImage<Bgr, Byte>();