C#使用Aforge对uvc协议摄像头亮度属性的更改
生活随笔
收集整理的這篇文章主要介紹了
C#使用Aforge对uvc协议摄像头亮度属性的更改
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用c#自帶的DirectShow類對基于uvc協議的攝像頭進行亮度參數的更改時,需要打開其自帶的一個頁面,如果想要實現在代碼中更改需要使用DirectShow的擴展類。首先,需要在VideoCaptureDevice.cs
類里添加幾個方法
然后,需要新建類VideoProcAmpProperty(和VideoCaptureDevice.cs在同一目錄)
using System;/// <summary>/// The enumeration specifies a setting on a camera./// </summary>public enum VideoProcAmpProperty{/// <summary>/// Brightness control./// </summary>Brightness = 0,/// <summary>/// Contrast control./// </summary>Contrast,/// <summary>/// Hue control./// </summary>Hue,/// <summary>/// Saturation control./// </summary>Saturation,/// <summary>/// Sharpness control./// </summary>Sharpness,/// <summary>/// Gamma control./// </summary>Gamma,/// <summary>/// ColorEnable control./// </summary>ColorEnable,/// <summary>/// WhiteBalance control./// </summary>WhiteBalance,/// <summary>/// BacklightCompensation control./// </summary>BacklightCompensation,/// <summary>/// Gain control./// </summary>Gain}/// <summary>/// The enumeration defines whether a camera setting is controlled manually or automatically./// </summary>[Flags]public enum VideoProcAmpFlags{/// <summary>/// No control flag./// </summary>None = 0x0,/// <summary>/// Auto control Flag./// </summary>Auto = 0x0001,/// <summary>/// Manual control Flag./// </summary>Manual = 0x0002}最后需要在Internals文件夾下新建IAMVideoProcAmp類
using System;using System.Runtime.InteropServices;/// <summary>/// The IAMVideoProcAmp interface controls camera settings such as brightness, contrast, hue,/// or saturation. To obtain this interface, query the filter that controls the camera./// </summary>[ComImport,Guid("C6E13360-30AC-11D0-A18C-00A0C9118956"),InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]internal interface IAMVideoProcAmp{/// <summary>/// Gets the range and default value of a specified camera property./// </summary>////// <param name="Property">Specifies the property to query.</param>/// <param name="pMin">Receives the minimum value of the property.</param>/// <param name="pMax">Receives the maximum value of the property.</param>/// <param name="pSteppingDelta">Receives the step size for the property.</param>/// <param name="pDefault">Receives the default value of the property. </param>/// <param name="pCapsFlags">Receives a member of the VideoProcAmpFlags enumeration, indicating whether the property is controlled automatically or manually.</param>////// <returns>Return's <b>HRESULT</b> error code.</returns>///[PreserveSig]int GetRange([In] VideoProcAmpProperty Property,[Out] out int pMin,[Out] out int pMax,[Out] out int pSteppingDelta,[Out] out int pDefault,[Out] out VideoProcAmpFlags pCapsFlags);/// <summary>/// Sets a specified property on the camera./// </summary>////// <param name="Property">Specifies the property to set.</param>/// <param name="lValue">Specifies the new value of the property.</param>/// <param name="Flags">Specifies the desired control setting, as a member of the VideoProcAmpFlags enumeration.</param>////// <returns>Return's <b>HRESULT</b> error code.</returns>///[PreserveSig]int Set([In] VideoProcAmpProperty Property,[In] int lValue,[In] VideoProcAmpFlags Flags);/// <summary>/// Gets the current setting of a camera property./// </summary>////// <param name="Property">Specifies the property to retrieve.</param>/// <param name="lValue">Receives the value of the property.</param>/// <param name="Flags">Receives a member of the VideoProcAmpFlags enumeration./// The returned value indicates whether the setting is controlled manually or automatically.</param>////// <returns>Return's <b>HRESULT</b> error code.</returns>///[PreserveSig]int Get([In] VideoProcAmpProperty Property,[Out] out int lValue,[Out] out VideoProcAmpFlags Flags);}然后進行重新生成解決方案并在想要使用擴展類的項目中更改引用即可使用DirectShow的擴展類。
DirectShow的源代碼可從c#的包管理器中點擊DirectShow的源路徑獲取。
嫌麻煩的可以去我上傳的資源進行下載。
總結
以上是生活随笔為你收集整理的C#使用Aforge对uvc协议摄像头亮度属性的更改的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: matlab常用工具箱的调用指令
- 下一篇: c# char unsigned_dll