
| 語言: | .NET C#/Visual Basic |
| 版本: | 3.0.3 |
| 发布于: | 2005年4月7日 |
| 作者: | IC Imaging Control技術支持部 |
| 需求: | IC Imaging Control >2.1 由WDM數據流類驅動程序驅動的相機、視頻轉換器或圖像採集卡 |
| |
示例程序窗口如下圖所示:

程序開始後首先調用內置對話框(.ShowDeviceSettingsDialog)供用戶選擇視頻設備。 而後通過.LiveStart顯示設備傳來的現場畫面數據流。 .MemoryCurrentGrabberColorformat = ICY8語句確保二值化算法得到的是8比特灰度級的圖像:
[C#] private void Form1_Load(object sender, System.EventArgs e) { icImagingControl1.ShowDeviceSettingsDialog(); if( !icImagingControl1.DeviceValid ) { Close(); return; } icImagingControl1.MemoryCurrentGrabberColorformat = TIS.Imaging.ICImagingControlColorformats.ICY800; icImagingControl1.LiveDisplay = false; icImagingControl1.LiveStart(); }
用戶點擊"Snap Image", .MemorySnapImage就會從現場視頻數據流中抓取一幀圖像並將其寫入環形緩存。
[C#] private void btnSnapImage_Click(object sender, System.EventArgs e) { icImagingControl1.MemorySnapImage(); icImagingControl1.Display(); btnBinarize.Enabled = true; }
用戶點擊"Binarize",程序首先讀取用戶之前設定好的閾值(threshold = txtThreshold.Text)。 而後創建圖像緩存的引用ib並將其設為環形緩存中的當前圖像(ImageBuffers.CurrentIndex)。 實際的圖像處理操作都是在下面的兩個for循環中。如果當前像素的灰度值 .imageData(x,y)大於所設定的閾值,則將其設為255,反之則設為0:
[C#] private void btnBinarize_Click(object sender, System.EventArgs e) { int threshold = int.Parse( txtThreshold.Text ); if( threshold < 0 || threshold > 255 ) { MessageBox.Show( "Invalid threshold value", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error ); } TIS.Imaging.ImageBuffer ib = icImagingControl1.ImageActiveBuffer; for( int y = 0; y < ib.Lines; ++y ) { for( int x = 0; x < ib.PixelPerLine; ++x ) { if( ib[x,y] < threshold ) ib[x,y] = 0; else ib[x,y] = 255; } } icImagingControl1.Display(); }
責任聲明
IC Imaging Control源代碼庫中的所有代碼均只用於教學目的,The Imaging Source Europe GmbH作為IC Imaging Control的開發製造商,不對任何由於使用本文或其中源代碼所產生的後果承擔責任。