2011-02-23 80 views
1

我是emgu cv的新手和主要項目我試圖從網絡攝像頭捕獲圖像並將其顯示在圖像框中,但顯示的是黑色圖像。使用Emgu捕獲圖像 - 黑色圖像

以下代碼有什麼問題?

using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using Emgu.CV; 
using Emgu.CV.Structure; 
using Emgu.CV.UI; 
using Emgu.Util; 

namespace WindowsFormsApplication7 
{ 
    public partial class Form1 : Form 
    { 
     private Capture capture; 

     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void Form1_Load(object sender, EventArgs e) 
     { 
      if (capture == null) 
       capture = new Capture(); 
      Image<Bgr,Byte> img=capture.QueryFrame(); 
      imageBox1.Image = img;     
     } 
    } 
} 
+1

你應該提供更多的資料在你的攝像頭,如果是筆記本電腦內置的或不和emgu您使用的版本。試着運行使用網絡攝像頭的Opencv例子,如果它不起作用,它不是一個emgu問題,而是一個opencv問題。 – 2011-02-23 15:53:16

+0

您是否嘗試過運行Emgu附帶的示例應用程序之一?如VideoSurveillance樣本。 – Mikos 2012-03-24 18:21:28

回答

0

我覺得有一個小小的錯誤。

用這個代替:

聲明爲全局變量:

Capture capture = default(Capture); 

負荷將這個:

capture = new Capture(0); 
Control.CheckForIllegalCrossThreadCalls = false; 
System.Threading.Thread t = new System.Threading.Thread(grab); 

t.Start(); 

創建一個子搶,投放,

do { 
    ImageBox1.Image = capture.QueryFrame(); 
} while (true); 

乾杯
個 Shreyas

0

呼叫QueryFrame()兩次,它爲我工作:

if (capture == null) 
      capture = new Capture(); 
capture.QueryFrame(); 
Image<Bgr,Byte> img=capture.QueryFrame().ToImage<Bgr, Byte>(); 
imageBox1.Image = img.Bitmap;