2012-04-02 61 views
2

我有下面的代碼來顯示使用EmgucV在imagebox圖像:EmguCV試圖讀取或寫入保護內存

Capture capture; 
    Image<Bgr, Byte> image; 

    public Form1() 
    { 
     InitializeComponent(); 
     Application.Idle += new EventHandler(Start); 
    } 
    void Start(object sender, EventArgs e) 
    { 
     capture = new Capture(); 
     image = capture.QueryFrame(); 
     imageBox1.Image = image; 
    } 

我得到的異常Attempted to read or write protected memory。我需要做些什麼來糾正這個問題?

+0

是什麼類型imageBox1? – surfen 2012-04-02 22:26:49

回答

4

這是可能的本地內存指示泄漏

我認爲這是在你的代碼中的錯誤。您的Start方法將在應用程序生命週期中多次(經常)調用。

它看起來應該只在應用程序中使用一個Capture對象。

只需將您的Capture實例化表單構造:

Capture capture; 

public Form1() 
{ 
    InitializeComponent(); 
    Application.Idle += new EventHandler(Capture); 
    capture = new Capture(); 
} 
void Capture(object sender, EventArgs e) 
{ 
    imageBox1.Image = capture.QueryFrame(); 
} 
相關問題