2012-06-06 267 views
2

我試圖捕捉到Visual Studio 2010中使用EMGU CV視頻寫入視頻的時候,但「System.AccessViolationException了未處理」的錯誤時,執行線使用emgu CV

video.WriteFrame<Bgr, byte>(marked); 

我得到的follwing錯誤:

System.AccessViolationException了未處理

試圖讀取或寫入保護內存。這通常表明其他內存已損壞。

private void button3_Click_1(object sender, EventArgs e) 
    { 
     Capture camera = new Capture(); 
     if (camera == null) 
     { 
      MessageBox.Show("can't find a camera", "error"); 
     } 
     double fps = camera.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FPS); 
     double cpHeight = camera.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT); 
     double cpWidth = camera.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FRAME_WIDTH); 
     double fourcc = camera.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FOURCC); 
     CvInvoke.cvNamedWindow("camera"); 
     Image<Bgr, byte> temp = camera.QueryFrame(); 
     //路徑 
     SaveFileDialog SaveFileDialog1 = new SaveFileDialog(); 
     SaveFileDialog1.FileName = DateTime.Now.ToString("yyyyMMddhhmmss"); 
     SaveFileDialog1.Filter = "Image Files(*.avi)|*.avi|All files (*.*)|*.*"; 
     if (SaveFileDialog1.ShowDialog() == DialogResult.OK) 
     { 
      MessageBox.Show("START RECORD,ESC TO STOP"); 
     } 
     VideoWriter video = new VideoWriter(SaveFileDialog1.FileName, (int)fourcc, 15, 800, 600, true); 
     while (temp != null) 
     { 
      CvInvoke.cvShowImage("camera", temp.Ptr); 
      temp = camera.QueryFrame(); 
      int c = CvInvoke.cvWaitKey(20); 
      Image<Bgr, byte> marked = faceDetection(temp); 
      video.WriteFrame<Bgr, byte>(marked); 
      if (c == 27) break; 
     } 
     video.Dispose(); 
     camera.Dispose(); 
     CvInvoke.cvDestroyWindow("camera"); 
    } 

有沒有人知道可能是什麼原因造成的?

感謝

埃文

回答

0

重新排序以下行其完全爲我工作後。也檢查是標記爲不爲空。如果標記爲空,則會導致訪問衝突錯誤。

while (temp != null) 
{ 
    CvInvoke.cvShowImage("camera", temp.Ptr); 

    Image<Bgr, byte> marked = faceDetection(temp); 
    video.WriteFrame<Bgr, byte>(marked); 

    int c = CvInvoke.cvWaitKey(20); 
    if (c == 27) break; 

    temp = camera.QueryFrame(); 
} 
0

對不起,對於遲到的答案,但也許有人會發現它有幫助。

我現在正在與自己爭吵(在不同情況下),看起來這是一個嘗試在我的項目中包含32位組件的問題。

在32位系統上運行完美,在64位無我有「System.AccessViolationException是未處理」

可悲的是沒有多少可以在我的情況下完成的,只是給了組件和做一些其他的way

也許這裏也是個問題。什麼是VideoWriter,看起來不像標準的.NET類?