2012-04-02 80 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(); 
} 
相关问题