2015-10-20 84 views
0

好吧,首先我只想說,我已經嘗試了多個教程來解決這個錯誤和衆多的網站,我已經搜索了這個論壇的潛在解決方案,但無濟於事。我使用的代碼幾乎與我在互聯網上找到的代碼完全相同,並且在運行代碼時不會出現語法錯誤。所以我得出結論,我有一個參考或聯繫問題。新的OpenCV和遇到了一個奇怪的錯誤

namespace Video_Capture 
{ 
    public partial class CameraCapture : Form 
    { 
     //Variable Declaration 
     private Capture capture; //takes images from camera as image frame 
     private bool captureInProgress; //checks if capture is executing 

     private void ProcessFram(object sender, EventArgs arg) 
     { 
      Image<Bgr, Byte> ImageFrame = capture.QueryFrame(); 
      CamImageBox.Image = ImageFrame; 
     } 
     public CameraCapture() 
     { 
      InitializeComponent(); 
     } 

     private void btnStart_Click(object sender, EventArgs e) 
     { 
      #region if capture is not created, create it now 
      if (capture == null) 
      { 
       try 
       { 
        capture = new Capture(); 
       } 
       catch (NullReferenceException excpt) 
       { 
        MessageBox.Show(excpt.Message); 
       } 
      } 
      #endregion 

      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 -= ProcessFram; 

       } 
       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 += ProcessFram; 

       } 
       captureInProgress = !captureInProgress; 
      } 
     } 
      private void ReleaseData() 
      { 
       if (capture != null) 
        capture.Dispose(); 
      } 
     } 
    } 

After running the code and pressing the "start" button I get this error.

+0

您使用的是哪個版本的Emgu?另外,確保您的項目在屬性下設置爲正確的目標平臺(32/64位)。它必須匹配Emgu dlls。 –

回答

0

你檢查你的依賴呢?您的問題看起來像是這個問題的複本,請檢查接受的答案:EmguCV TypeInitializationException

+0

是的,我試圖粘貼目錄中的這些.dll文件,但它仍然顯示相同的錯誤。 – rorivy15

+0

您是否嘗試過使用Process Monitor或Dependency Walker來確定是否缺少其他東西?我推薦進程監視器,在線上放置一個斷點,在進程監視器上開始捕獲事件,在Visual Studio上執行步驟(F5),停止捕獲事件。然後從列表中篩選您的進程並搜索您的進程找不到的DLL。 您可以在此處下載Process Monitor:https://technet.microsoft.com/en-us/library/bb896645.aspx –