2011-02-05 88 views
6

我想在使用EMGU的C#程序中創建直方圖。 EMGU包含一個名爲MCvHistogram的類,但我不知道如何使用它。如何創建直方圖

+0

本文介紹如何在RGB直方圖創建 http://stackoverflow.com/questions/8204822/how-to-draw-histogram-using-emgucv-and-c-sharp – JiP 2014-01-14 16:05:41

回答

11

如果您想使用EmguCV,您應該使用DenseHistogram類。 我會告訴你基本用法:

// Create a grayscale image 
    Image<Gray, Byte> img = new Image<Gray, byte>(400, 400); 
    // Fill image with random values 
    img.SetRandUniform(new MCvScalar(), new MCvScalar(255)); 
    // Create and initialize histogram 
    DenseHistogram hist = new DenseHistogram(256, new RangeF(0.0f, 255.0f)); 
    // Histogram Computing 
    hist.Calculate<Byte>(new Image<Gray, byte>[] { img }, true, null); 

有很多的DenseHistogram類中其他常用的方法,如背投

+0

感謝名單..但我已經使用CvInvoke.cvCalHist(), 計算直方圖,但我發現上述方法使用起來更容易。 您能否簡單闡述McvHistogram和DenseHistogram之間的區別? – 2011-02-07 04:35:29

+2

DenseHistogram是包裝McvHistogram的託管類。您可以檢查密集講述課,並檢查它是否有屬性MCvHistogram。我的建議是,當opencv功能已被封裝在適當的託管類中時,不要使用cvinvoke ... – 2011-02-07 10:22:40

3

您可以使用此代碼片段:

histogramBox.GenerateHistograms(image,bin);    
histogramBox2.Refresh(); 

它會自動創建你的圖片的直方圖。