使用C# EmguCV來擷取海康HIKVISION DS-2CD2610F-I的影像範例

基本上此篇的做法跟 使用C# EmguCV來擷取D-Link DCS-930 IP Cam的影像範例 這篇之前寫的文章範例一樣

只是單純因為公司是用海康的IP CAM  , 基本上只要支援即時串流協議( Real Time Streaming Protocol,RTSP) 的IP CAM,都可以利用EmguCV來擷取畫面

這款IP CAM其實就有內建一些影像處理以及簡易影像判斷(如區域畫面異動,或是移動偵測等等)

程式碼和成果畫面如下分享

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Threading;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.CV.CvEnum;

namespace EmguCV_20171013
{
    public partial class Form1 : Form
    {
        private Capture _capture = null;
        private bool _captureInProgress;

        public Form1()
        {
            InitializeComponent();
            CvInvoke.UseOpenCL = false;
            try
            {
                //_capture = new Capture("rtsp://帳號:密碼@10.248.63.220/");//
                _capture = new Capture("rtsp://MyAccount:MyPW@10.248.63.220/");
                _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;
            }
        }
    }
}