C# 通過Emgu CV播放流媒體(RTSP)

來源:互聯網
上載者:User

標籤:

      Emgu CV is a cross platform .Net wrapper to the OpenCV image processing library. Allowing OpenCV functions to be called from .NET compatible languages such as C#, VB, VC++, IronPython etc. The wrapper can be compiled by Visual Studio, Xamarin Studio and Unity, it can run on Windows, Linux, Mac OS X, iOS, Android and Windows Phone.

  Emgu CV :http://www.emgu.com/wiki/index.php/Main_Page,需要下載3.0版本以後的,Emgu CV 3.0繼成了ffmpeg

  

Capture _capture = new Capture(fileName); //rtsp://user:[email protected]:554/  _capture.ImageGrabbed += capture_ImageGrabbed;_capture.Start();

private void capture_ImageGrabbed(object sender, EventArgs e)
{
  try
  {
    Mat frame = new Mat();

    lock (lockObj)
    {
      if (capture != null)
      {
        if (!capture.Retrieve(frame))
        {
          frame.Dispose();
          return;
        }
        if (frame.IsEmpty)
          return;

        //顯示圖片 可以使用Emgu CV 提供的 ImageBox顯示視頻, 也可以轉成 BitmapSource顯示。

        //略

      }
    }
  }
  catch (Exception ex)
  {
  }
}

 

 

public static class BitmapSourceConvert    {        /// <summary>        /// Delete a GDI object        /// </summary>        /// <param name="o">The poniter to the GDI object to be deleted</param>        /// <returns></returns>        [DllImport("gdi32")]        private static extern int DeleteObject(IntPtr o);        /// <summary>        /// Convert an IImage to a WPF BitmapSource. The result can be used in the Set Property of Image.Source        /// </summary>        /// <param name="image">The Emgu CV Image</param>        /// <returns>The equivalent BitmapSource</returns>        public static BitmapSource ToBitmapSource(IImage image)        {            using (System.Drawing.Bitmap source = image.Bitmap)            {                IntPtr ptr = source.GetHbitmap(); //obtain the Hbitmap                BitmapSource bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(                    ptr,                    IntPtr.Zero,                    Int32Rect.Empty,                    System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());                DeleteObject(ptr); //release the HBitmap                return bs;            }        }    }

 

 注意事項:由於ffmpeg 預設使用TCP同步串連請求視頻源,連線逾時時間很長,

Capture _capture = new Capture(fileName),如果訪問的媒體不存在,會導致阻塞。需要設定ffmpeg串連方式或者逾時時間。

設定方式:
public bool SetCaptureProperty(CapProp property, double value); //Capture方法。具體怎麼設定不知道、或者Emgu CV沒有提供這個介面

 

C# 通過Emgu CV播放流媒體(RTSP)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.