2013-09-10 82 views
2

我在c#中使用emgu cv。如何從emgu cv攝像頭獲取視頻流?

我需要知道如何從emgu cv中從我的攝像頭(默認網絡攝像頭)獲取視頻流?

+0

出於興趣。請使用Google或至少訪問圖書館的官方網站:http://www.emgu.com/wiki/index.php/Camera_Capture_in_7_lines_of_code –

回答

5

您可以使用下面的代碼使一個應用程序捕獲和顯示視頻流:

public class CameraCapture 
{ 
    private Capture capture; //takes images from camera as image frames 
    private bool captureInProgress; 

    private void ProcessFrame(object sender, EventArgs arg) 
    { 
     Image<Bgr, Byte> ImageFrame = capture.QueryFrame(); //line 1 
     CamImageBox.Image = ImageFrame; //line 2 
    } 
    private void Form1_Load(object sender, EventArgs e) 
    { 
     if (capture == null) 
     { 
      try 
      { 
       capture = new Capture(); 
      } 
      catch (NullReferenceException excpt) 
      { 
       MessageBox.Show(excpt.Message); 
      } 
     } 

     if (capture != null) 
     { 
      if (captureInProgress) 
      { //if camera is getting frames then stop the capture and set button Text 
       // "Start" for resuming capture 
       btnStart.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 
       btnStart.Text = "Stop"; 
       Application.Idle += ProcessFrame; 
      } 
      captureInProgress = !captureInProgress; 
     } 
    } 
} 
2

不知道你想要什麼用數據來做,但是這將讓你從相機的單個幀(和在PictureBox顯示它在一個WinForm)

private void Form1_Load(object sender, EventArgs e) 
{    

    var capture = new Emgu.CV.Capture(); 

    using (var nextFrame = capture.QueryFrame()) 
    { 
     if (nextFrame != null) 
     {       
      pictureBox1.Image = nextFrame.ToBitmap(); 
     } 
    }       
}