2012-03-29 376 views
2

我想選擇我的攝像頭幀的像素顏色。所以我在一個ImageBox中捕獲了一個節目而沒有任何問題。但是,當我嘗試訪問ImageBox上存儲的圖像時,我雙擊ImageBox我得到一個CvException。當我嘗試獲取圖像的像素時出現異常彈出。如何獲得EmguCV ImageBox圖像?

的OpenCV:無法識別或不支持的陣列型

這是我的捕捉幀:

// On Form Load 
Application.Idle += ProcessFrame; 

private void ProcessFrame(object sender, EventArgs arg) 
    { 
     if (cap != null) 
     { 
      using (Image<Bgr, byte> frame = cap.QueryFrame()) 
      { 
       if (frame != null) 
       { 
        imageFrame = frame; 
        imageBoxFrame.Image = imageFrame; 

        Bgr color = imageFrame[50, 100]; 
       } 
      } 
     } 
    } 

並在DoubleClick事件:

private void imageBoxFrame_MouseDoubleClick(object sender, MouseEventArgs e) 
    { 
     if (treeViewObjects.SelectedNode is ColorNode && !isTracking) 
     { 
      if (imageFrame == null) 
       return; 

      Emgu.CV.UI.ImageBox imageBox = (Emgu.CV.UI.ImageBox)sender; 
      Image<Bgr, byte> image = (Image<Bgr, byte>)imageBox.Image; 

      Bgr color = image[e.X, e.Y]; // This line causes the Exception 
     } 
    } 

顯然的圖像是不爲空。 我做錯了什麼?也許與線程的東西?

+0

已經有一段時間,但你應該回答你自己的問題,所以這出來的「開放式問題」隊列。 – 2014-05-14 17:46:23

回答

3

(問題由OP回答回答發帖請參見Question with no answers, but issue solved in the comments (or extended in chat)

的OP寫道:

我解決它。

我只需要克隆圖像,因爲使用語句擦除圖像數據。所以,在ProcessEvent上,我只需要將幀複製到imageFrame。

imageFrame = frame.Clone(); 

而且還有一個問題。訪問像素數據的正確方法是[Y,X]不是[X,Y]。

Bgr color = image[e.Y, e.X];